function chkCheckBox(formelement,text)
{
	var flag='false';
	
	if(formelement.checked==true){
		flag='true';
	}
	else{
		for (var i =0;i<formelement.length;i++ ){
			if(formelement[i].checked==true){
				flag='true';
			}
		}
	}
	if (flag=='false')
	{
		alert(' Please Select '+text);
		return false;
	}
	else
	{
		return true;
	}

}

function chkYear(foreelement,text)
{
	var alertStr="";
	theDate = new Date();
	var year = theDate.getFullYear();
	var selectyear =parseInt(foreelement.value);
	if(selectyear>=year)return true;
	else{
		alertStr= text + ' you have selected is not correct.\n';
		alertStr = alertStr + 'Please select a valid  ' + text + '.';
		alert(alertStr);
		return false;	
	}
}

function chkMonth(foreelement,foreelement1,text)
{
	theDate = new Date();
	var alertStr="";
	var month = theDate.getMonth();
	var selectmonth =parseInt(foreelement.value);
	var year = theDate.getFullYear();
	var selectyear =parseInt(foreelement1.value);
	if(selectyear>year){
		return true;
	}else{
		if(selectmonth>=(month+1)){
			return true;
		}else{
			alertStr= text + ' you have selected is not correct.\n';
			alertStr = alertStr + 'Please select a valid  ' + text + '.';
			alert(alertStr);
			return false;	
		}
	}	
}

function chkSelectBlank(formelement,text,element)
{	
	var alertStr="";
	if (formelement.options[formelement.selectedIndex].value=='selected'){
		alertStr= 'You have not selected ' + text +'.\n';
		alertStr = alertStr + 'Please select ' + element +'.';
		alert(alertStr);
		formelement.focus();
		return false;
	}
	else
	{
		return true;
	}
	return false;
}

function chkMultipleSelect(formelement, text , element){

	var alertStr="";
	if (formelement.selectedIndex==-1){

		alertStr= 'You have not selected ' + text +'.\n';
		alertStr = alertStr + 'Please select atleast one ' + element + '.';
		alert(alertStr);
		formelement.focus();
		return false;
	}else{
		
		return true;
	}
}

function chkBlank(formelement,text, elementtext)
{
	var eleVal = formelement.value;
	var len = eleVal.length;
	var alertStr="";
	while(eleVal.substring(0,1) == ' '){
		eleVal = eleVal.substring(1, len);
	}
	if (eleVal == '')
	{
		if(elementtext!=''){
			alertStr='You have not entered ' + elementtext + '.\n';
		}
		alertStr = alertStr + 'Please enter the ' + text + '.';
		alert(alertStr);
		formelement.value="";
		formelement.focus();
		return false;
	}else{
		return true;
	}
}

function chkPhoneNumber(formelement,text){
	
	var alertStr="";
	var checkOK = "0123456789-";
	var checkStr = formelement.value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++){
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++){
			if (ch == checkOK.charAt(j)){
				break;
			}
		}
		if (j == checkOK.length){
			allValid = false;
			break;
		}
	}
	if (!allValid){
		alertStr= text + ' you have provided is not correct.\n';
		alertStr = alertStr + 'Please ensure that the ' + text + ' does not contain any alphabets or special characters.';
		alert(alertStr);
		formelement.value="";
		formelement.focus();
		return false;	
	}else{
		return true;
	}
}

function chkAllZeroNumbers(formelement,text){
	
	var alertStr="";
	var checkStr = formelement.value;
	var mCount = 0;
	for (i = 0;  i < checkStr.length;  i++){
		ch = checkStr.charAt(i);
		if (ch == '0' || ch == '-'){
			mCount++;
		}
	}
	if (mCount == checkStr.length){
		alertStr= text + ' you have provided is not correct.\n';
		alertStr = alertStr + 'Please ensure that the ' + text + ' does not contain all zeros.';
		alert(alertStr);
		formelement.value="";
		formelement.focus();
		return false;	
	}else{
		return true;
	}
}

function chkNaN(formelement,text)
{
	var alertStr="";
	var checkOK = "0123456789";
	var checkStr = formelement.value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++){
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++){
			if (ch == checkOK.charAt(j)){
				break;
			}
		}
		if (j == checkOK.length){
			allValid = false;
			break;
		}
	}
	if (!allValid){
		alertStr= text + ' you have provided is not correct.\n';
		alertStr = alertStr + 'Please ensure that the ' + text + ' does not contain any alphabets or special characters.';
		alert(alertStr);
		formelement.value="";
		formelement.focus();
		return false;	
	}else{
		return true;
	}
}
//---- following function is used for checking value in first name, middle name and last name fields.
function chkName(formelement, text){
	var alertStr="";
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.' ";
	var checkStr = formelement.value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++){
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++){
			if (ch == checkOK.charAt(j)){
				break;
			}
		}
		if (j == checkOK.length){
			allValid = false;
			break;
		}
	}
	if (!allValid){
		alertStr= text + ' you have provided is not correct.\n';
		alertStr = alertStr + 'Please ensure that the ' + text + ' does not contain any numbers or special characters.';
		alert(alertStr);
		formelement.value="";
		formelement.focus();
		return false;	
	}else{
		return true;
	}
}
function chkAllowChar(formelement, text){
	var alertStr="";
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`~!@#$%^&()+-[]{}/|;:,<>.? ";
	var checkStr = formelement.value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++){
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++){
			if (ch == checkOK.charAt(j)){
				break;
			}
		}
		if (j == checkOK.length){
			allValid = false;
			break;
		}
	}
	if (!allValid){
		alertStr= text + ' you have provided is not correct.\n';
		alertStr = alertStr + 'Please ensure that the ' + text + ' does not contain any numbers.';
		alert(alertStr);
		formelement.value="";
		formelement.focus();
		return false;	
	}else{
		return true;
	}
}

function chkAlphaNumeric(formelement, text){
	var alertStr="";
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	var checkStr = formelement.value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++){
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++){
			if (ch == checkOK.charAt(j)){
				break;
			}
		}
		if (j == checkOK.length){
			allValid = false;
			break;
		}
	}
	if (!allValid){
		alertStr= text + ' you have provided is not correct.\n';
		alertStr = alertStr + 'Please ensure that the ' + text + ' does not contain any special characters.';
		alert(alertStr);
		formelement.value="";
		formelement.focus();
		return false;	
	}else{
		return true;
	}
}

function chkAlpha(formelement, text){
	var pattern = "[^a-zA-Z]+$";			
	var checkAlpha = new RegExp(pattern);
	var alertStr="";
	if(checkAlpha.test(formelement.value)){
		
		alertStr= text + ' you have provided is not correct.\n';
		alertStr = alertStr + 'Please ensure that the ' + text + ' does not contain any numbers or special characters.';
		alert(alertStr);
		formelement.value="";
		formelement.focus();
		return false;
	}else{	
		return true;
	}
}

function echeck(str, text) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=(str.length-1);
		var ldot=str.indexOf(dot);
		var alertStr = "";
		var plusmin = "�";
		alertStr= text + ' Address you have provided is not correct.\n';
		alertStr = alertStr + 'Please ensure that the '+ text +' Address is in proper format like myname@myaddress.com.';
		
		
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.lastIndexOf(at)==lstr){
			alert(alertStr);
			return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.lastIndexOf(dot)==lstr){
			alert(alertStr);
			return false;
		}

		if (str.indexOf("_")==0 || str.lastIndexOf("_")==lstr){
			alert(alertStr);
			return false;
		}

		if (str.indexOf("-")==0 || str.lastIndexOf("-")==lstr){
			alert(alertStr);
			return false;
		}

		if (str.indexOf(at,(lat+1))!=-1){
			alert(alertStr);
			return false;
		}
		
		if (str.substring(lat,(lat+1))==dot || str.substring((lat+1),(lat+2))==dot){
			alert(alertStr);
			return false;
		}

		if (str.indexOf(dot,(lat+2))==-1){
			alert(alertStr);
			return false;
		}

		if (str.indexOf(" ")!=-1){
			alert(alertStr);
			return false;
		}

		if (!(str.indexOf(plusmin)==-1)){
			alert(alertStr);
			return false;
		}

		if (!(str.indexOf(":")==-1)){
			alert(alertStr);
			return false;
		}

		if (!(str.indexOf(",")==-1)){
			alert(alertStr);
			return false;
		}
		for (var i=0; i<(str.length-1); i++){
			ch = str.charAt(i);
			ch1 = str.charAt(i+1);
			if (ch==ch1 && ch=='.'){
				alert(alertStr);
				return false;
			}
		}
		return true;					
	}

function checkEmail(formelement, text){
	var emailID = formelement;
	if(!chkSpecialCharMail(formelement, '`~!#$%^&()[]{}|;,+<>*', text)){
		return false;
	}
	if (echeck(emailID.value, text)==false){
		emailID.value="";
		emailID.focus();
		return false;
	}
	return true;
 }

function chkSpecialCharMail(formelement, mChar, text){
	var alertStr="";
	var msg='true';
	var a=formelement.value;
	var b=a.length;
	var ch=mChar.length;
	var i,j;
	for(i=0;i<ch;i++){
		var ch1=mChar.substring(i,i+1);
		for(j=0;j<b;j++){
			var a1=a.substring(j,j+1);
			if(a1==ch1){
				alertStr= text + ' Address you have provided is not correct.\n';
				alertStr = alertStr + 'Please ensure that the ' + text + ' Address is in proper format like myname@myaddress.com.';
				alert(alertStr);
				formelement.value="";
				formelement.focus();
				msg='false';
				return false;
			}
		}
	}
	if (msg=='true'){
		return true;
	}

}

/* This function checks for the minimum characters. */

function chkLessLen(formelement,text,len)
{
	var alertStr = "";
	if(formelement.value.length<parseInt(len))
	{
		alertStr= text + ' contains less characters.\n';
		alertStr = alertStr + 'Please ensure that the ' + text + ' does not contain less than ' + len + ' characters.';
		alert(alertStr);
		formelement.value="";
		formelement.focus();
		return false;
	}
	else
	{
		return true;
	}
}

/* This function checks for the maximum characters. */

function chkGreaterLen(formelement,text,len)
{
	var alertStr = "";
	if(formelement.value.length>parseInt(len))
	{
		alertStr= text + ' contains extra characters.\n';
		alertStr = alertStr + 'Please ensure that the ' + text + ' does not exceed ' + len + ' characters.';
		alert(alertStr);
		formelement.value="";
		formelement.focus();
		return false;
	}
	else{
		return true;
	}
}

/* This function checks for special characters. */

function chkSpecialChar(formelement,text)
{
	var msg='true';
	var a=formelement.value;
	var b=a.length;
	var cha='`~!@#$%^&()+-[]{}/|;:,<>.?';
	var ch=cha.length;
	var i,j;
	for(i=0;i<ch;i++)
	{
		var ch1=cha.substring(i,i+1);
		for(j=0;j<b;j++)
		{
			var a1=a.substring(j,j+1);
			if(a1==ch1)
			{
				msg= text + ' you have provided is not correct.\n';
				msg = msg + 'Please ensure that the ' + text + ' does not contain any special characters.';
				alert(msg);
				formelement.value="";
				formelement.focus();
				return false;
			}
		}
	}
	if (msg=='true')
	{
	return true;
	}
}

function chkSpecialCharForZip(formelement,text)
{
	var msg='true';
	var a=formelement.value;
	var b=a.length;
	var cha='`~!@#$%^&()+[]{}/|;:,<>.?_';
	var ch=cha.length;
	var i,j;
	for(i=0;i<ch;i++)
	{
		var ch1=cha.substring(i,i+1);
		for(j=0;j<b;j++)
		{
			var a1=a.substring(j,j+1);
			if(a1==ch1)
			{
				msg= text + ' you have provided is not correct.\n';
				msg = msg + 'Please ensure that the ' + text + ' does not contain any special characters.';
				alert(msg);
				formelement.value="";
				formelement.focus();
				return false;
			}
		}
	}
	if (msg=='true')
	{
	return true;
	}
}

function chkSpace(formelement,text)
{
	var msg='true';
	var a=formelement.value;
	var b=a.length;
	var i,j;
		for(j=0;j<b;j++)
		{
			var a1=a.substring(j,j+1);
			if(a1==' ')
			{
				msg= text + ' you have provided is not correct.\n';
				msg = msg + 'Please ensure that the ' + text + ' does not contain any spaces.';
				alert(msg);
				formelement.value="";
				formelement.focus();
				return false;
			}
		}

	if (msg=='true')
	{
	return true;
	}
}

/* This function compels the user to enter number greater than 0. */

function chkLEZero(formelement,text)
{
	if (formelement.value <= 0)
	{
		alert('Enter the '+text+' greater than 0.');
		formelement.focus();
		return false;
	}
	else
	{
		return true;
	}
}

/* This function checks for identical username & passwords. */

function chkUserFirstLetter(formelement,text){
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	var checkStr = formelement.value;
	var allValid = 'false';
	var alertStr="";
	var ch = checkStr.charAt(0);
	for (j=0; j<checkOK.length; j++){
		if (ch == (checkOK.charAt(j))){
			allValid = 'true';
			break;
		}
	}
		
	if (allValid == 'false'){
		alertStr= text + ' you have provided is not correct.\n';
		alertStr = alertStr + 'Please ensure that the ' + text + '  starts with an alphabet.';
		alert(alertStr);
		formelement.value="";
		formelement.focus();
		return false;	
	}else{
		return true;
	}
}

/* This function checks for identical passwords. */

function chkPassword(formelement1,formelement2, text)
{
	var password1=formelement1.value;
	var password2=formelement2.value;
	var alertStr = "";
	if (password1 != password2)
	{
		alertStr= text + ' does not match with Password text.\n';
		alertStr = alertStr + 'Please ensure that the ' + text + ' matches with Password text.';
		alert(alertStr);
		if(formelement1.type != "hidden"){
			formelement2.focus();
			formelement2.value="";
		}		
		return false;
	}
	else
	{
		return true;
	}
}

function comparePassword(frm, element)
{
	var alertStr="";
	var len = frm.elements.length;
	for(var i=0;i < len;i++)
	{
		if(frm.elements[i].type == "text")
		{
			if(element.value == frm.elements[i].value){
				alertStr= 'Password you have provided is not correct.\n';
				alertStr = alertStr + 'Please ensure that the Password does not match with any of the textboxes.';
				alert(alertStr);
				element.focus();
				element.value="";
				return false;
			
			}
		}
	}
	return true;
}

function chkRadio(formelement, text, element){

	var alertStr = "";
	var flag='false';
	if(formelement.checked==true){
		flag='true';
	}
	else{
		for (var i =0;i<formelement.length;i++ ){
			if(formelement[i].checked==true){
				flag='true';
			}
		}
	}
	if (flag=='false'){

		alertStr= 'You have not selected ' + text + '.\n';
		alertStr = alertStr + 'Please select the ' + element + '.';
		alert(alertStr);
		return false;
	}
	else
	{
		return true;
	}

}

/* This function is used to trim the leading and trailing spaces from given string.
   Useful to remove unwanted spaces before processing string value in JavaScript. */

function trim (str)
{
    var k=0;
    var i=0;
    var j=0;
    k   =   str.length;
    while ( str.charAt (j) == ' ' )
       j++;

    i   =   k;
    while ( str.charAt (i-1) == ' ' )
        i   =   i-1;
    if ( j != k )
        trimstr = str.substring(j,i);
    else
        trimstr = '';
    return trimstr;
}

/* This function is used to check if the given string containes single quote chracter*/

function hasQuotes(str)
{
    var ch="'";
    if(str.indexOf(ch)==-1)
    return false;
    return true;
}

/* This function is used to open a new pop-up window. */
function OpenWin (link, windowName)
{
    loc =   link;
    win =   window.open (loc,windowName,'top=150,left=75,height=300,width=600,scrollbars=yes,status=no,toolbar=no,resizable=yes') ;
    win.focus();

}

/* Used for rounding off value. Deprecated. Insted use function round_decimals given below. */
function roundOff(value, precision)
{
        value = "" + value //convert value to string
        precision = parseInt(precision);

        var whole = "" + Math.round(value * Math.pow(10, precision));

        var decPoint = whole.length - precision;

        if(decPoint != 0)
        {
                result = whole.substring(0, decPoint);
                result += ".";
                result += whole.substring(decPoint, whole.length);
        }
        else
        {
                result = whole;
        }
        return result;
}

/* Used for rounding off decimal values to the correct decimal precision. */

function round_decimals(original_number, decimals)
{
 var result1 = original_number * Math.pow(10, decimals)
 var result2 = Math.round(result1)
 var result3 = result2 / Math.pow(10, decimals)
 return pad_with_zeros(result3, decimals)
}

/* Internally used by round_decimals function for padding amount with zeros while rounding off. */

function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()

    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {

        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0

        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }

    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length

    if (pad_total > 0) {

        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++)
            value_string += "0"
        }
   // alert("deci :"+value_string);
    return value_string
}

	//use this function to disable form element
function disable(elem) { // elem: form element to be disabled
  elem.onfocus=elem.blur;
}
	//use this function to enable form element
function enable(elem) { // elem: form element to be reenabled
  elem.onfocus=null;
}

/*function to get the date after the given period
  currentYear - String giving current year in yyyy format
  currentMonth - String giving current month in mm format
  currentDay - String giving current day in dd format
  addDays - Integer showing no of days after the current date
  return next date as mm/dd/yyyy string
*/
function getNextDate(currentYear, currentMonth, currentDay, addDays) {
	var nextDate = '';
	
	var currDateObj = new Date(parseInt(currentYear),
				parseInt(currentMonth),
				parseInt(currentDay));
		
	currDateObj.setDate(parseInt(currentDay)+addDays);
	nextDate = currDateObj.getMonth()+'/'+currDateObj.getDate()+'/'+currDateObj.getYear();
	return nextDate;
}

function chkDate(formelement, text, delim){
	var monthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	var ddVal = formelement.value;	
	if(ddVal.indexOf(delim) < 1){		
		badDateAlert(formelement);
		return false;
	}
	var dateArray = ddVal.split(delim);
	if(dateArray.length != 3){
		badDateAlert(formelement);
		return false;
	}
	if(dateArray[2].length != 4){
		badDateAlert(formelement);
		return false;
	}
	if(parseInt(dateArray[1]) > 12){
		badDateAlert(formelement);
		return false;
	}
	
	if((parseInt(dateArray[1]) == 2) && (parseInt(dateArray[2])%4 == 0)){
		if((parseInt(dateArray[0])) > (monthDays[parseInt(dateArray[1]-1)])+1){
			badDateAlert(formelement);
			return false;
		}
	}else if((parseInt(dateArray[0])) > (monthDays[parseInt(dateArray[1]-1)])){
		badDateAlert(formelement);
		return false;
	}
	return true;
}

function badDateAlert(ele){
	alert("Invalid Date");
	ele.value = "";
	if(ele.type != "hidden"){
		ele.focus();
	}		
}

function sqlDate(srcEle, destEle, delim){
	if(!chkDate(srcEle, 'Date', delim)) return false;	
	var temp = (srcEle.value).split(delim);	
	destEle.value = temp[2] +"/"+ temp[1] +"/"+ temp[0];
	return true;
}

function goToError(err){
	document.err_frm.actionPage.value="/errorPages/error.jsp?err="+err;
	document.err_frm.submit();
}

function help(anc){
	if(anc == 5)
	{
		OpenWin("/helpfiles/bedTypeHelpfile.jsp", "ResAvenue_Help");
	}
	else
	{
		OpenWin("/helpfiles/helpfile.jsp#"+anc, "ResAvenue_Help");
	}
}

//---- Added by Ankit. The above function is called for setup wizard redirection. 02-Aug-04----
function continueConfiguration(fname, target, action){
	obj = eval("document."+fname);
	obj.actionPage.value = target;
	if(action == "alloc_new"){
		if(obj.action.value != "set"){
			alert("Please allocate room before proceeding to Rate Mater.");
			return false;
		}
	}
	if(action == "rate_add"){
		if(obj.action.value != "set"){
			alert("Please add Rate Code before proceeding.");
			return false;
		}
	}
	if(action == "rates"){
		if(obj.action.value != "rates"){
			alert("Please configure Rates before proceeding.");
			return false;
		}
	}
//	return false;
	obj.submit();
}

//---- Added by Ankit. The above function is used only in includes/adm_brief_help.jsp. 17-Sep-04----
function goToPage(mPage){
	document.incfrm.actionPage.value=mPage;
	document.incfrm.submit();
}


/*
	Function to call pop-up for displaying Secure Certificate.
	Called from req_booking_nights, getAvailability, setRooms
*/
function popUpVsign(url){
	var url = 'https://digitalid.verisign.com/as2/46c9d61e98b639b5252af54f0575b41b';
	window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
}


function chkSpecialCharUrl(formelement, mChar, text)
{
	var alertStr="";
	var msg='true';
	var a=formelement.value;
	var b=a.length;
	var ch=mChar.length;
	var i,j;
	for(i=0;i<ch;i++){
		var ch1=mChar.substring(i,i+1);
		for(j=0;j<b;j++){
			var a1=a.substring(j,j+1);
			if(a1==ch1){
				alertStr= text + ' you have provided is not correct.\n';
				alertStr = alertStr + 'Please ensure that the ' + text + ' you have provided is in proper format like www.abc.com.';
				alert(alertStr);
				formelement.value="";
				formelement.focus();
				msg='false';
				return false;
			}
		}
	}
	if (msg=='true'){
		return true;
	}

}

function chkurl(element, text){
	var dotcount=0,charEle='',naString='';
	var alertStr="";
	var mSlashIndex = (element.value).indexOf("/");
	if(!chkSpecialCharUrl(element, '`~!#$%^&()[]{}|;,+<>@*\\', text)){
		return false;
	}
	charEle = element.value.substring(0, 7);
	if (charEle == 'http://'){
		alertStr = 'The ' + text + ' you have provided is not correct.\n';
		alertStr = alertStr + 'Please ensure that the ' + text + ' you have provided is in proper format like www.abc.com.';
		alert(alertStr);
		element.value="";
		element.focus();
		return false;
	}
	charEle = '';
	if (mSlashIndex>=0 && mSlashIndex < 7){
		alertStr = 'The ' + text + ' you have provided is not correct.\n';
		alertStr = alertStr + 'Please ensure that the ' + text + ' you have provided is in proper format like www.abc.com.';
		alert(alertStr);
		element.value="";
		element.focus();
		return false;
	}
	for(var x=0; x<element.value.length; x++){
		charEle = element.value.substring(x, x+1);
		if(charEle == '.'){
			dotcount++;
		}
	}
	if (dotcount < 2){
		alertStr = 'The ' + text + ' you have provided is not correct.\n';
		alertStr = alertStr + 'Please ensure that the ' + text + ' you have provided is in proper format like www.abc.com.';
		alert(alertStr);
		element.value="";
		element.focus();
		return false;
	}
	for(var i=0;i<(element.value.length-2);i++){
		naString=element.value.substring(i,i+1);
		var naString2=element.value.substring(i+1,i+2);
		if(naString==' ' || (naString =="." && naString2== ".")){
			alertStr= 'The ' + text + ' you have provided is not correct.\n';
			alertStr = alertStr + 'Please ensure that the ' + text + ' you have provided is in proper format such as www.abc.com';
			alert(alertStr);
			element.value="";
			element.focus();
			return false;
		}
	}
	return true;	
}

function ChkStartEnd(element, text, allowSpChar){
	var mCheck = '';
	var mCount = 0;
	var mStr = element.value
	var mLength = parseInt((mStr).length);
	var mStart = mStr.substring(0,1);
	var mEnd = mStr.charAt(parseInt(mLength - 1));
	for (i=0; i<allowSpChar.length; i++){
		mCheck = allowSpChar.substring(i,i+1);
		if (mStart == mCheck || mEnd == mCheck){
			mCount++;
		}
	}
	if (mCount > 0){
		alertStr= 'The ' + text + ' you have provided is not correct.\n';
		alertStr = alertStr + 'Please ensure that the ' + text + ' does not start or end with special character.';
		alert(alertStr);
		element.value="";
		element.focus();
		return false;
	}
	return true;
}

function chkSecurePassword(element, text){
	var alertStr="";
	var msg='true';
	var a=element.value;
	var b=a.length;
	var mChar = '`~!@#$%^&()+-[]{}/|;:,<>.?_';
	var mString = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	var mNum = '0123456789';
	var mNLength=mNum.length;
	var ch=mChar.length;
	var sl=mString.length;
	var a1= '';
	var a2= '';
	var ch1 = '';
	var ch2 = '';
	var mCount = 0;
	var mNCount = 0;
	var mCCount = 0;
	var i,j;
	
	/*for(i=0;i<ch;i++){
		ch1=mChar.substring(i,i+1);
		for(j=0;j<b;j++){
			a1=a.substring(j,j+1);
			if(a1==ch1){
				mCount++;	
			}
		}
	}*/
	mCount++;
	for(i=0;i<mNLength;i++){
		ch1=mNum.substring(i,i+1);
		for(j=0;j<b;j++){
			a1=a.substring(j,j+1);
			if(a1==ch1){
				mNCount++;	
			}
		}
	}

	for(i=0;i<sl;i++){
		ch2=mString.substring(i,i+1);
		for(j=0;j<b;j++){
			a2=a.substring(j,j+1);
			if(a2==ch2){
				mCCount++;	
			}
		}
	}

	if (mCount==0 || mNCount==0 || mCCount==0){
		msg ='false';
	}
	if (msg=='true'){
		return true;
	}else{
		alertStr= text + ' you have provided is not correct.\n';
		alertStr = alertStr + 'Please ensure that the ' + text + ' contains atleast one Character and one Number.';
		alert(alertStr);
		element.value="";
		element.focus();
		return false;
	}
}

function chkCardByLuhnAlgo(cardNumber,CardType, cardTypeDesc) {     
		
	var CCNum =cardNumber; //Card Number
	var CCNum =CCNum.replace(/ /g, "");
	var dashindex=CardType.indexOf("-");
	var CCType=CardType.substring(dashindex+1,CardType.length);//Card Type
	
	var msg = 'Card Number does not match with Card Type.\nPlease enter proper Card Number that matches with the card type you have selected.';
	// var finalmsg='Length of Card Number you have provided is not correct.\nPlease ensure that the Card Number you enter is same as it appears on your credit card.';
	var finalmsg='Invalid Card Number.';

	//Checking Card Type 
	if(CCType=='')
	{
		alert('Card Type is not selected.\nPlease select one of the credit cards from the Card Type dropdown.');
		return false;
	}

	//Check for Card Number entered.
	if(CCNum=='' || CCNum==0)
	{
		  alert('Card Number you have provided is not correct.\nPlease ensure that the Card Number you enter is same as it appears on your credit card.');
		  return false;
	} 
	if(CCNum !='')
	{  
		for( var i = 0; i <CCNum.length; ++i ) 
			{
				var c = CCNum.charAt(i);
				if( c < '0' || c > '9' ) 
				{
					alert('Card Number you have provided is not correct.\nPlease ensure that the Card Number does not contain any alphabets, spaces or special characters.');
					return false;
				} 
			}  
	 }

	if(cardTypeDesc == 'CREDITCARD') {
		//Checking for valid card types supported by this script
		//Discover Novus(DSNV) has not been validated but ignored by script for now
		if(CCType !='VISA' && CCType !='MSTR' 
			&& CCType !='AMEX' && CCType !='JPCB'
			&& CCType!='ECRD' && CCType !='DCLB'
			&& CCType !='DSNV' && CCType !='CTBL'  && CCType !='CVMS') {
			alert('Card Type selected is not supported.\nPlease contact the System Administrator to report this error.')
			return false;
		}
		//Check Visa 
		if(CCType.indexOf('VISA') !=-1)
		{
			if ((CCNum.length !=13 && CCNum.length != 16) && (CCNum.substring(0,1) == 4))
				{
					alert('Length of Card Number you have provided is not correct.\nPlease ensure that the Card Number you enter is same as it appears on your credit card.');
					return false;
				}
			if ((CCNum.length == 13 || CCNum.length == 16) && (CCNum.substring(0,1) == 4))
			{
				if(!cardval(cardNumber))
				{
			 
						alert(finalmsg);  
						return false; 
				}
			 }
	
			else
			{ 
				alert(msg);  
				return false;
			}
		}
		//Check Mastercard  and Citibank ECard
		if((CCType.indexOf('MSTR') !=-1) || (CCType.indexOf('ECRD') !=-1) || (CCType.indexOf('CVMS') !=-1))
		{
			var firstdig=CCNum.substring(0,1);
			var seconddig=CCNum.substring(1,2);
			if ((CCNum.length !=16 && CCNum.length != 19) && (firstdig == 5) && ((seconddig >= 1) && (seconddig <= 5))) 
			{ 
				alert('Length of Card Number you have provided is not correct.\nPlease ensure that the Card Number you enter is same as it appears on your credit card.');
				return false;
			}
	
			if ((CCNum.length == 16 || CCNum.length == 19) && (firstdig == 5) && ((seconddig >= 1) && (seconddig <= 5)))
			{
				if(!cardval(cardNumber))
				{
					alert(finalmsg);  
					return false; 
				}
				
				}
		
				else
				{
					alert(msg);  
					return false;
				}

		}

		//Check American Express 
		if(CCType.indexOf('AMEX') !=-1)
		{
			firstdig = CCNum.substring(0,1);
			seconddig = CCNum.substring(1,2);
			if ((CCNum.length !=15) && (firstdig == 3) && ((seconddig == 4)||(seconddig == 7)))
			{ 
				alert('Length of Card Number you have provided is not correct.\nPlease ensure that the Card Number you enter is same as it appears on your credit card.');
				return false;
			}
			if (((CCNum.length == 15)  || (CCNum.length == 18)) && (firstdig == 3) && ((seconddig == 4) ||(seconddig == 7)))
			{
				if(!cardval(cardNumber))
				{  
					alert(finalmsg);  
					return false; 
				}
			}
			else
			{
				alert(msg);  
				return false;
			}
		}		

		//Check JCB  card 
		if(CCType.indexOf('JPCB') !=-1)
		{
			if ((CCNum.length != 16) && (CCNum.match(/^(3088|3096|3112|3158|3337|3528|3566|3530|3540|3541)/)))
			{
				alert('Length of Card Number you have provided is not correct.\nPlease ensure that the Card Number you enter is same as it appears on your credit card.');
				return false;
			}
			if ((CCNum.length==16) && (CCNum.match(/^(3088|3096|3112|3158|3337|3528|3566|3530|3540|3541)/))) 
			{
				if(!cardval(cardNumber))
				{  
					alert(finalmsg);  
					return false; 
				}
			}
			else
			{
				alert(msg);  
				return false;
			}
		}

		
		//Check Diners

		if(CCType.indexOf('DCLB') !=-1)
		{   
			firstdig = CCNum.substring(0,1);
			seconddig = CCNum.substring(1,2);
			if ((CCNum.length !=14 && CCNum.length != 17) && (firstdig == 3) && ((seconddig == 0) || (seconddig == 6) || (seconddig == 8)))
			{
				alert('Length of Card Number you have provided is not correct.\nPlease ensure that the Card Number you enter is same as it appears on your credit card.');
				return false;
			}

			if((CCNum.length == 14 || CCNum.length == 17)  && (firstdig == 3) && ((seconddig == 0) || (seconddig == 6) || (seconddig == 8)))
			{
				if(!cardval(cardNumber))
				{
					alert(finalmsg);  
					return false; 
				}
			}
			else
			{
				alert(msg);  
				return false;
			}
		}

		//Check CarteBlanche
		if(CCType.indexOf('CTBL') !=-1)
		{
			firstdig = CCNum.substring(0,1);
			seconddig = CCNum.substring(1,2);
			if ((CCNum.length !=14) && (firstdig == 3) && ((seconddig == 0)||(seconddig == 6)||(seconddig == 8)))
			{ 
				alert('Length of Card Number you have provided is not correct.\nPlease ensure that the Card Number you enter is same as it appears on your credit card.');
				return false;
			}
			if (((CCNum.length == 14)) && (firstdig == 3) && ((seconddig == 0)||(seconddig == 6)||(seconddig == 8)))
			{
				if(!cardval(cardNumber))
				{  
					alert(finalmsg);  
					return false; 
				}
			}
			else
			{
				alert(msg);  
				return false;
			}
		}

		//Check Discover
		if(CCType.indexOf('DSNV') !=-1)
		{
			firstdig = CCNum.substring(0,1);
			seconddig = CCNum.substring(1,2);
			if ((CCNum.length !=16) && (firstdig == 6) && ((seconddig == 0)||(seconddig == 5)))
			{ 
				alert('Length of Card Number you have provided is not correct.\nPlease ensure that the Card Number you enter is same as it appears on your credit card.');
				return false;
			}
			if (((CCNum.length == 16)) && (firstdig == 6) && ((seconddig == 0)||(seconddig == 5)))
			{
				if(!cardval(cardNumber))
				{  
					alert(finalmsg);  
					return false; 
				}
			}
			else
			{
				alert(msg);  
				return false;
			}
		}	
	} else if(cardTypeDesc == 'DEBITCARD') {
		if(CCType !='VISA' && CCType !='AXISDB'
			&& CCType !='CORPDB' && CCType !='DEUTDB'
			&& CCType !='HDFCDB' && CCType !='INGVDB'
			&& CCType !='IOSDB' && CCType !='KRVDB' && CCType != 'OTHRDB') {
			alert('Card Type selected is not supported.\nPlease contact the System Administrator to report this error.')
			return false;
		}
		//Check for Detbit cards added by Bipin 1/19/2009
		/* commented by bipin on 2/3/2009 because this code only supports validation for VISA type,
		   and debit card can be of VISA, Master or Mestero type. 
			if( CCType == 'AXISDB' || CCType == 'CORPDB'
				|| CCType =='DEUTDB' || CCType == 'HDFCDB'
				|| CCType == 'VISA' || CCType == 'INGVDB'
				|| CCType == 'IOSDB' || CCType == 'KRVDB') {
				
				firstdig = CCNum.substring(0,1);
				if (CCNum.length != 16  && firstdig == 4)	{ 
					alert('Length of Card Number you have provided is not correct.\nPlease ensure that the Card Number you enter is same as it appears on your credit card.');
					return false;
				}
				if (CCNum.length == 16 && firstdig == 4 ) {
					if(!cardval(cardNumber)) {				 
						alert(finalmsg);  
						return false; 
					}
				 } else { 
					alert(msg);  
					return false;
				}
			}
		*/
		firstdig = CCNum.substring(0,1);
	//	alert(" firstdig  : " + firstdig + "  CCNum.length : " + CCNum.length);
		if(firstdig == 4 && CCNum.length == 16) {
			if(!cardval(cardNumber)) {				 
				alert(finalmsg);  
				return false; 
			}
		} else if (firstdig == 5 && CCNum.length >= 12 && CCNum.length <= 19) {
			if(!cardval(cardNumber)) {				 
				alert(finalmsg);  
				return false; 
			}
		} else {
			alert(msg);  
			return false;
		}
	}
	return true;
}//method is closed.

function cardval(cardNum){
	var s=cardNum;
	var v = "0123456789";
	var w = "";
	if(s !="")
	{ 
	   for (i=0; i < s.length; i++) 
		{
			x = s.charAt(i);
			if (v.indexOf(x,0) != -1)
			w += x;
		}
		j = w.length / 2;
		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);  //returns true here.
	}
}// method is closed

function checkValidURL(field){
	var httpregex=/^([a-zA-Z]+:\/\/)/
	var urlregex=/^[A-Za-z0-9][A-Za-z0-9._\-\/]*$/;
	var match=field.match(httpregex); // has a protocol indicator
	if(!(field.indexOf("///") == -1)){
		return false;
	}
	if(field.indexOf("_") != -1){
		var aa = field.split("_");
		for(i = 0; i < aa.length ; i++){
			if(aa[i] == ""){
				return false;
			}
		}
	}
	if(field.indexOf("-") != -1){
		var aa1 = field.split("-");
		for(i = 0; i < aa1.length ; i++){
			if(aa1[i] == ""){
				return false;
			}
		}
	}
	if(field.indexOf(":") != -1){
		var ss=field.split(":");
		if(!(ss[0] == "http" || ss[0] == "HTTP")){
			return false;
		}
		var pp=ss[1].split(".");
		if(pp.length == 3 || pp.length == 4 ){
			for(i = 0; i < pp.length ; i++){
				if(pp[i] == ""){
					return false;
				}
			}
			if(!(pp[0] = "//www" || pp[0] == "//WWW")){
				return false;
			}else if(pp[1] == "www" || pp[1] == "WWW" || pp[2] =="www" || pp[2] == "WWW"){
				return false;
			}
		}else{
			return false;
		}
	}else{
		var pp=field.split(".");
		if(pp.length == 3 || pp.length == 4 ){
			for(i = 0; i < pp.length ; i++){
				if(pp[i] == ""){
					return false;
				}
			}

			if(!(pp[0] = "www" || pp[0] == "WWW")){
				return false;
			}else if(pp[1] == "www" || pp[1] == "WWW" || pp[2] =="www" || pp[2] == "WWW"){
				return false;
			}
		}else{
			return false;
		}
	}

	if (match){
		match=field.substr(match[1].length,field.length)
		//match=match.match(urlregex);
	}else{
		var match=field.match(urlregex);
	}
	if(!match){
		return false;
	}else{
		return true;
	}
}
