//*******************************************************************************
//'* Purpose  : Commonly used Javascript Functions on the AOME Career Site.
//'* Date     : 17 Oct 2006
//'* Author   : Mohammed Owais
//'* History      Auth        Date	Description
//'  --------     --------    ------- ---------------------------------------------
//'
//'*******************************************************************************
// Start

function ContainOnlyAlphabetsWithSpaces(strValue)
{
		strValue = strValue.toUpperCase();
		for (i=0;i<strValue.length;i++)
		{
			if (strValue.charAt(i)<"A" || strValue.charAt(i) > "Z")
			{
				if (strValue.charAt(i) != ' '){
					return false;
				}	
			}
		}
		return true;
}

function OpenWindow(Agent,Relogin)
			{
				var CompanyId = document.getElementById('txtCompanyID').value;
				if (Relogin)
				{
					eurl = "../Frameset.aspx?CompanyID="+ CompanyId;
				}
				else
				{
					var VacancyId = document.getElementById('txtVacancyID').value
					eurl = "../Frameset.aspx?CompanyID="+ CompanyId + "&VacancyId=" + VacancyId;
				}	
				if (Agent){
					eurl+="&Agent=1"
				}
				awindow = openCentered(eurl, 795, 520, 'application', 'toolbar=yes,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes')	
			}	
			
			
function openCentered (url, width, height, windowName, featureString) 

			{
				if (!windowName)
						windowName = '';
				if (!featureString)
						featureString = '';
				else
						featureString = ',' + featureString;
						var x = Math.round((screen.availWidth - width) / 2);
						var y = Math.round((screen.availHeight - height) / 2);
						featureString = 'left=' + x + ',top=' + y + ',width=' + width 
							+ ',height=' + height + featureString;
				winname = open (url, windowName, featureString);
				
				if (!winname) {
					alert("The window could not be opened. Please check if you have a popup blocker installed that may be preventing the window from opening.");
				}
				else
				{
					winname.focus();
				}				
			}			
function openWindow(url, windowName, featureString) 
{
	if (featureString == "")
	{
		featureString = "width=780,height=580,status=yes,scrollbars=yes,minimize=yes,top=10,left=10,resizable=1,toolbar=1,location=1,menubar=1";
	}

	winname = open (url, windowName, featureString);
	if (!winname) {
		alert("The window could not be opened. Please check if you have a popup blocker installed that may be preventing the window from opening. Try holding down the Ctrl key on your keyboard while clicking on the link.");
	}else 
	{
		winname.focus();
	}				
}

function clearLogin(e)
{
	if (e.value == "(enter email address)")
		e.value = "";
}

function defaultLogin(e)
{	
	if (e.value.length == 0)
	{
		e.value = "(enter email address)";
	}
}

function popHelp()
{
	window.open ("../keywordhelp.aspx?CompanyId=" + document.getElementById("txtCompanyID").value, null, "width=650,height=450,scrollbars=yes");
}		        

// Checking white spaces in a field

var whitespace = " \t\n\r";

function isEmpty(s)
{   
	return ((s == null) || (s.length == 0))
}
				
function isWhitespace (s)
{   
	var i;
	if (isEmpty(s)) return true;
	for (i = 0; i < s.length; i++)
	{   
		// Check that current character isn't whitespace.
		var c = s.charAt(i);
		if (whitespace.indexOf(c) == -1) return false;
	}
	// All characters are whitespace.
	return true;
}  // End Checking white spaces in a field


function alltrim(strLine)
{	var trimstr = ""
	trimstr = rtrim(ltrim(strLine))
	return trimstr
}

function ltrim(strLine)
{var trimstr = ""
	var blkflg = 0
	var len    = strLine.length
	for (var i=0; i<=len-1; i++)
	{if(strLine.charAt(i) != " " )
		{{
				trimstr= strLine.substring(i,len)
				blkflg = 1
				break }}}
	return trimstr
}	

function rtrim(strLine)
{var trimstr = ""
	var blkflg = 0
	var len    = strLine.length-1
	var i = len
	while (strLine.charAt(i) == " ") {i=i-1 }
	trimstr = strLine.substring(0,i+1)
	return trimstr
}
		
//End

//function for Search button / image
function goSearch(PID)
{
	var temp = document.getElementById("ucHeadermenucontrol_txtSiteSearch").value;
	if (temp == "" || temp == "(Search text)" || isWhitespace(temp) == true) 
	{
			alert("Please enter word(s) to search.");
			document.getElementById("ucHeadermenucontrol_txtSiteSearch").value = "";
			document.getElementById("ucHeadermenucontrol_txtSiteSearch").focus();
	}
	else
	{
	 if (PID !=null)
		window.location="SiteSearch.aspx?txtSearch="+temp+"&PageId="+PID;
		else
		window.location="SiteSearch.aspx?txtSearch="+temp;
	}
}
	
function clearTxtSearch(e)
{
	if (e.value == "(Search text)" ){
		e.value = "";
	}

}
			
function defaultTxtSearch(e)
{	
	if (e.value.length == 0)
		{
			e.value = "(Search text)";
		}
}	

function checkEnter(e)
{
	var code;
	
	if (!e) e = window.event;
	if (e.keyCode) 
	{
		code = e.keyCode;
	}
	else
	{
		code = e.which;
	}
	
	if (code == 13)
	{
		goSearch();
		return false;
	}
	return true;
}	

function queryString(field) {

// The window.location.search property gets the part of
// the url that follows the ? symbol, including the ? symbol.
// We then add on the substring() method to find the exact
// location of the substring within the querystring after
// the ? symbol. Instead of using a fixed index number as
// the argument for the indexOf() method we repeat the
// window.location.search property and search for the
// index of the ? symbol. We want to find the index
// immediately following the ? symbol, hence
// indexOf("?")+1, to retrieve our first
// field/value pair.

    var a = window.location.search.substring(window.location.search.indexOf("?")+1);

// Now that we've gotten everything following the ?
// symbol we need to split the string at every new field.
// We use the split() method to find each instance of
// the & symbol and split the string into each
// field/value pair.

    var q = a.split("&");

// Now, we'll loop through all the field/value pairs
// in the string and separate them.

    for(var x=0;x<q.length;x++) {

// Again we'll implement the split() method to separate
// the field/value pairs at the = symbol.

        var z = q[x].split("=");

// Once we've reached this point in the loop we check
// to see if the field z (which is the current field/value pair)
// matches the field we input into the queryString() function.
// z[0] is the first index value, which is the field name.

        if(z[0]==field) {

// If z[0] (the field name) matches the field name input
// into the queryString() function then we return the
// field value z[1].

            return(z[1]);
        }
    }
    return 0;
}
//End
function Continue(Agent,Relogin,BUId,IsIntranet)
			{
			    var CompanyId = document.getElementById('txtCompanyID').value;
			    var prefix = "";
			    
			    //dig one level deeper for intranet pages
				if (IsIntranet) {
				    prefix = "../"
				}
				
				if (Relogin)
				{
					eurl = "Redirect.aspx?CompanyID="+ CompanyId;
				}
				else
				{
					var VacancyId = document.getElementById('txtVacancyID').value
					//eurl = "../../Frameset.aspx?CompanyID="+ CompanyId + "&VacancyId=" + VacancyId;
					eurl = "Redirect.aspx?CompanyID="+ CompanyId + "&VacancyId=" + VacancyId;
				}	
				if (Agent){
					eurl+="&Agent=1"
				}
				eurl+="&BusinessUnitID=" + BUId
				awindow = openCentered(prefix + eurl, 795, 520, 'application', 'toolbar=yes,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes')	
			}	