﻿
// redirect to main site

function colredirecttoMainSite(drpFromId,drpToId,txtJobTitleId,txtSalaryId,target)
{
    var fromLocation = document.getElementById(drpFromId);
    var toLocation = document.getElementById(drpToId);
    
    var jobTitle = document.getElementById(txtJobTitleId);  
    var salary = document.getElementById(txtSalaryId);
    
    if (toLocation != null && toLocation.value == "")
    {
        alert("Please enter at least the destination location."); 
        return false;
    }
    
    var newUrl = target+'/' + EncodeURI(toLocation.value);
    
    if(fromLocation != null && fromLocation.value != "" && fromLocation.value != toLocation.value )
    {
       newUrl += "/" + EncodeURI(fromLocation.value); 
    }
    else if(jobTitle != null && jobTitle.value != "")
    {
        newUrl += "/-"
    }
    
    if(jobTitle != null && jobTitle.value != "")
    {
       newUrl += "/" + EncodeURI(jobTitle.value); 
    }
    
    if(salary != null && salary.value != "")
    {
       newUrl += "/" + EncodeURI(salary.value); 
    }  
    else 
    {
        newUrl += "/-"
    }
    
    window.open(newUrl);
}

function EncodeURI(encodeThis)
{
    var newString = new String(encodeThis);
    var regExp = /\s+/g;
    newString = newString.replace(regExp,'-');
    regExp = /\/+/g;
    newString = newString.replace(regExp,'');
    return escape(newString);
}