function checkValidDate(txtDDElement,txtMMElement,txtYYElement,fieldName,allowEmpty){
	if(allowEmpty == false)
	{
	if (txtDDElement.selectedIndex==0)
	{
		alert("Please select a Day for " + fieldName)
		txtDDElement.focus()
		return false
	}
	if (txtMMElement.selectedIndex==0)
	{
		alert("Please select a Month for " + fieldName)
		txtMMElement.focus()
		return false
	}
	if (txtYYElement.selectedIndex==0)
	{
		alert("Please select a Year for " + fieldName)
		txtYYElement.focus()
		return false
	}
	}
	
	var userDay=txtDDElement[txtDDElement.selectedIndex].value
	var userMon=txtMMElement[txtMMElement.selectedIndex].value
	var userYear=txtYYElement[txtYYElement.selectedIndex].value
	var passedDate=new Date(userYear,userMon-1,userDay)
	var todays=new Date()
	var currdate= new Date(todays.getFullYear(),todays.getMonth(),todays.getDate())
	if(passedDate < currdate){
	alert("Please dont enter a past date");
	txtDDElement.focus()
	return false
	}
	if(passedDate.getDate()!=userDay || passedDate.getMonth()!=userMon-1 || passedDate.getFullYear()!=userYear){
	alert("Please enter a valid date");
	txtDDElement.focus()
	return false
	}
	return true;
}

function checkValidDateOfBirth(txtDDElement,txtMMElement,txtYYElement,fieldName,allowEmpty){
	if(allowEmpty == false)
	{
	if (txtDDElement.selectedIndex==0)
	{
		alert("Please select a Day for " + fieldName)
		txtDDElement.focus()
		return false
	}
	if (txtMMElement.selectedIndex==0)
	{
		alert("Please select a Month for " + fieldName)
		txtMMElement.focus()
		return false
	}
	if (txtYYElement.selectedIndex==0)
	{
		alert("Please select a Year for " + fieldName)
		txtYYElement.focus()
		return false
	}
	}
	
	var userDay=txtDDElement[txtDDElement.selectedIndex].value
	var userMon=txtMMElement[txtMMElement.selectedIndex].value
	var userYear=txtYYElement[txtYYElement.selectedIndex].value
	var passedDate=new Date(userYear,userMon-1,userDay)
	var todays=new Date()
	var currdate= new Date(todays.getFullYear(),todays.getMonth(),todays.getDate())
	if(parseFloat(passedDate.getDate())!=parseFloat(userDay) || parseFloat(passedDate.getMonth())!=parseFloat(userMon-1) || parseFloat(passedDate.getFullYear())!=parseFloat(userYear)){
	alert("Please enter a valid date");
	txtDDElement.focus()
	return false
	}
	return true;
}

function chkLength(txtElement,MinPwdLength,fieldName)
{
	if(txtElement.value.indexOf(' ')!=-1){
		alert(fieldName + " cannot have space/s");
		txtElement.focus();
		return false;
	}
	if (txtElement.value.length < MinPwdLength)
		{
		alert(fieldName + " must be atleast " + MinPwdLength + " characters");
		txtElement.focus();
		return false;
		}
		return true;
}

function checkAll(frm)
{
	//chkselect
	//chkall
	field = frm.chkselect;
	if(frm.chkall.checked == true)
	{
		if(field.length==null)
			field.checked=true;
		else
		{	
			for (i = 0; i < field.length; i++) 
				field[i].checked = true;
		}
	}	
	else
	{
		if(field.length==null)
			field.checked=false;
		else	
		{
			for (i = 0; i < field.length; i++) 
				field[i].checked = false;
		}	
	}
}

// function for all CHECKBOXES to check/check the 'chkall' CHECKBOX
function setchkall(field, fieldArr, frmName){
	if(field.checked == false) frmName.chkall.checked = false;
	else{
		var flag = false;
		if(fieldArr.length==null)
			flag=true;
		if(fieldArr.length!=null)
		{
			for(i=0; i<fieldArr.length; i++)
			{
				if(fieldArr[i].checked == true)
					flag = true;
				else
				{
					flag = false;
					break;
				}	
			}
		}
		if(flag == true) frmName.chkall.checked = true;
	}
}



//Validates dropdown select box.
function chkDDList(lstElement,fieldName)
{
	if (lstElement.selectedIndex<=0)
	{
		alert( "Please select a " + fieldName )
		lstElement.focus()
		return false;
	}
	else
	{
		return true;
	}
}

//Validates dropdown select box.
function chkDDListValue(lstElement,fieldName)
{
	if (lstElement.selectedValue=="")
	{
		alert( "Please select a " + fieldName )
		lstElement.focus()
		return false;
	}
	else
	{
		return true;
	}
}
//Validate a TextBox Input
function checkTextBox(txtElement,fieldName)
{
	
	if(ltrim(txtElement.value).length == 0)
	{
		alert("Please enter " + fieldName);
		txtElement.focus();
		return false;
	}
	return true;
}

//Validates a TextArea
function checkTextArea(txtElement,maxAllowedLength,fieldName,allowEmpty)
{
	if(allowEmpty == false && ltrim(txtElement.value).length == 0)
	{
		alert("Your " + fieldName  + " must be entered.");
		txtElement.focus();
		return false;
	}
	if(txtElement.value.length > maxAllowedLength)
	{			
		alert("You have entered " + txtElement.value.length + " characters in the " + fieldName + ". \nThe Maximum number of characters allowed for this field is " + maxAllowedLength);
		txtElement.value = txtElement.value.substring(-1,maxAllowedLength);
		return false;
	}
	return true;
}

//checking if a checkbox is selected
function checkCheckBox(chkElement,fieldName,isAlert) 
{	
	if(isNaN(chkElement.length)) //ie if its not a group
	{ 
		if(!chkElement.checked) 
		{
			if (isAlert)
			{
				alert("Please select atleast one " + fieldName + "")
			}
			return false;
		}
		else
		{
			return true;
		}
	}
	else      //ie if it is a group
	{	var isChecked=false
		for(i=0;i<chkElement.length;i++)  //
		{
			isChecked = isChecked || chkElement[i].checked
		}
		if (!isChecked)
		{
			if (isAlert)
			{
				alert("Please select atleast one " + fieldName + "")
			}
				return false;
		}
		else
		{
			return true;
		}
	}
}

//Validates Radio options
function checkRadio(optElement,fieldName)
{
	if(isNaN(optElement.length))
	{ 
		if(!optElement.checked) 
		{
			alert("Please select a '" + fieldName + "'")
		
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{	var isChecked=false
		for(i=0;i<optElement.length;i++)  //
		{
			isChecked = isChecked || optElement[i].checked					 
			
		}
		if (!isChecked)
		{
			alert("Please select a '" + fieldName + "'")
			optElement[0].focus();
			return false
		}
		else
		{
			return true;
		}
	}
}	

//Validates Email. NS 4+ or IE 4+
function checkEmail(txtElement,fieldName,allowEmpty)
{
	var str= txtElement.value
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if(allowEmpty == false && str.length == 0)//empty value is not allowed
	{
		alert("Please enter " + fieldName);
		txtElement.focus();
		return false;
	}
	if(allowEmpty == true && str.length == 0)//empty value is allowed
	{
		return true;
	}
	else 
	{
		if (filter.test(str))
			testresults=true
		else
		{
			alert("Please enter a valid Email Address!");
			txtElement.focus();
			testresults=false
		}
	}	
	return (testresults)
}

//Validates Pin/Phone/Fax
function chkPinPhoneFax(txtElement,fieldName,allowEmpty)
{
	if(allowEmpty==false && txtElement.value.length == 0)
	{
		alert("Please enter " + fieldName );
		txtElement.focus();
		return false;
	}
	if(txtElement.value.search("[^0-9 ,/+-]")!=-1)
	{
		alert("Please enter a valid " + fieldName);
		txtElement.focus();
		return false;
	}
	return true;
}

//Validates Numeric text field
function checknumber(txtElement,fieldName,allowEmpty)
{
	var x=txtElement.value
	var anum=/(^\d+$)|(^\d+\.\d+$)/
	if(allowEmpty==false && x.length == 0)
	{
		alert("Please enter " + fieldName);
		txtElement.focus();
		return false;
	}
	if (anum.test(x))
		testresult=true
	else
	{
		alert("Please enter a valid " + fieldName );
		txtElement.focus();
		testresult=false
	}
	return (testresult)
}
function checkPrecision(txtElement,fieldName,allowEmpty)
{
	var x=txtElement.value
	var anum=/(\.)[0-9]{1}$/
	if(allowEmpty==false && x.length == 0)
	{
		alert("Please enter " + fieldName);
		txtElement.focus();
		return false;
	}
	if (anum.test(x))
		testresult=true
	else
	{
		alert("Please enter a valid " + fieldName +" It takes only numerics with one precision" );
		txtElement.focus();
		testresult=false
	}
	
	return (testresult)
}


//function to check special characters like @#$%^&*()+ except _ , 'and . in the string for fields like User ID
function chkSpecialChar(txtElement)
{
	if(txtElement.value.search("[^0-9a-z,.'&/\A-Z -]")!=-1) 
	{
		return false;
	}
	return true;
}
//Left Trim a string
function ltrim(strText) 
{
	return strText.replace(/^\s+/,'');
}
//Right trim a string
function rtrim(strText) 
{
	return strText.replace(/\s+$/,'');
}
//Trim a string

function trim(strText) 
{
	
	return strText.replace(/^\s+/,'').replace(/\s+$/,'');
}


//function to validate Date in MMDDYYYYY
function chkMMDDYY(txtMMElement,txtDDElement,txtYYElement,fieldName,allowEmpty)
{	
	if(allowEmpty == false)
	{
		if (txtMMElement.selectedIndex==0)
		{
			alert("Kindly select a month for " + fieldName)
			txtMMElement.focus()
			return false
		}
		if (txtDDElement.selectedIndex==0)
		{
			alert("Kindly select a day for " + fieldName)
			txtDDElement.focus()
			return false
		}
		if (txtYYElement.selectedIndex==0)
		{
			alert("Kindly select a year for " + fieldName)
			txtYYElement.focus()
			return false
		}
	}

	if( allowEmpty == true && txtDDElement.selectedIndex==0 && 
		txtMMElement.selectedIndex==0 && txtYYElement.selectedIndex==0)
	{
		//empty value is allowed
		return true;
	}
	else
	{
		var i=0;
		var j=0;
		var strDate = "" + txtMMElement[txtMMElement.selectedIndex].value;
		strDate = strDate + "/" + txtDDElement[txtDDElement.selectedIndex].value;
		strDate = strDate + "/" + txtYYElement[txtYYElement.selectedIndex].value;

		j= strDate.indexOf("/",i);
		var strMnth=strDate.substring(i,j);
		
		i=strMnth.length + 1;
		j= strDate.indexOf("/",i);
		var strDay=strDate.substring(i,j);
		
		j=j+3;
		i=strDate.length
		var strYear=strDate.substring(j,i);

		strMnth--;
		dtDate=new Date(strYear,strMnth,strDay);
		var dtDay=dtDate.getDate();
		var dtMnth=dtDate.getMonth();
		var dtYear=dtDate.getYear();

		if (strYear == "")
		{
			alert("Kindly select a valid " + fieldName)
			txtDDElement.focus()
			return false;
		}
		
		if((strDay!=dtDay) || (strMnth!=dtMnth) || (strYear!=dtYear))
		{
			alert("Kindly select a valid " + fieldName)
			txtDDElement.focus()
			return false;	
		}
		return true;
	}
}


// When date is passed as sting in a single text box
function chkDDMMYYString(txtElement,fieldName,allowEmpty)
{	
	if(allowEmpty == false)
	{
		if(ltrim(txtElement.value).length == 0)
		{	
			alert("Your " + fieldName + " must be entered.");
			txtElement.focus();
			return false;
		}	
	}
	if( allowEmpty == true && (ltrim(txtElement.value).length == 0))
	{
		//empty value is allowed
		return true;
	}
	else	
	{		
		var i=0;
		var j=0;
		var strDate = txtElement.value;
		j= strDate.indexOf("/",i);
		var strMnth=strDate.substring(i,j);		
		i=strMnth.length + 1;
		j= strDate.indexOf("/",i);
		var strDay=strDate.substring(i,j);		
		//for checking valid year
		var isValidYearStr = strDate.substring(j+1, strDate.length);		
		j=j+3;
		i=strDate.length
		var strYear=strDate.substring(j,i);
		strMnth--;
		dtDate=new Date(strYear,strMnth,strDay);
		var dtDay=dtDate.getDate();
		var dtMnth=dtDate.getMonth();
		var dtYear=dtDate.getYear();
		if(dtYear == 0)
		{
			if(parseInt(strDay) <= 29)
			{
				dtDay = strDay;					
				if(parseInt(strDay) == 29) strMnth++; 
			}
		}
		if((strDay!=dtDay) || (strMnth!=dtMnth) || (strYear!=dtYear) || isNaN(dtYear) || (strYear == ""))
		{
			alert("Invalid '" + fieldName + "'")
			txtElement.focus()
			return false;	
		}
		if(parseInt(isValidYearStr) < 1900 || isValidYearStr.search("[^0-9]") != -1){
			alert("Invalid year in '" + fieldName + "'")
			txtElement.focus()
			return false;	
		}
		return true;
	}
}

//function to check special characters like @#$%^&*()_+. in the string for fields like User Name
//which can allow spaces, commas, hyphen etc.
function chkUncommonspecialChar(txtElement,fieldName,allowEmpty){
	var tempStr = trim(txtElement.value);
	var specChar = "~!@#$%^&*()|";
	var checkstring = /[^0-9a-z A-Z _]/

	if(allowEmpty == false && tempStr == ""){
		alert(fieldName + "cannot be left blank");
		txtElement.focus();
		return false;
	}

	for(i=0; i<specChar.length; i++){
		if(tempStr.indexOf(specChar.charAt(i)) != -1){
			alert("Incorrect " + fieldName + ". No special characters allowed.");
			txtElement.focus();
			return false;
		}
	}

	if (txtElement.value.search(checkstring)!=-1)
	{
			alert("Incorrect " + fieldName);
			txtElement.focus();
			return false;
	}
	
	return true;
}

//function to check the minimumlength of a string or password
function chkPasswordLength(Password,MinPwdLength,fieldName)
{
	if (Password.value.length < MinPwdLength)
		{
		alert(fieldName + " must be atleast " + MinPwdLength + " characters");
		Password.focus();
		return false;
		}
		return true;
}



function chkNumInPwd(txtElement)
{
	var num_valid="123456789";
	var tempStr = txtElement.value;
	
	for(i=0; i<num_valid.length; i++){
		if(tempStr.indexOf(num_valid.charAt(i)) != -1){
		// it means num_valid and tempStr matches each other
			return true;
		}
	}
			return false;
}

function chkCharactersInPwd(txtElement)
{
	var char_valid="abcdefghijklmnopqrstuvwxyz";
	var tempStr = txtElement.value;
	
	for(i=0; i<char_valid.length; i++){
		if(tempStr.indexOf(char_valid.charAt(i)) != -1){
		// it means num_valid and tempStr matches each other
			return true;
		}
	}
			return false;
}

function chkCapCharactersInPwd(txtElement)
{
	var char_valid="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var tempStr = txtElement.value;
	
	for(i=0; i<char_valid.length; i++){
		if(tempStr.indexOf(char_valid.charAt(i)) != -1){
		// it means num_valid and tempStr matches each other
			return true;
		}
	}
			return false;
}


function chkPassword(txtElement,fieldName,allowEmpty)
{
	if(allowEmpty==false && txtElement.value.length == 0)
	{
		alert("Please enter your " + fieldName + "");
		txtElement.focus();
		return false;
	}
	
	/*
	var checkstring = /[^0-9a-z A-Z _]/

	if (txtElement.value.search(checkstring)!=-1)
	{
		alert("Please enter a valid " + fieldName + ".\nIt can only include numbers and characters");
		txtElement.focus();
		return false;
	}

	if (txtElement.value != "")
	{
		numOutput = chkNumInPwd(txtElement);
		if(!numOutput)
		{
			alert(fieldName + " should contain Numeric values");
			txtElement.focus();
			return false;
		}
	
		CharOutput = chkCharactersInPwd(txtElement);
		if(!CharOutput)
		{
			alert( fieldName + " should contain Character values");
			txtElement.focus();
			return false;
		}
		
		CharOutputCap = chkCapCharactersInPwd(txtElement);
		if(!CharOutputCap)
		{
			alert(fieldName + " should contain Capital Character values");
			txtElement.focus();
			return false;
		}
	}
	*/
	
	return true;
}

//function to validate a TextBox Input
function chkTxtBox(txtElement,fieldName)
{
//alert(txtElement);
	if(ltrim(txtElement.value).length == 0)
	{
		alert(fieldName);
		txtElement.focus();
		return false;
	}
	return true;
}

		// FUNCTION FOR POPUP WINDOW
var strWin=null;
function OpenWin(strURL,winWidth,winHeight) 
{
	var chngpass;
	strWinName='EtihadPopup'
	winTop=0; 
	winLeft=0;
	winLeft=Math.floor((Math.abs(screen.availWidth-winWidth))/2);
	winTop= Math.floor((Math.abs(screen.availHeight-winHeight))/2);
	try{
	if(strWin!=null)
	{
		//alert();
		
		strWin.close();
	}
	}catch (e){};
	strWin=window.open(strURL,strWinName,'top= '+ winTop + ',left=' + winLeft + ',width=' + winWidth + ',height= '+winHeight+',toolbar=nomenubar=no,location=no,directories=no,status=no,resizable=yes,scrollbars=yes,scrollbar=yes');
	strWin.focus();

	//return strWin;
	//return false;
	
}

function OpenWin1(strURL,winWidth,winHeight) 
{
	var chngpass;
	strWinName='EtihadPopup'
	winTop=0; 
	winLeft=0;
	winLeft=Math.floor((Math.abs(screen.availWidth-winWidth))/2);
	winTop= Math.floor((Math.abs(screen.availHeight-winHeight))/2);
	try{
	if(strWin!=null)
	{
		//alert();
		
		strWin.close();
	}
	}catch (e){};
	strWin=window.open(strURL,strWinName,'top= '+ winTop + ',left=' + winLeft + ',width=' + winWidth + ',height= '+winHeight+',toolbar=nomenubar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no,scrollbar=no');
	strWin.focus();

	//return strWin;
	//return false;
	
}


function chkTextAlpha(txtElement,fieldName,allowEmpty)
{

	var char_valid="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var tempStr = txtElement.value;
	
	if(allowEmpty==false && txtElement.value.length == 0)
	{
		alert("Please enter " + fieldName );
		txtElement.focus();
		return false;
	}
	if(txtElement.value.search("[^ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]")!=-1)
	{
		alert("Please enter a valid " + fieldName);
		txtElement.focus();
		return false;
	}
	return true;
}

// added by pradeep on 29Aug, 05
function getconfirm() 
{ 
	if (confirm("Are you sure you want to delete this Country Admin?")==true) 
	return true; 
	else 
	return false; 
}
function ValidateMod7(txtElement)
{
	//alert(txtElement.value.length);
	if(txtElement.value.length < 8 )
	{
		alert("Please enter a valid AWB Number");
		return false;
	}
	if(!chkPinPhoneFax(txtElement,"AWB Number",false))
	{
		return false;
	}	
	var data1 = parseFloat(txtElement.value.substring(0,7)); 
	var data2 =	parseFloat(txtElement.value.substring(7));
	var modVal = data1 % 7;
	if(modVal != data2)
	{
		alert("Please enter a valid AWB Number. Mod 7 validation Failed");
		return false;
	}
	return true;		
}

//Function Added by Rajiv. R for Validating Package Details in Online bookings form
function IsNumeric(txtElement,fieldName,allowEmpty)
{
   var strValidChars = "0123456789.";
   var strChar;
   var blnResult = true;

   if (txtElement.value.length == 0) 
   {
		alert(fieldName + ' cannot be blank');
		return false;
   }
  
   for (i = 0; i < txtElement.value.length && blnResult == true; i++)
   {
		strChar = txtElement.value.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
		{
			alert('Please enter a valid'+fieldName);
			blnResult = false;
		}
   }
   return blnResult;
 }

