function showCalendar(ReturnField)
{
	var urlString = "popCalendar.aspx?ReturnField=" + ReturnField;
	popupWindowWithStyle(174, 192, urlString, "PopupCalendar", "no", "no", "no");
}
	
function popupWindow(width, height, url, WindowName)
{
	var left			= ((window.screen.availWidth /2) - (width/2)) - 20;
	var top				= ((window.screen.availHeight /2) - (height/2)) - 40;
	var WindowStyle		= "height=" + height + ",width=" + width + ",left=" + left + ",top=" + top + ",status=yes,scrollbars=no,toolbars=no";
									
	var PopupWindow = window.open(url,WindowName,WindowStyle);
	PopupWindow.focus();
}

function popupWindowWithStyle(width, height, url, WindowName, Status, Scrollbars, Toolbars, Resize) {
	var left			= ((window.screen.availWidth /2) - (width/2)) - 20;
	var top				= ((window.screen.availHeight /2) - (height/2)) - 40;
	
	if (Resize == "")
	{
		Resize = "no";
	}
	var WindowStyle		= "height=" + height + ",width=" + width + ",left=" + left + ",top=" + top + ", resizable=" + Resize + ", status=" + Status + ",scrollbars=" + Scrollbars + ",toolbar=" + Toolbars;
									
	var PopupWindow = window.open(url,WindowName,WindowStyle);
	PopupWindow.focus();
}

function showDynamicHelp(ModuleID,FunctionID)
{
	var Qstr="M=" + ModuleID + "&F=" + FunctionID;
		popupWindowWithStyle(607, 387,"hlpContent.aspx?" + Qstr , "viewHelp", "yes", "yes", "no", "no");						
}

function showAttachment(Id, AttachmentId, ViewType)
{
	switch (ViewType.toUpperCase())
		{
			
			case "PROPOSAL" :
						popupWindowWithStyle(600, 400,"proViewAttachment.aspx?ProposalId=" + Id + "&AttachmentSeqId=" + AttachmentId, "viewAttachment", "yes", "auto", "no", "yes");
						break;
			case "INVOICE" :
						popupWindowWithStyle(600, 400,"invViewAttachment.aspx?SeqID=" + Id + "&ContentID=" + AttachmentId, "viewAttachment", "yes", "yes", "yes", "yes");
						break;
			case "CABINCREW" :
						
						if (AttachmentId == 'Passport Size')
						{
							popupWindowWithStyle(314, 477,"crwPreviewPhotoFrame.aspx?Id=" + Id + "&PhotoType=" + AttachmentId , "viewCabinCrewPhoto", "yes", "no", "no", "no");
						}
						else
						{
							popupWindowWithStyle(348, 477,"crwPreviewPhotoFrame.aspx?Id=" + Id + "&PhotoType=" + AttachmentId , "viewCabinCrewPhoto", "yes", "no", "no", "no");
						}						
						break;
						
			case "CABINCREW_EVENTS" :						
						popupWindowWithStyle(607, 387,"envCabinCrewPopup.aspx?Id=" + Id , "viewCabinCrewDetails", "yes", "no", "no", "no");						
						break;
		}
}

function popCabinCrewPhotoUpload(CabinCrewId)
{
	popupWindow(440, 150, "popCrwPhotoUpload.aspx?Id=" + CabinCrewId, "updateCabinCrewPhoto");
}

function validateControls(Controls, pageForm)
{
	var sourceForm	= pageForm;
	var aryControls = Controls.split("|");						
	var aryItem;
	var lstItem;
	var txtItem;
	var rdoItem;
	var rdoElements;
	var rdoChecked;
	var Msg = "";
		
	for(var Index=0; Index < aryControls.length; Index++)
	{
		aryItem = aryControls[Index].split("/");
		with (sourceForm)
		{
			if (aryItem[0].substr(0,3) == "lst")
			{
				lstItem = eval(aryItem[0]);
				if (lstItem.selectedIndex != -1)
				{
					if (lstItem.options[lstItem.selectedIndex].value == "")
					{
						if (Msg == "")
						{
							Msg = "* select a value from " + aryItem[1] + " drop down list\n";
						}
						else
						{
							Msg = Msg + "* select a value from " + aryItem[1] + " drop down list\n";
						}
					}
				}
				else
				{
					if (Msg == "")
					{
						Msg = "* select a value from " + aryItem[1] + " drop down list\n";
					}
					else
					{
						Msg = Msg + "* select a value from " + aryItem[1] + " drop down list\n";
					}
				}
			}
			else if (aryItem[0].substr(0,3) == "rdo")
			{
				rdoItem		= eval(aryItem[0]);
				rdoElements = rdoItem.length;
				rdoChecked	= false;
				
				for (var count = 0; count < rdoElements; count++)
				{
					if (rdoItem[count].checked)
					{
						rdoChecked = true;
						break;
					}
				}
				
				if (rdoChecked == false)
				{
					if (Msg == "")
					{
						Msg = "* select a radio button to indicate " + aryItem[1] + "\n";
					}
					else
					{
						Msg = Msg + "* select a radio button to indicate " + aryItem[1] + "\n";
					}
				}
			}
			else
			{						
				txtItem			= eval(aryItem[0]);																
				if (txtItem.value == "")						
				{	
					if (Msg == "")
					{
						Msg = "* value for " + aryItem[1] + "\n";			
					}
					else
					{
						Msg = Msg + "* value for " + aryItem[1] + "\n";			
					}							
				}						
			}
		}
	}	
	return Msg;
}

function contextMenu()
{
	var oContext = window.createPopup();
	var _IsSuccessful = false;
	if (window.opener)
	{
		oContext.document.body.innerHTML = window.opener.top.ContextMenu.innerHTML;
		_IsSuccessful = true;
	}
	else
	{	
		if (window.top.frames[0])
		{
			oContext.document.body.innerHTML = window.top.ContextMenu.innerHTML;	
			_IsSuccessful = true;
		}
	}
	
	if (_IsSuccessful == true)
	{
		oContext.show(event.offsetX + 5, event.offsetY, 200, 153, document.body);	
	}
}

function checkFieldValue(Field, ErrorMessage, Mode)
{	
	var Msg = "Invalid character(s) found and it will be\nremoved from the value specified";
	var IsError = false;
	switch (Mode.toUpperCase())
	{
		
		case "ALPHA" :
						if (checkForAlphaChar(Field.value) == false)
						{
							Msg = (ErrorMessage.length > 0) ? (ErrorMessage + "\n\n" + Msg) : Msg;
							alert(Msg);
							Field.value = Field.value.replace(/[^a-zA-Z]/g, "");
							Field.focus();
						}
						break;
						
		case "ALPHANUM" :
						if (checkForAlphaNumChar(Field.value) == false)
						{
							Msg = (ErrorMessage.length > 0) ? (ErrorMessage + "\n\n" + Msg) : Msg;
							alert(Msg);
							Field.value = Field.value.replace(/[^a-zA-Z0-9]/g, "");
							Field.focus();
						}
						break;
		case "ALPHASPLNUM" :
						if (checkForAlphaSpecialNumChar(Field.value) == false)
						{
							Msg = (ErrorMessage.length > 0) ? (ErrorMessage + "\n\n" + Msg) : Msg;
							alert(Msg);
							Field.value = Field.value.replace(/[^a-zA-Z0-9\-\s\/ ]/g, "");
							Field.focus();
						}
						break;
						
		case "ALPHASPL" :
						if (checkForAlphaSpecialChar(Field.value) == false)
						{
							Msg = (ErrorMessage.length > 0) ? (ErrorMessage + "\n\n" + Msg) : Msg;
							alert(Msg);
							Field.value = Field.value.replace(/[^a-zA-Z0-9\-\s\/,<=.]/g, "");
							Field.focus();
						}
						break;
						
		case "FREETEXT" :
						if (checkForFreeTextChar(Field.value) == false)
						{
							Msg = (ErrorMessage.length > 0) ? (ErrorMessage + "\n\n" + Msg) : Msg;
							alert(Msg);
							Field.value = Field.value.replace(/[^a-zA-Z0-9\-\s\/,=.%:;?!$&]/g, "");
							Field.focus();
						}
						break;						
						
		
		case "ALPHANUMHYPNDOT" :
						if (checkForAlphaNumHypnDotChar(Field.value) == false)
						{
							Msg = (ErrorMessage.length > 0) ? (ErrorMessage + "\n\n" + Msg) : Msg;
							alert(Msg);
							Field.value = Field.value.replace(/[^a-zA-Z0-9\-\s\.]/g, "");
							Field.focus();
						}
						break;
						
		case "EMAIL" :
						if (checkOnlyEmail(Field.value) == false)
						{
							Msg = (ErrorMessage.length > 0) ? (ErrorMessage + "\n\n" + Msg) : Msg;
							alert(Msg);							
							Field.focus();
						}
						break;
						
		case "WEB" :
						if (checkOnlyWeb(Field.value) == false)
						{
							Msg = (ErrorMessage.length > 0) ? (ErrorMessage + "\n\n" + Msg) : Msg;
							alert(Msg);							
							Field.focus();
						}
						break;
						
		case "NON_QUOTE_DBL_QUOTE" :
						//Once the replaceChar function is placed in this file this has to be uncommented
						/*if (checkForSpaceQuoteDblQuoteChar(Field.value) == false)
						{
							Msg = "Invalid character(s) found and it will be\nremoved from the value specified.\n\nPlease specify value without quotes or\ndouble-quotes.";
							Msg = (ErrorMessage.length > 0) ? (ErrorMessage + "\n\n" + Msg) : Msg;
							alert(Msg);
							Field.value = replaceChar(Field.value,"'","");
							Field.value = replaceChar(Field.value,'"',"");
							Field.focus();
						}
						break;*/
						
						if (checkForSpaceQuoteDblQuoteChar(Field.value) == false)
						{
							Msg = (ErrorMessage.length > 0) ? (ErrorMessage + "\n\n" + Msg) : Msg;
							alert(Msg);
							Field.value = Field.value.replace(/[^a-zA-Z0-9\-\s\/,=.:;%?!$&]/g, "");
							Field.focus();
						}
						break;
						
		case "NUM" :
						if (checkForNum(Field.value) == false)
						{
							Msg = (ErrorMessage.length > 0) ? (ErrorMessage + "\n\n" + Msg) : Msg;
							alert(Msg);
							Field.value = Field.value.replace(/[^0-9\-\s\.]/g, "");
							Field.focus();
						}
						break;
						
		case "INT" :
						if (checkForInt(Field.value) == false)
						{
							Msg = (ErrorMessage.length > 0) ? (ErrorMessage + "\n\n" + Msg) : Msg;
							alert(Msg);
							Field.value = Field.value.replace(/[^0-9]/g, "");
							Field.focus();
						}
						break;
		case "DATE" :
						if (checkForDate(Field.value) == false)
						{
							Msg = "Date not valid";
							alert(Msg);
							Field.focus();
						}
						break;
	}	
}

//Function to check alpha
function checkForAlphaChar(str)
{
	return ((str!="")?(str.search( /[^a-zA-Z]+/ ) == -1):true);
}

//Function to check alpha and numbers
function checkForAlphaNumChar(str)
{
	return ((str!="")?(str.search( /[^a-zA-Z0-9]+/ ) == -1):true);
}

//Function to check alpha and numbers
function checkForAlphaSpecialNumChar(str)
{
	return ((str!="")?(str.search( /[^a-zA-Z0-9\-\s\/ ]+/ ) == -1):true);
}

//Function to check alpha with hyphen, space, /, comma, <, = and fullstop
function checkForAlphaSpecialChar(str)
{
	return ((str!="")?(str.search( /[^a-zA-Z0-9\-\s\/,<=.]+/ ) == -1):true);
}

//Function to check alpha with hyphen, space, /, comma, <, = and fullstop
function checkForFreeTextChar(str)
{
	return ((str!="")?(str.search( /[^a-zA-Z0-9\-\s\/,=.%:;?!$&]+/ ) == -1):true);
}

//Function to check alpha with hyphen, space, /, comma and fullstop
function checkForAlphaNumHypnDotChar(str)
{
	return ((str!="")?(str.search( /[^a-zA-Z0-9\-\s\.]+/ ) == -1):true);
}

//Function to check alpha with hyphen, space, /, comma and fullstop
function checkForInt(str)
{
	return ((str!="")?(str.search( /[^0-9]+/ ) == -1):true);
}

//Function to check only email id
function checkOnlyEmail(str){	
	return ((str!="")?((str.search( /^\w+((-\w+)|(\.\w+)|(\_\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]{2,5}$/ ) != -1)&&(str.lastIndexOf("@")==str.indexOf("@"))):true);
}

//Function to check only web address
function checkOnlyWeb(str){	
	return ((str!="")?((str.search( /^\w+((-\w+)|(\.\w+)|(\_\w+))*\.[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]{2,5}((\/){0,1}[A-Za-z0-9])*((\.[A-Za-z0-9]*){0,1})$/ ) != -1)&&(str.lastIndexOf("http://")==-1)):true);
	//((\/){0,1}[A-Za-z0-9])*
}

//Function to check single and double quotes
function checkForSpaceQuoteDblQuoteChar(str)
{
	return ((str.indexOf("'") == -1) && (str.indexOf('"') == -1))
}

//Function to check alpha and numbers
function checkForNum(str)
{
	return ((str!="")?(str.search( /[^0-9/.]+/ ) == -1):true);
}
//Function to check date format as dd-mm-yyyy
function checkForDate(str)
{
	return ((str!="")?(str.search( /^((0[1-9])|(1[0-9])|(2[0-9])|(3[0-1]))\-(([1-9])|(0[1-9])|(1[0-2]))\-((\d{2})|(\d{4}))$/ ) == -1):true);
}

function replaceOnlySpacesString(str)
{
	return str.replace(/(^\s*)|(\s*$)/g, ""); 
}

//Function will convert string to upper case
function UCase(InputString)
{	
	if (InputString.length == 0)
	{
		//alert(InputString);
		return InputString;
	}
	else
	{
		//alert(InputString.toUpperCase());
		return InputString.toUpperCase();
	}
}

//Function will convert input Field to upper case ' added by wakil 21 jan 2006
function UCaseField(Field)
{	
	var inputField = document.all.item(Field);
	
	if (inputField.value.length == 0)
	{
		
		
	}
	else
	{
		inputField.value=inputField.value.toUpperCase();
	}
}

//Function will convert string to lower case
function LCase(InputString)
{	
	if (InputString.length == 0)
	{
		return InputString;
	}
	else
	{
		return InputString.toLowerCase();
	}
}

function TrimToSize(Field, Size)
{
	if (Field.value.length > Size)
	{
		Field.value = Field.value.substr(0,Size);
	}
}

function CheckFieldLength(Field, MaxLength)
{
	var inputField = document.all.item(Field);
	
	if (inputField.value.length > MaxLength)
	{
		alert("Please note:\n\nMaximum allowed characters for this field is " + MaxLength + " characters.\nThe extra characters will be removed");
		inputField.value = inputField.value.substr(0, MaxLength);
	}	
}

function GetSelected(Field, Value)
{
	for (var index = 0; index < Field.length; index++)
	{
		if (Field[index].value == Value)
		{
			Field[index].selectedIndex = index;			
			Field.value = Value;
			break;
		}
	}
}

function GetMultiSelected(Field, Value)
{
	var aryValue = Value.split(",");
					
	for (var index = 0; index < Field.length; index++)
	{
		for (var count = 0; count < aryValue.length; count++)
		{
			if (Field[index].value == replaceOnlySpacesString(aryValue[count]))
			{			
				Field[index].selected = true;
				break;
			}
		}
	}
}

function InchesToCm(InchInputField, CmInputField)
{
	InchInputField.value = replaceOnlySpacesString(InchInputField.value);
	if ((replaceOnlySpacesString(InchInputField.value) != "") && (checkForNum(InchInputField.value) == true))
	{
		InchInputField.value = (Number(InchInputField.value)).toFixed(2);
		CmInputField.value= ((InchInputField.value) * 2.54).toFixed(2);					
	}
	else
	{
		InchInputField.value = "";
		CmInputField.value = "";
	}
}

function CmToInch(CmInputField, InchInputField)
{
	CmInputField.value = replaceOnlySpacesString(CmInputField.value);
	if ((replaceOnlySpacesString(CmInputField.value) != "") && (checkForNum(CmInputField.value) == true))
	{
		CmInputField.value = (Number(CmInputField.value)).toFixed(2);
		InchInputField.value = (CmInputField.value / 2.54).toFixed(2);
	}
	else
	{
		CmInputField.value = "";
		InchInputField.value = "";
	}
}

function CheckFileType(fname)
			{
				var isValidFileType = false;
				var vfilename;
				var x1,testXls;
				
				try
				{
					vfilename = fname; 
				
					if (vfilename.value != "" )
						{
							x1=vfilename.value.lastIndexOf(".");
							testXls=vfilename.value.substring(x1,x1+4);
							
							if(testXls.toUpperCase()!= ".XLS" && testXls.toUpperCase()!= ".DOC" && testXls.toUpperCase()!= ".PPT" && testXls.toUpperCase()!= ".RTF" && testXls.toUpperCase()!= ".TXT" && testXls.toUpperCase()!= ".PDF" && testXls.toUpperCase()!= ".ZIP" && testXls.toUpperCase()!= ".JPEG" && testXls.toUpperCase()!= ".JPG" && testXls.toUpperCase()!= ".GIF" && testXls.toUpperCase()!= ".PNG" && testXls.toUpperCase()!= ".BMP" && testXls.toUpperCase()!= ".MDI")
							{
								//alert("Please browse only appropiate excel file");
								isValidFileType = false;
							}
							else
							{
								isValidFileType = true;
							}
						}
						else
						{
							isValidFileType = false;
						}
				}
				catch(e) 
				{ 
					isValidFileType = false;
				}
				return isValidFileType;
			}

function daysBetween(dy,mo,yr)
	{
		
		var checkDateString = opener.checkField.value;
		var checkDateArray  = checkDateString.split("-");
		var nMonth          = getMonth(checkDateArray[1]);
					
		var myval;
		var diff;
		
		//var nDate = new Date(); // current date (local)		
		//var nTime = nDate.getTime(); // current time (UTC)
		
		var nDate = Date(checkDateArray[0]/nMonth/checkDateArray[2]);
		var nTime = Date.UTC(checkDateArray[2], nMonth - 1, checkDateArray[0]);
		
		var dTime = Date.UTC(yr, mo - 1, dy); // specified time (UTC)		
		var mydt = Date(dy/mo/yr);
		
		var bTime = Math.abs(nDate - mydt)  // time difference
		myval = (dTime -nTime)
			

		diff = parseInt(myval / (1000 * 60 * 60 * 24));		
		return diff;
	}
	
	function getMonth(MonthName)
	{
		var nMonth = 0;
		
		switch (MonthName)
			{	
				case "Jan" :
					nMonth = 1;
					break;	
				case "Feb" :
					nMonth = 2;
					break;	
				case "Mar" :
					nMonth = 3;
					break;	
				case "Apr" :
					nMonth = 4;
					break;	
				case "May" :
					nMonth = 5;
					break;	
				case "Jun" :
					nMonth = 6;
					break;	
				case "Jul" :
					nMonth = 7;
					break;	
				case "Aug" :
					nMonth = 8;
					break;	
				case "Sep" :
					nMonth = 9;
					break;	
				case "Oct" :
					nMonth = 10;
					break;	
				case "Nov" :
					nMonth = 11;
					break;	
				case "Dec" :
					nMonth = 12
					break;
			}
			return nMonth;
	}
	
	function Trim(TRIM_VALUE)
	{
		 
		if(TRIM_VALUE.length < 1)
		{
			return "";
		}
		TRIM_VALUE = RTrim(TRIM_VALUE);
		TRIM_VALUE = LTrim(TRIM_VALUE);
		if(TRIM_VALUE=="")
		{
			return "";
		}
		else
		{
			return TRIM_VALUE;
		}
	} //End Function

	function RTrim(VALUE)
	{
		var w_space = String.fromCharCode(32);
		var v_length = VALUE.length;
		var strTemp = "";
		if(v_length < 0)
		{
			return"";
		}
		var iTemp = v_length -1;

		while(iTemp > -1)
		{
			if(VALUE.charAt(iTemp) == w_space)
			{
			}
			else
			{
				strTemp = VALUE.substring(0,iTemp +1);
				break;
			}
			iTemp = iTemp-1;

		} //End While
		return strTemp;

	} //End Function

	function LTrim(VALUE)
	{
		var w_space = String.fromCharCode(32);
		if(v_length < 1)
		{
			return"";
		}
		var v_length = VALUE.length;
		var strTemp = "";

		var iTemp = 0;

		while(iTemp < v_length)
		{
			if(VALUE.charAt(iTemp) == w_space)
			{
			}
			else
			{
				strTemp = VALUE.substring(iTemp,v_length);
				break;
			}
			iTemp = iTemp + 1;
		} //End While
		return strTemp;
	} //End Function


function SignOut()
{
	window.top.close();
}