//*******************************************************************************
//'* Purpose  : Commonly used Javascript Functions in Gulf Air Career Site.
//'* Date     : 19-Aug-2005
//'* Author   : Syed Abid
//'* 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 = 8;
				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();
	}				
}

// 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
}

var previous;
var ele;
function LoadPage(url)
{
	var iframe1 = document.getElementById("ifrmGA");
	iframe1.src = url;
	//insertIt();

}

function insertIt() 
{		
	oldDiv = document.getElementById('framediv');
	newDiv = document.createElement(oldDiv.tagName);
	newDiv.id = oldDiv.id;
	//alert(window.frames[0].document.body.innerHTML);
	newDiv.innerHTML = window.frames[0].document.body.innerHTML;
	oldDiv.parentNode.replaceChild(newDiv, oldDiv);		
} 

function sourceCheck(e)
{
	ele=(typeof event!=='undefined')? event.srcElement : e.target;
	if (ele.tagName=='A' && (ele.className=='LeftMenuHeadingLink1' || ele.className == 'LeftMenuHeadingLink'))
	{
	
		var parent = document.getElementsByName("hlnkLeftLink");

		for(i = 0; i < parent.length; i++)
		{
			parent[i].className = "LeftMenuHeadingLink";
		}
		ele.className = "LeftMenuHeadingLink1";
	}
}
			/*if (!previous)
			{
				ele.className = 'LeftMenuHeadingLink1';
			}
			else 
			{ 
					if (ele.className == 'LeftMenuHeadingLink') {
						ele.className = 'LeftMenuHeadingLink1';
						previous.className = 'LeftMenuHeadingLink';  
					}
					else
					{
						ele.className = 'LeftMenuHeadingLink';
						previous.className = 'LeftMenuHeadingLink1';  
					}
			}
			previous = ele;
			*/
	

function bubbledEvent()
{	
	if (window.captureEvents)
	{
		window.captureEvents(Event.CLICK);
		window.onclick=sourceCheck;
	}
	else
		document.onclick=sourceCheck;
		
}
		
//End

function resize_iframe1(id){
el=document.getElementById(id)
el.style.height="100px" // for Firefox and Opera
setTimeout("el.style.height=el.contentWindow.document.body.scrollHeight+'px'",10) // setTimeout required for Opera

}

function resize_iframe(id){
document.getElementById("ifrmGA").height="0"; // required for Moz, value can be "", null, or integer
document.getElementById('ifrmGA').height=window.frames["ifrmGA"].document.body.scrollHeight;

}
