function trim(inputString) 
{
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") 
   { 
	  retValue = retValue.substring(1, retValue.length);
	  ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") 
   { 
	  retValue = retValue.substring(0, retValue.length-1);
	  ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) 
   {
	  retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); 
   }
   return retValue; 
}

function isEmail(strEMail) //validations for email
{
	var strInvalidChars,blnTemp,i,strTemp,intdot,IsMail,strEMailRev,intAtTheRate;
	intdot = strEMail.lastIndexOf(".");
	if (intdot == -1 )
		return false;
	
	intdot=strEMail.length-intdot-1;
	if (intdot < 2 )
		return false;
	
	// Disallowed characters
	strInvalidChars = "!#$%^&*()=+{}[]|\;:'/?>,< ";

	intAtTheRate = strEMail.indexOf("@") ;

	// Check that there is at least one '@' and a character before @
	if (intAtTheRate < 1)
		blnTemp=true;
	else
		blnTemp=false;

	if (blnTemp)
		return !blnTemp;
	
	// Check that there is at least one '.' in the form a@a.com
	blnTemp = (strEMail.indexOf(".") < 3);
   if (blnTemp)
		return !blnTemp;

	//   Check that there is at least one char between '.' and @ after @
	intdot= strEMail.indexOf(intAtTheRate+1,".");
	blnTemp = (intdot==2);
	 if (blnTemp)
		return !blnTemp;

	//   Check that there is at least one char between '.' and @ before @
	blnTemp = (strEMail.substring(intAtTheRate - 1, intAtTheRate) == ".");
	if (blnTemp)
		return !blnTemp;

	//  and that the length is at least six (a@a.co)
	blnTemp = (strEMail.length < 6);
   if (blnTemp) 
		return !blnTemp;
	//  Check that there is only one '@'
	blnTemp = (intAtTheRate != strEMail.lastIndexOf("@"));
	
   if (blnTemp)
	return !blnTemp;
   //    extra checks
  //     AFTER '@' space is not allowed
	strTemp=strEMail.substring(intAtTheRate+1);
	blnTemp = (strTemp.indexOf(" ") > 0);
   if (blnTemp) 
		return !blnTemp;

  //   Check that there is one dot AFTER '@'
	blnTemp = (strTemp.indexOf(".") == 0);
   if (blnTemp)
		return !blnTemp;
	
	//    Check if there's a quote (")
	blnTemp = strEMail.indexOf("\"") > 0;
	 if (blnTemp )
		return !blnTemp;
	
	//     Check if there's any other disallowed chars
	//     optimize a little if strEMail longer than strInvalidChars
	//     check the other way around
	if (strEMail.length > strInvalidChars.length)
	{
		for(var i = 0; i< strInvalidChars.length;i++)
		{
			if (strEMail.indexOf(strInvalidChars.substring(i,i+1)) > 0 )
				  blnTemp = true;
			if (blnTemp )
				break;
		} //end for
	} //end if
	else
	{
		for(var i = 0 ;i< strEMail.length;i++)
		{
			if (strInvalidChars.indexOf(strEMail.substring(i,i+1)) > 0) 
				  blnTemp = true;
			if (blnTemp )
				break;
		} //end for
	} //end else
	if (blnTemp)
		return !blnTemp;
	
	//     extra check
	 //    no two consecutive dots
	blnTemp = strEMail.indexOf("..") > 0;
	if (blnTemp)
		return !blnTemp;
	
	//    if any of the above are true, invalid e-mail
	return !blnTemp;

}

function chkSubmit()
{
	if (trim(document.frmRegister.name.value) == "")
	{
		alert("Please enter Name field");
		document.frmRegister.name.focus();
		return;
	}
	if (document.frmRegister.email.value.indexOf("@") == -1 || document.frmRegister.email.value.indexOf(".") == -1 || ! isEmail(document.frmRegister.email.value))
	{
		alert("Please enter a valid email address");
		document.frmRegister.email.focus();
		return;
	}
	if (document.frmRegister.cemail.value.indexOf("@") == -1 || document.frmRegister.cemail.value.indexOf(".") == -1 || ! isEmail(document.frmRegister.cemail.value))
	{
		alert("Please enter a valid Confirm email address");
		document.frmRegister.cemail.focus();
		return;
	}
	if (trim(document.frmRegister.email.value) != trim(document.frmRegister.cemail.value))
	{
		alert("Check the email address, both need to be same!!!");
		document.frmRegister.email.focus();
		return;
	}
	if (trim(document.frmRegister.city.value) == "")
	{
		alert("Please enter City / Town");
		document.frmRegister.city.focus();
		return;
	}
	if (trim(document.frmRegister.countries.value) == "")
	{
		alert("Please select Country");
		document.frmRegister.countries.focus();
		return;
	}
	document.frmRegister.method="post";
	document.frmRegister.action = "Modelregisterdetails.asp";
	document.frmRegister.submit();
}

function chkEscort()
{
	if (trim(document.frmRegister.txtNickname.value) == "")
	{
		alert("Please enter a Nick Name");
		document.frmRegister.txtNickname.focus();
		return;
	}
	if (trim(document.frmRegister.txtPassword.value) == "")
	{
		alert("Please enter a Password");
		document.frmRegister.txtPassword.focus();
		return;
	}
	document.frmRegister.method="post";
	document.frmRegister.action = "escortEditProfile.asp?formSubmit=Submit";	
	document.frmRegister.submit();
}



function chkClient()
{

	if (trim(document.frmRegister.txtLoginName.value) == "")
	{
		alert("Please enter a Nick Name");
		document.frmRegister.txtLoginName.focus();
		return;
	}


	/*if (trim(document.frmRegister.txtPassword.value) == "")
	{
		alert("Please enter password field");
		document.frmRegister.txtPassword.focus();
		return;
	}
	if (trim(document.frmRegister.txtConPass.value) == "")
	{
		alert("Please enter Confirm password field");
		document.frmRegister.txtConPass.focus();
		return;
	}

	if (trim(document.frmRegister.txtPassword.value) != trim(document.frmRegister.txtConPass.value))
	{
		alert("Check the Password fields, both need to be same!!!");
		document.frmRegister.txtPassword.focus();
		return;
	}*/
	if (document.frmRegister.email.value.indexOf("@") == -1 || document.frmRegister.email.value.indexOf(".") == -1 || ! isEmail(document.frmRegister.email.value))
	{
		alert("Please enter a valid email address");
		document.frmRegister.email.focus();
		return;
	}

	if (trim(document.frmRegister.txtFName.value) == "")
	{
		alert("Please enter First Name field");
		document.frmRegister.txtFName.focus();
		return;
	}
	if (trim(document.frmRegister.txtLName.value) == "")
	{
		alert("Please enter Last Name field");
		document.frmRegister.txtLName.focus();
		return;
	}
	if (trim(document.frmRegister.txtAddress.value) == "")
	{
		alert("Please enter Address field");
		document.frmRegister.txtAddress.focus();
		return;
	}
/*	if (trim(document.frmRegister.txtPhone.value) == "")
	{
		alert("Please enter Contact No. field");
		document.frmRegister.txtPhone.focus();
		return;
	}*/
	if (trim(document.frmRegister.txtAge.value) == "")
	{
		alert("Please enter Age field");
		document.frmRegister.txtAge.focus();
		return;
	}
	if ( !ValidateNo( trim(frmRegister.txtAge.value), "1234567890" ) )
	{
		alert( "Please Check the Age you have entered!" );
		frmRegister.txtAge.focus();
		return;
	}
	/*if (trim(document.frmRegister.txtProfession.value) == "")
	{
		alert("Please enter Profession field");
		document.frmRegister.txtProfession.focus();
		return;
	}*/
	if (document.frmRegister.txtCCardNo1.value.length  < 4)
	{
		alert("Please enter a valid Credit Card Number");
		document.frmRegister.txtCCardNo1.focus();
		return;
	}
		if (document.frmRegister.txtCCardNo2.value.length  < 4)
	{
		alert("Please enter a valid Credit Card Number");
		document.frmRegister.txtCCardNo2.focus();
		return;
	}
	if (document.frmRegister.txtCCardNo3.value.length  < 4)
	{
		alert("Please enter a valid Credit Card Number");
		document.frmRegister.txtCCardNo3.focus();
		return;
	}
		if (document.frmRegister.txtCCardNo4.value.length  < 4)
	{
		alert("Please enter a valid Credit Card Number");
		document.frmRegister.txtCCardNo4.focus();
		return;
	}
	if (trim(document.frmRegister.txtExpiryMM.value) == "")
	{
		alert("Please enter a valid month for Credit Card Expiry Date");
		document.frmRegister.txtExpiryMM.focus();
		return;
	}
/*	if (trim(document.frmRegister.txtIssueNo.value) == "")
	{
		alert("Please enter a valid Issue Number");
		document.frmRegister.txtIssueNo.focus();
		return;
	}
*/
	if (parseInt(document.frmRegister.txtExpiryMM.value) > 12)
	{
		alert("Please enter a valid month for Credit Card Expiry Date");
		document.frmRegister.txtExpiryMM.focus();
		return;
	}
	if (trim(document.frmRegister.txtExpiryMM.value) < 1)
	{
		alert("Please enter a valid month for Credit Card Expiry Date");
		document.frmRegister.txtExpiryMM.focus();
		return;
	}

	if (document.frmRegister.txtExpiryYY.value.length  < 4)
	{
		alert("Please enter a valid Year(yyyy) for Credit Card Expiry Date");
		document.frmRegister.txtExpiryYY.focus();
		return;
	}


	document.frmRegister.method="post";
	if (trim(document.frmRegister.hidSave.value) == "new")
	{
		//document.frmRegister.action = "Clientregisterdetails.asp";	
		document.frmRegister.action = "Clientregister.asp?formSubmit=Submit";
	}
	else
	{
		document.frmRegister.action = "editProfile.asp?formSubmit=Submit";	
	}

	document.frmRegister.submit();
}

function ValidateNo( NumStr, String ) 
{
	for( var Idx = 0; Idx < NumStr.length; Idx ++ )
	{
		var Char = NumStr.charAt( Idx );
		var Match = false;
		for( var Idx1 = 0; Idx1 < String.length; Idx1 ++) 
		{
			if( Char == String.charAt( Idx1 ) ) 
			Match = true;
		}
		if ( !Match ) 
			return false;
	}
	return true;
}

function NumericOnly(i) //Check for numbers in quantity
{
	event.keyCode=DisallowNum(event.keyCode)
	

}

function DisallowNum(keyPressed)
{
	if ((keyPressed>=48 && keyPressed<=57) ||(  keyPressed ==46))
	{
	}
	else
	{
		keyPressed = 0
	}
		return keyPressed	
}


var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s)
{
	var i;
    for (i = 0; i < s.length; i++)
	{   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
	}
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
	{   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year)
{
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) 
{
	for (var i = 1; i <= n; i++) 
	{
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr)
{
	var daysInMonth = DaysArray(12);
	var pos1=dtStr.indexOf(dtCh);
	var pos2=dtStr.indexOf(dtCh,pos1+1);
	var strMonth=dtStr.substring(0,pos1);
	var strDay=dtStr.substring(pos1+1,pos2);
	var strYear=dtStr.substring(pos2+1);
	strYr=strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) 
	{
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth);
	day=parseInt(strDay);
	year=parseInt(strYr);
	if (pos1==-1 || pos2==-1)
	{
		alert("The date format should be : mm/dd/yyyy");
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12)
	{
		alert("Please enter a valid month");
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
	{
		alert("Please enter a valid day");
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear)
	{
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear);
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false)
	{
		alert("Please enter a valid date");
		return false;
	}
return true;
}

function ValidateForm()
{
	var dt=document.frmRegister.txtRegDate;
	if (trim(document.frmRegister.txtRegDate.value) != "")
	{
		if (isDate(dt.value)==false)
		{
			document.frmRegister.txtRegDate.value = currentdate();
			return false;
		}
		else
		return true;
	}
 }

function currentdate()
{

var accdate;
var months=new Array(13);
months[1]="1";
months[2]="2";
months[3]="3";
months[4]="4";
months[5]="5";
months[6]="6";
months[7]="7";
months[8]="8";
months[9]="9";
months[10]="10";
months[11]="11";
months[12]="12";
var time=new Date();
var lmonth=months[time.getMonth() + 1];
var date=time.getDate();
var year=time.getYear();
if (year < 2000)    // Y2K Fix, Isaac Powell
year = year + 1900; // http://onyx.idbsu.edu/~ipowell
//document.write("<center>" + lmonth + " ");
//document.write(date + ", " + year + "</center>");
//alert(date + "/" + lmonth + "/" + year );
accdate = ( lmonth + "/" +date + "/" + year) ;
//alert (accdate);
return accdate;
}

function chkPW()
{
	if (trim(document.frmPW.txtLogin.value) == "")
	{
		alert("Please enter valid User name");
		document.frmPW.txtLogin.focus();
		return;
	}
	document.frmPW.pw.value = "pw";
	document.frmPW.method="post";
	document.frmPW.action = "ForgotPass.asp";
	document.frmPW.submit();
}

function chgPassword()
{
	if (trim(document.frmPassword.txtPassword.value) == "")
	{
		alert("Please enter old password");
		document.frmPassword.txtPassword.focus();
		return;
	}
	if (trim(document.frmPassword.txtNew.value) == "")
	{
		alert("Please enter New password");
		document.frmPassword.txtNew.focus();
		return;
	}
	if (trim(document.frmPassword.txtConfirm.value) == "")
	{
		alert("Please enter Confirm password");
		document.frmPassword.txtConfirm.focus();
		return;
	}
	if (document.frmPassword.txtNew.value != document.frmPassword.txtConfirm.value)
	{
		alert("New Password and Confirm password should be same");
		document.frmPassword.txtConfirm.focus();
		return;
	}
	document.frmPassword.method="post";
	document.frmPassword.action = "ChangePassword.asp?formSubmit=Submit";	
	document.frmPassword.submit();
}

function submitPage()
{
	alert("hii");
	document.frmDefault.method="post";
	document.frmDefault.action = "http://www.supermodel-escorts.com/homepage.asp";	
	document.frmDefault.submit();
}

function chkMail()
{
	if (document.frmDefault.txtEmail.value.indexOf("@") == -1 || document.frmDefault.txtEmail.value.indexOf(".") == -1 || ! isEmail(document.frmDefault.txtEmail.value))
	{
		alert("Please enter a valid email address");
		document.frmDefault.txtEmail.focus();
		return;
	}
	if (!ValidateNo( trim(frmDefault.txtMobile.value), "1234567890" ) )
	{
		alert( "Please enter a valid mobile number!" );
		frmDefault.txtMobile.focus();
		return;
	}
	document.frmDefault.method="post";
	document.frmDefault.action = "SendMail.asp";	
	document.frmDefault.submit();
}


function chkLogin()
{
	if (trim(document.frmLogin.txtLogin.value) == "")
	{
		alert("Please enter Login Id");
		document.frmLogin.txtLogin.focus();
		return;
	}
	if (trim(document.frmLogin.txtPass.value) == "")
	{
		alert("Please enter Password");
		document.frmLogin.txtPass.focus();
		return;
	}
	document.frmLogin.method="post";
	document.frmLogin.action = "CheckLogin.asp";
	document.frmLogin.submit();
}