var xmlHttp

if (!xmlHttp) {
try {
  xmlHttp = new XMLHttpRequest();
}
catch (e) {
  xmlHttp=false
}
}


// the php script to process the form.  var must be global!

var URLto = 'index.php';
var tempURL = '';
var div = '';


// function to build POST requests

function buildPOST(theFormName) {
    theForm = document.forms[theFormName];
    var qs = ''
    for (e=0;e<theForm.elements.length;e++) {
        if (theForm.elements[e].name!='') {
            var name = theForm.elements[e].name;
            qs+=(qs=='')?'':'&'
            qs+= name+'='+escape(theForm.elements[e].value);
        }
    }
    qs+="\n";
    return qs
}

// function to communicate with remote script

function send_post(theFormName, theURL) {
    URLto = theURL;
    var xmlMessage = buildPOST(theFormName);
    xmlHttp.open("POST", URLto, false) ;

    // for ie compatability
    xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded') ;
//    xmlHttp.setRequestHeader('Content-Type','multipart/form-data') ;

    xmlHttp.send(xmlMessage)
}

function send_get(theURL) {

    xmlHttp=null
    // code for Mozilla, etc.
    if (window.XMLHttpRequest)
    {
    xmlHttp=new XMLHttpRequest()
    }
    // code for IE
    else if (window.ActiveXObject)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP")
    }

    tempURL = theURL;

    xmlHttp.onreadystatechange=state_Change
    xmlHttp.open("GET",theURL,true)
    xmlHttp.send(null)
}

function state_Change()
{
    // if xmlhttp shows "loaded"
    
    var finaldest = 'weather_container';
    
    var optionDiv = document.getElementById(div);

    if (xmlHttp.readyState==4)
    {
        // if "OK"
        // 200 = url exists
        // 404 = page not found
        //0 = uninitialized
        //1 = loading
        //2 = loaded
        //3 = interactive
        //4 = complete

        if (xmlHttp.status==200)
        {

            var tempAr = tempURL.split("&");
            var tempsubAr;
            
            //$('#main_tpl').SlideOutLeft(500);
            //optionDiv.innerHTML = '';

            optionDiv.innerHTML = xmlHttp.responseText;
            document.getElementById('status-'+div).innerHTML = 'Weather feed supplied by <a href="http://www.weather.com" target="_blank">The Weather Channel</a>';
            //YAHOO.util.Event.onAvailable('main_tpl', TF.Scroller.init, TF.Scroller, true);
            //window.status = "completed";
            //Effect.SlideDown('main_tpl');
            //Effect.Grow('main_tpl');
            //Effect.Pulsate('main_tpl');

            //if (finaldest != 'main_tpl') $('#'+finaldest).SlideInRight(500);

        }
        else
        {
           window.location = tempURL;
        }
    }
}

function selectDest(script_url, s, container){
    var d = new Date();
    var t = d.getTime();
    var tempsubAr;
    
    div = container;
    
    document.getElementById('status-'+div).innerHTML = "&nbsp;&nbsp;&nbsp;Loading....";
    send_get('http://'+script_url+'?ajax_mode=1&t='+t+'&loc='+s.value);
    s.blur();
    return;
  
}
