//***********************************************************************
//Function Name : fnCheckNull
//Author		: TCS
//Date			: 18th Jan, 2006
//Input			: Field value, Field name
//Output		: Returns true if field is not null else false
//Purpose		: Checks if the field is null or not
//***********************************************************************

function fnCheckNull(astrFieldValue,astrFieldName)
{
	if (stripSpaces(astrFieldValue) == "")
	{

		// alert(astrFieldName + " should be entered");  // This is line is commented by Manish : Date: 18-Feb
		alert("Please enter " + astrFieldName + "   ");

		return false;
	}
	else
	{
		return true;
	}
}
//***********************************************************************
//Function Name : stripSpaces
//Author		: TCS
//Date			: 18th Jan, 2006
//Input			: InString
//Output		: Returns trim value of InString
//Purpose		: trims  the InString
//***********************************************************************
function stripSpaces (InString)
{
		OutString="";
        for ( Count=0 ; Count < InString.length ; Count++ )
		{
            TempChar=InString.substring (Count, Count+1);
            if (TempChar != " ")
            {
                  OutString=OutString+TempChar;
            }

        }
        return (OutString);
}
//***********************************************************************
//Function Name : fnCheckMaxLength
//Author		: TCS
//Date			: 18th Jan, 2006
//Input			: Field value, Field name,Max Length for the Field
//Output		: Returns true if field length is lessthan or equal MAX Length else false
//Purpose		: Checks if field length is lessthan or equal MAX Length
//***********************************************************************

function fnCheckMaxLength(astrFieldValue,astrFieldName,fieldMaxLength)
{
	if (stripSpaces(astrFieldValue).length > fieldMaxLength)
	{
		alert(astrFieldName + " length should not be more than  " + fieldMaxLength);
		return false;
	}
	else
	{
		return true;
	}
}

//***********************************************************************
//Function Name : fnCheckMaxLength
//Author		: TCS
//Date			: 18th Jan, 2006
//Input			: Field value, Field name,Max Length for the Field
//Output		: Returns true if field length is lessthan or equal MAX Length else false
//Purpose		: Checks if field length is lessthan or equal MAX Length
//***********************************************************************

function fnCheckMaxLengthWithErrMsg(astrFieldValue,fieldMaxLength,errMsg)
{
	if (stripSpaces(astrFieldValue).length > fieldMaxLength)
	{
		alert(errMsg);
		return false;
	}
	else
	{
		return true;
	}
}


//***********************************************************************
//Function Name : fnCheckPhone
//Author		: TCS
//Date			:  18th Jan, 2006
//Input			: Field value, Field name
//Output		: Returns true if valid integer 
false
//Purpose		: Checks if the field is valid integer or not
//***********************************************************************

function fnCheckPhone(initstrFieldValue,
								initStrFieldName,
								codestrFieldValue,
								codeStrFieldName,
								numberstrFieldValue,
								numberStrFieldName
							 )
{

	//var RefString="1234567890";
	//var InitString="1234567890";
	var RefString="1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	var InitString="1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	var InString = "";
	var totLength = 0;
	var InternationalCodeLength = 0;
	var AreaCodeLength = 0;
	var NumberLength = 0;

	InString = stripSpaces(initstrFieldValue);

	InternationalCodeLength = InString.length;


	for (Count=0; Count < InString.length; Count++)  // this is for the Int code
	{
		if (InitString.indexOf (InString.substring (Count, Count+1))==-1)
		{ /// this block will be executed only when the char is not number
	 		   if(Count==0) {  // checking is first char is + sign
					 if( ! (InString.substring (Count, Count+1) == '+')) {					 
						alert( initStrFieldName + " should be alphanumeric.");
						return (false);
				 } 
			   } else {
				alert(initStrFieldName + " should be alphanumeric.");
				return (false);
			   }
		}
     } // end of for loop

    InString = "";

  	InString = stripSpaces(codestrFieldValue);
	AreaCodeLength = InString.length;


	for (Count=0; Count < InString.length; Count++)  // Validate the Area Code
	{
        if (RefString.indexOf (InString.substring (Count, Count+1))==-1)
		{
				alert(codeStrFieldName + " should be alphanumeric. ");
				return (false);
		}
     } // Area code validation ends here

    InString = "";

  	InString = stripSpaces(numberstrFieldValue);

	//var numberLength = InString.length;
	NumberLength = InString.length;

	for (Count=0; Count < InString.length; Count++)  // Validate the Phone Number.
	{
        if (RefString.indexOf (InString.substring (Count, Count+1))==-1)
		{
				alert(numberStrFieldName + " should be alphanumeric.");
				return (false);
		}
     }  /// Number Validation Ends




				 if(NumberLength<6 || NumberLength>12) { 
					  alert( numberStrFieldName +  " is invalid. ");
					  return (false);
				 } 
				 else 	if((AreaCodeLength<1)||(AreaCodeLength>5))
				{
					  alert( codeStrFieldName + " should be atleast 5 digits ");
					  return (false);
					}


     return true;
}

///////////////// Function for Mobile Number Validation is added by Manish 

function fnCheckMobileNumber(initstrFieldValue,
								initStrFieldName,
								numberstrFieldValue,
								numberStrFieldName
							 )
{

	var RefString="1234567890";
	var InitString="1234567890";
	var InString = "";
	var totLength = 0;
	var InternationalCodeLength = 0;
	var NumberLength = 0;


	InString = stripSpaces(initstrFieldValue);
	InternationalCodeLength = InString.length;

	for (Count=0; Count < InString.length; Count++)
	{
		if (InitString.indexOf (InString.substring (Count, Count+1))==-1)
		{ /// this block will be executed only when the char is not number
	 		   if(Count==0) {  // checking is first char is + sign
					 if( ! (InString.substring (Count, Count+1) == '+')) {					 
						alert( initStrFieldName + " should be numeric.");
						return (false);
				 } 
			   } else {
				alert(initStrFieldName + " should be numeric.");
				return (false);
			   }
		}
     } // end of for loop


    InString = "";

  	InString = stripSpaces(numberstrFieldValue);

	//var numberLength = InString.length;
	NumberLength = InString.length;

	for (Count=0; Count < InString.length; Count++)
	{
        if (RefString.indexOf (InString.substring (Count, Count+1))==-1)
		{
				alert(numberStrFieldName + " should be numeric.");
				return (false);
		}
     }  /// Number Validation Ends

			if(NumberLength<9  || NumberLength>12) { 
				alert( " Mobile number is invalid. ");
				return (false);
			}
     return true;
}



//***********************************************************************
//Function Name :fnCheckMail
//Author		: TCS
//Date			: 30th Jan, 2006
//Input			: Field value, Field name
//Output		: Returns true if valid email else false
//Purpose		: Checks if the field is valid email or not
//***********************************************************************

function fnCheckMail(astrEmail,astrFieldName)
{

	if( stripSpaces(astrEmail) != "" )

	{
	var lintCount;
	var lintAtrate;
	var lintDot;
	var lstrTemp;

	lintAtrate=0;
	lintDot = 0;
	var lstrRefString = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@._-';

	if (astrEmail.substring(0,1) == "." || astrEmail.substring(0,1) == "@"
	||  astrEmail.substring(0,1) == "_" || astrEmail.substring(0,1) == "-"
	|| astrEmail.substring(astrEmail.length-1,astrEmail.length) == "."
	|| astrEmail.substring(astrEmail.length-1,astrEmail.length) == "@"
	|| astrEmail.substring(astrEmail.length-1,astrEmail.length) == "-"
	|| astrEmail.substring(astrEmail.length-1,astrEmail.length) == "_")
	{
		alert("Please enter a valid " + astrFieldName + ": alphanumeric, '.','-','_','@'");
		return false;
	}

	for (lintCount=0; lintCount < astrEmail.length; lintCount++)
	{
		lstrTemp  = astrEmail.substring(lintCount, lintCount+1);
		if (lstrRefString.indexOf(lstrTemp) == -1)
		{
			alert("Please enter a valid " + astrFieldName + ": alphanumeric,'.','-','_','@'");
			return false;
		}
		if (lstrTemp == "@")
		{
			lintAtrate++;
			if (astrEmail.substring(lintCount-1,lintCount) == "." || astrEmail.substring(lintCount+1,lintCount+2) == ".")
			{
				alert("Please enter a valid " + astrFieldName + ": alphanumeric, '.','-','_','@'");
				return false;
			}
		}
		if (lstrTemp == ".")
		{
			lintDot = lintDot + 1;
			if (astrEmail.substring(lintCount+1,lintCount+2) == ".")
			{
				alert("Please enter a valid " + astrFieldName + ": alphanumeric, '.','-','_','@'");
				return false;
			}
		}
	}

	if (lintAtrate > 1 || lintDot == 0 || lintAtrate == 0)
	{
		alert("Please enter a valid " + astrFieldName + ": alphanumeric, '.','-','_','@'");
		return false;
	}

	}
	return true;
}

function disPlayDeprDate()
{
	var abc = "sss";
	var day = document.frmbookhotel.arrivaldate.value;
	var mth = document.frmbookhotel.arrivalmonth.value;
	var year = document.frmbookhotel.arrivalyear.value;
	var numNights = document.frmbookhotel.nightsdate.value;
	
	var month = 0;
	var deptDate = new Date();

	if(mth=="Jan" )
	{
		month = 0;
	}
	else if(mth=="Feb" )
	{
		month = 1;
	}
	else if(mth=="Mar" )
	{
		month = 2;
	}
		else if(mth=="Apr" )
	{
			month = 3;
	}
		else if(mth=="May" )
	{
			month = 4;
	}
		else if(mth=="Jun" )
	{
			month = 5;
	}
		else if(mth=="Jul" )
	{
			month = 6;
	}
		else if(mth=="Aug" )
	{
			month = 7;
	}
		else if(mth=="Sept" )
	{
			month = 8;
	}
		else if(mth=="Oct" )
	{
			month = 9;
	}
		else if(mth=="Nov" )
	{
			month = 10;
	}
	else if(mth=="Dec" )
	{
		month = 11;
	}

var	monthName =	new	Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec") // 
var total = 0 ;
total = parseInt(day) +parseInt( numNights );
deptDate.setFullYear(year,month,total)
dept.innerHTML = "Depart by Midday  " + deptDate.getDate() + " " + monthName [deptDate.getMonth()] + " " +  deptDate.getFullYear() ;

}


function getDateObject(year,mth,day)
{
	var month = 0;
	var retDate = new Date();

   if(mth=="Jan" )
	{
		month = 0;
	}
	else if(mth=="Feb" )
	{
		month = 1;
	}
	else if(mth=="Mar" )
	{
		month = 2;
	}
		else if(mth=="Apr" )
	{
			month = 3;
	}
		else if(mth=="May" )
	{
			month = 4;
	}
		else if(mth=="Jun" )
	{
			month = 5;
	}
		else if(mth=="Jul" )
	{
			month = 6;
	}
		else if(mth=="Aug" )
	{
			month = 7;
	}
		else if(mth=="Sept" )
	{
			month = 8;
	}
		else if(mth=="Oct" )
	{
			month = 9;
	}
		else if(mth=="Nov" )
	{
			month = 10;
	}
	else if(mth=="Dec" )
	{
		month = 11;
	}
    retDate.setFullYear(year,month,day)
		return retDate;

}


 function validateAdultsChildrens(noOfAdults, noOfChildrens,noOfRooms)

{

	alert("Hello" +noOfAdults + noOfChildrens + noOfRooms  );

	if ( parseInt(noOfAdults) > (2 * parseInt( noOfRooms )) )
	{
		alert("Maximun no Of Adults allowed for" +  noOfRooms + " Rooms is " +  (2 * parseInt(noOfRooms)) );
		
	}

		if (parseInt(noOfChildrens) > (4 *parseInt( noOfRooms)) )
	{
		alert("Maximun no Of Childsrens allowed for" +  noOfRooms + " Rooms is " +  (4 * parseInt( noOfRooms )) );
		
	}

}



function fnCheckAlphaNumeric(initstrFieldValue,initStrFieldName)
{
    var RefString="1234567890";
	var InitString="1234567890";
	var InitString2="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var InitString3="abcdefghijklmnopqrstuvwxyz";
	var InString = "";
	var totLength = 0;

	InString = stripSpaces(initstrFieldValue);

	totLength = InString.length;


	for (Count=0; Count < InString.length; Count++)
	{
        if ((InitString.indexOf (InString.substring (Count, Count+1))==-1)&&
        (InitString2.indexOf (InString.substring (Count, Count+1))==-1)&&
        (InitString3.indexOf (InString.substring (Count, Count+1))==-1))
		{
				alert("The "+initStrFieldName + "should be Alphanumeric only.");
				return (false);
		}
     }
	 return true;

}


function fnCheckNumeric(initstrFieldValue,initStrFieldName)
{
    var RefString="1234567890";
	var InitString="1234567890";
	var InString = "";
	var totLength = 0;

	InString = stripSpaces(initstrFieldValue);

	totLength = InString.length;


	for (Count=0; Count < InString.length; Count++)
	{
        if (InitString.indexOf (InString.substring (Count, Count+1))==-1)
		{
				alert("The "+initStrFieldName + "should be numeric only.");
				return (false);
		}
     }
	 return true;

}

function fnCheckMinLength(astrFieldValue,astrFieldName,fieldMaxLength)
{
	if (stripSpaces(astrFieldValue).length < fieldMaxLength)
	{
		alert(astrFieldName + " length should not be less than  " + fieldMaxLength);
		return false;
	}
	else
	{
		return true;
	}
}



function fnCheckNumericPin(initstrFieldValue,initStrFieldName)
{
    var RefString="1234567890";
	var InitString="1234567890";
	var InString = "";
	var totLength = 0;

	InString = initstrFieldValue;

	totLength = InString.length;


	for (Count=0; Count < InString.length; Count++)
	{
        if (InitString.indexOf (InString.substring (Count, Count+1))==-1)
		{
				alert(initStrFieldName + " should be numeric");
				return (false);
		}
     }
	 return true;

}


//***********************************************************************
//Function Name :fnCheckValidDate
//Author		: TCS
//Date			: 28th Feb, 2006
//Input			: Day,Month,Year
//Output		: Returns true if valid date else false
//Purpose		: Checks if the given Day,Month,Year form a valid Date
//***********************************************************************


function fnCheckValidDate(lstrDay,lstrMonth,lstrYear)
{
		var lintYear;						//Contains integer representation of year
						
		var lintDay;						//Contains integer representation of day

		//Converting the strings into integers.

	
		var lintMonth = -1;

		if(lstrMonth=="Jan" )
		{
			lintMonth = 1;
		}
		else if(lstrMonth=="Feb" )
		{
			lintMonth = 2;
		}
		else if(lstrMonth=="Mar" )
		{
			lintMonth = 3;
		}
			else if(lstrMonth=="Apr" )
		{
				lintMonth = 4;
		}
			else if(lstrMonth=="May" )
		{
				lintMonth = 5;
		}
			else if(lstrMonth=="Jun" )
		{
				lintMonth = 6;
		}
			else if(lstrMonth=="Jul" )
		{
				lintMonth = 7;
		}
			else if(lstrMonth=="Aug" )
		{
				lintMonth = 8;
		}
			else if(lstrMonth=="Sept" )
		{
				lintMonth = 9
		}
			else if(lstrMonth=="Oct" )
		{
				lintMonth = 10;
		}
			else if(lstrMonth=="Nov" )
		{
				lintMonth = 11;
		}
		else if(lstrMonth=="Dec" )
		{
			lintMonth = 12;
		}

	
	lintDay = parseInt(lstrDay,10);
	lintYear = parseInt(lstrYear,10);

	

	//Check for Day validity for months with 30 days only.
		if ((lintDay > 30) && ((lintMonth == 4) || (lintMonth == 6) || (lintMonth 
== 9) || (lintMonth == 11)))
		{
			
			return false;
		}
		//Is the year is a leap year?
		if ((lintYear % 400) == 0)
		{
			lblnLeapYear = true;
		}
		else if ((lintYear % 100) == 0)
			{
				lblnLeapYear = false;
			}
			else if ((lintYear % 4) == 0)
				{
					lblnLeapYear = true;
				}
			else
				{
					lblnLeapYear = false;
				}
		//Check for Day validity for February.
		if ((lintMonth == 2) && (((lblnLeapYear == false) && (lintDay > 28)) || 
((lblnLeapYear == true) && (lintDay > 29))))
		{
			
			return false;
		}

		return true;

}

/*******************************************************************/
	function cardval(s) 
	{
		// remove non-numerics
		var v = "0123456789";
		var w = "";
		for (i=0; i < s.length; i++) 
		{
			x = s.charAt(i);
			if (v.indexOf(x,0) != -1)
			w += x;
		}
		// validate number
		j = w.length / 2;
		if (j < 6.5 || j > 8 || j == 7) return false;
		k = Math.floor(j);
		m = Math.ceil(j) - k;
		c = 0;
		for (i=0; i<k; i++) 
		{
			a = w.charAt(i*2+m) * 2;
			c += a > 9 ? Math.floor(a/10 + a%10) : a;
		}
		for (i=0; i<k+m; i++) c += w.charAt(i*2+1-m) * 1;
		return (c%10 == 0);
	}
/*******************************************************************/




/*******************************************************************/

//***********************************************************************
//Function Name :replaceAll
//Author		: TCS
//Date			: 23th Aug, 2006
//Input			: String input String ,String specila Char
//Output		: Returns replaced String
//Purpose		: to replace specila char with blank space
//***********************************************************************



function replaceAll(inputString,findString,replaceString){

var intIndexOfMatch = inputString.indexOf( findString );
while (intIndexOfMatch != -1){
	inputString = inputString.replace( findString,replaceString );
	intIndexOfMatch = inputString.indexOf( findString );
}
return inputString;



}




//***********************************************************************
//Function Name :Show
//Author		: TCS
//Date			: 14 Feb , 2007
//Input			: 
//Output		: 
//Purpose		: To display sun navigation for News Room
//***********************************************************************

function show(){


  if ((document.getElementById("newTable").style.display == 'none'))
      {
	    document.getElementById("newTableAwards").style.display = 'none';
        document.getElementById("newTable").style.display = 'inline';
      } else {
        document.getElementById("newTable").style.display = 'none';
      }
  } 
  
  
  function article(){
  
  
    if ((document.getElementById("newTableA").style.display == 'none'))
        {
  	    document.getElementById("newTableArticle").style.display = 'none';
          document.getElementById("newTableA").style.display = 'inline';
        } else {
          document.getElementById("newTableA").style.display = 'none';
        }
    } 
    function showArticleSub(){
  
  
    if ((document.getElementById("newTableArticleSub").style.display == 'none'))
        {
  	    document.getElementById("newTableAS").style.display = 'none';
          document.getElementById("newTableArticleSub").style.display = 'inline';
        } else {
          document.getElementById("newTableArticleSub").style.display = 'none';
        }
    } 
  	function showJob(){
  
  
    if ((document.getElementById("newTable").style.display == 'none'))
        {
  
          document.getElementById("newTable").style.display = 'none';
        } else {
          document.getElementById("newTable").style.display = 'inline';
        }
    } 
  
     function showcioi(){
  
  
    if ((document.getElementById("newTablecioi").style.display == 'none'))
        {
  
          document.getElementById("newTablecioi").style.display = 'none';
        } else {
          document.getElementById("newTablecioi").style.display = 'inline';
        }
    } 

//***********************************************************************
//Function Name :Show
//Author		: TCS
//Date			: 14 Feb , 2007
//Input			: 
//Output		: 
//Purpose		: To display sun navigation for News Room
//***********************************************************************

function showAwards(){


  if ((document.getElementById("newTableAwards").style.display == 'none'))
      {
	    document.getElementById("newTable").style.display = 'none';
        document.getElementById("newTableAwards").style.display = 'inline';
      } else {
        document.getElementById("newTableAwards").style.display = 'none';
      }
  } 

  /*
  function fnCheckCCVLength(astrFieldValue,astrFieldName,fieldMaxLength)
{
	if (stripSpaces(astrFieldValue).length == fieldMaxLength){
		return true;
	}else{
		alert(astrFieldName + " should be of 3 or 4 digits");
		return false;
		}
}

  */
  