

function campusexplorerrdlogger(bdcz, bdcr)
{
  try {
    var myImage = new Image();
    var imgSrc='';
    var ourDate = new Date();
    var interaction_ord = "" + ourDate.getFullYear() + (ourDate.getMonth() + 1) + ourDate.getDate() + ourDate.getHours() + ourDate.getMinutes() + ourDate.getSeconds() + Math.floor(Math.random()*11) ;
    imgSrc = interaction_rdurl + '/RDlog.gif?bdcf=' +  interaction_nodeuuid + '&mktid=' + escape(interaction_mktid) + '&mkw=' + escape(interaction_mkw) + '&bdcz=' + bdcz + '&bdcs=' + interaction_bdcs + '&bdcr=' + bdcr + '&ord=' +interaction_ord;
    myImage.src = imgSrc;
    } catch (e) {}	 
}

function processOnlineClick(id)
{
   //alert(document.getElementById(id).checked );
}

function SelectAll(id)
{
var currentstyle = document.getElementById(id).style.className;
var currentvalue = document.getElementById(id).value; 
   if (document.getElementById(id).disabled == false){
       document.getElementById(id).focus();
       document.getElementById(id).select();
    
       document.getElementById(id).className = 'ce-location-enter';
   }
}

function disablelocation(id)
{

   if(document.getElementById(id).disabled == true){
       document.getElementById(id).disabled = false ;   
    }
    else{
       document.getElementById(id).disabled = true ;
       document.getElementById(id).value = 'Enter city, state OR zip';
    }
}


function locationfocus(id)
{
     //document.getElementById('location-search-error').innerHTML="&nbsp;";

}


function checkEnter(e){
    var characterCode

    if(e && e.which){ 
        e = e;
        characterCode = e.which ;
    }
    else{
        e = event;
        characterCode = e.keyCode;
    }

    if(characterCode == 13){ 
        GeoAjaxCall(document.getElementById('location').value);
        return false ;
    }
    else{
        return true ;
    }

}



function GeoAjaxCall(q)
{

 campusexplorerrdlogger('j.campusexplorer.formOpen.i', 0);

 document.getElementById('location-search-error').innerHTML="&nbsp;";
 
 if (q == "Enter city, state OR zip" ) {


        var loc = document.location+ "";
        var newatts="";
        var altered=false;
 
        if ( ( document.getElementById('onlineOff').checked == true && loc.indexOf("o-exclude-online") == -1 ) || (document.getElementById('onlineOff').checked == false && loc.indexOf("o-exclude-online") > -1 )  ) {

        //if the loc already has location information, remove it before adding the new location
        if ( loc.indexOf("/m/") > -1 ) {
            //alert(loc);
               
            var locatts=loc.substring(loc.indexOf("/m/") + 3, loc.length);
            //alert(locatts);
            if (locatts == "o-exclude-online/" ) { 
                document.location=loc.substring(0,loc.indexOf("/m/"));
            } else {
                if ( locatts.charAt (locatts.length - 1) == "/" ) {
                    locatts=locatts.substring(0,locatts.length -1);
                    var locattsArray = locatts.split("--")
                    for (var i =0; i < locattsArray.length; i++) {
                            var thisatt = locattsArray[i];
                            //alert(thisatt);
                            if (thisatt.length > 2 && ( thisatt.substring(0,2) == "c-" || thisatt.substring(0,2) == "s-" || thisatt.substring(0,2) == "z-" ) ) {
                                
                            } else {
                                if (thisatt!="o-exclude-online" ) {
                                    if(newatts.length > 0 ) newatts=newatts+"--";
                                    newatts = newatts + thisatt;
                                    altered=true;
                                    //alert("normal found: " + thisatt);
                                }
                            }
                    }
                }
                //alert(locatts);
                var locstem=loc.substring(0,loc.indexOf("/m/"));
                locstem=locstem+"/m/";
                loc=locstem+newatts;
                //if(newatts.length > 0 && newatts.indexOf("--") == -1 ) loc=loc+"--";
                if (document.getElementById('onlineOff').checked == true ) loc=loc+"--o-exclude-online/"
                //alert(loc);
                if ( loc.charAt (loc.length - 1) != "/" ) loc=loc+"/";
                
                campusexplorerrdlogger('j.campusexplorer.formComplete.i', 0);


                document.location=loc;
            }
        } else {
            document.location=loc + "m/o-exclude-online/";
        }
    }
                      

 } else {
        var req = null; 
        var LocalityName = null;
        var AdministrativeAreaName = null;
        var CountryNameCode = null;
        var PostalCodeNumber = null;
        //alert("Started...");

        if (window.XMLHttpRequest)
        {
                req = new XMLHttpRequest();
                if (req.overrideMimeType) 
                {
                        req.overrideMimeType('text/xml');
                }
        } 
        else if (window.ActiveXObject) 
        {
                try {
                        req = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e)
                {
                        try {
                                req = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (e) {}
                }
        }


        req.onreadystatechange = function()
        { 
                //alert("Wait server...");
                if(req.readyState == 4)
                {
                        if(req.status == 200 && req.responseText.indexOf("Servlet Exception") == -1 )
                        {

                                try {
                                    LocalityName = req.responseXML.getElementsByTagName('LocalityName')[0].firstChild.data;
                                } catch (e) { LocalityName = "" }
                                
                                try {
                                    CountryNameCode = req.responseXML.getElementsByTagName('CountryNameCode')[0].firstChild.data;
                                } catch (e) { CountryNameCode = "" }   
                                                            
                                try {
                                    PostalCodeNumber = req.responseXML.getElementsByTagName('PostalCodeNumber')[0].firstChild.data;
                                } catch (e) { PostalCodeNumber = "" }                               
                               
                                try {
                                    AdministrativeAreaName = req.responseXML.getElementsByTagName('AdministrativeAreaName')[0].firstChild.data;
                                } catch (e) { AdministrativeAreaName = "" }                                   
                                
                                if ( CountryNameCode == "" ) {
                                    document.getElementById('location-search-error').innerHTML="Please try another location";
                                    document.getElementById('location').focus();
                                }
                                else if ( CountryNameCode != "US" ) {
                                    document.getElementById('location-search-error').innerHTML="Please enter a location in the USA";
                                    document.getElementById('location').focus();
                                }
                                else if ( CountryNameCode == "US" ) {
                               
                                    var loc = document.location+ "";
                                    var newatts="";
                                    var altered=false;
                                    
                                    loc = loc.replace("o-exclude-online", "");
                                    loc = loc.replace("----", "--");
                                                                        
                                    //if the loc already has location information, remove it before adding the new location
                                    if ( loc.indexOf("/m/") > -1 ) {
                                        //alert(loc);
                                           
                                        var locatts=loc.substring(loc.indexOf("/m/") + 3, loc.length);
                                        if ( locatts.charAt (locatts.length - 1) == "/" ) {
                                            locatts=locatts.substring(0,locatts.length -1);
                                            var locattsArray = locatts.split("--")
                                            for (var i =0; i < locattsArray.length; i++) {
                                                    var thisatt = locattsArray[i];
                                                    //alert(thisatt);
                                                    if (thisatt.length > 2 && ( thisatt.substring(0,2) == "c-" || thisatt.substring(0,2) == "s-" || thisatt.substring(0,2) == "z-" ) ) {
                                                        
                                                    } else {
                                                        if(newatts.length > 0 ) newatts=newatts+"--";
                                                        newatts = newatts + thisatt;
                                                        altered=true;
                                                        //alert("normal found: " + thisatt);
                                                    }
                                            }
                                        }
                                        //alert(locatts);
                                        var locstem=loc.substring(0,loc.indexOf("/m/"));
                                        locstem=locstem+"/m/"
                                        loc=locstem+newatts;
                                        //if(newatts.length > 0 && newatts.indexOf("--") == -1 ) loc=loc+"--";
                                        //alert(loc);
                                    }
                                                  
                                    var dashdash="--";

                                    if ( loc.indexOf("/m/") == -1 ) {
                                        loc=loc+"m/"
                                    } 
                                    /*else if ( loc.charAt (loc.length - 1) == "/" ) {
                                        loc=loc.substring(0,loc.length -1);
                                    }*/
                                    
                                    if ( loc.charAt (loc.length - 1) == "-" || newatts.length == 0  ) dashdash="";
                                    else dashdash="--";
                                    
                                    if (PostalCodeNumber != null && PostalCodeNumber.length > 0 ) {
                                        loc=loc + dashdash + "z-" + PostalCodeNumber.toLowerCase().replace(" ", "_");
                                        altered=true;
                                    }
                                    
                                    if ( loc.indexOf("--") == -1 && altered == false ) dashdash="";
                                    else dashdash="--";
                                                                       
                                    if (AdministrativeAreaName != null && AdministrativeAreaName.length > 0 ) { 
                                        loc=loc + dashdash + "s-" + AdministrativeAreaName.toLowerCase().replace(" ", "_");
                                        altered=true;
                                    }
                                    
                                    if ( loc.indexOf("--") == -1 && altered == false ) dashdash="";
                                    else dashdash="--";                                    
                                    
                                    if (LocalityName != null && LocalityName.length > 0 ) { 
                                        loc=loc + dashdash + "c-" + LocalityName.toLowerCase().replace(" ", "_");
                                        altered=true;
                                    }
                                    
                                    if (altered) {
                                        if ( loc.charAt (loc.length - 1) != "/" ) {
                                            loc=loc+"/";
                                        }
                                        loc = loc.replace("----", "--");
                                        campusexplorerrdlogger('j.campusexplorer.formComplete.i', 0);
                                        document.location=loc;                                
                                    } else {
                                        document.getElementById('location-search-error').innerHTML="Please try another location";
                                        document.getElementById('location').focus();
                                    }
                                }
                              
			            }	
                        else	
                        {
                                window.status="Error: returned status code " + req.status + " " + req.statusText;
                        }		
                } 
        }; 

        req.open("GET", "/include/googlegeo.asp?q=" + escape(q) + "&buster=" + escape(new Date()), true); 
        req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
        req.send(null); 

    }
} 

