/* Common JavaScript goes here. */

/**
 * Function Name : trim
 * Description : Used to remove white space from the string
 */

function trim(sString) {
	while (sString.substring(0,1) == ' ') {
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ') {
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}



//Popup page
function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=500,left = 176,top = 32');");
}

/**
 * Function Name : isEmpty
 * Return Value : Boolean (true or false) When String empty, return true else false.
 * Description : Used to check the Form Element is null or empty.
 * Parameter Description :
 * 		HtmlElementObject obj = Html Element to validate null or empty.
 *		String errorString = String will be displayed when object value is empty
 *		String errorObjName = Element name to display a Error String, leave blank or pass 'alert' to alert the string.
 *		String defaultValue = while validating, need to consider the default value
 *
 *  Example : 
 	=>  To Display Error in Specific Element ( Div Id )
	 		if(isEmpty(document.form1.firstname, 'First Name is required', 'err_firstname' ) == true ) {
				errorFlag = true;
			}
	
	=>	To make alert for the error 
	
			if(isEmpty(document.form1.firstname, 'First Name is required', '' ) == true ) {
				return false;
			}
		
 *
 *
 */

function isEmpty(obj, errorString, errorObjName, defaultValue ) {
	
	if(obj!='') {
		
		if( trim(obj.value)=='' || obj.value == defaultValue ) {
			
			ShowMessege(errorObjName, errorString);
			
			return true;
			
		} else {
			
			if( errorObjName && errorObjName!='alert' && errorObjName!='') {
				document.getElementById(errorObjName).innerHTML = '';	
			}
			
		}
	}
	return false;
}

/**
 * Function Name : isNumeric
 * Return Value : Boolean (true or false) When value is numeric, return true else false.
 * Description : Used to check the Form Element value is numeric or not.
 * Parameter Description :
 * 		HtmlElementObject obj = Html Element to validate numeric.
 *		String errorString = String will be displayed when object value is numeric
 *		String errorObjName = Element name to display a Error String, leave blank or pass 'alert' to alert the string.
 *
 *  Example : 
 	=>  To Display Error in Specific Element ( Div Id )
	 		if(isNumeric(document.form1.mobileno, 'Mobile number must be numeric', 'err_mobileno' ) == true ) {
				errorFlag = true;
			}
	
	=>	To make alert for the error 
	
			if(isNumeric(document.form1.mobileno, 'Mobile number must be numeric', '' ) == true ) {
				return false;
			}
		
 *
 *
 */
function isNumeric(obj, errorString, errorObjName) {
	
	if(obj!='') {
		var value = obj.value;
		
		if(isNaN(value) ) {
			
			ShowMessege(errorObjName, errorString);
			
			return true;
			
		} else {
			
			if( errorObjName && errorObjName!='alert' && errorObjName!='') {
				document.getElementById(errorObjName).innerHTML = '';	
			}
			
		}
	}
	return false;
}

/**
 * Function Name : webpage url
 */
function Is_Url(theurl){
	 var tomatch= /[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
	 if (tomatch.test(theurl))
     {
       //  window.alert("URL OK.");
         return true;
     }
     else
     {
        // window.alert("URL invalid. Try again.");
         return false;
     }
}

/**
 * Function Name : emailValidate
 * Return Value : Boolean (true or false) When value is numeric, return true else false.
 * Description : Used to check the Form Element value is in email format or not.
 */

function emailValidate(email, errorString, errorObjName) {
	
	var emailFilter=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,4}))$/;
	
	if (!(emailFilter.test(email))) {
	     
		ShowMessege(errorObjName, errorString);
		
		return true;
		
	} else {
		
		if( errorObjName && errorObjName!='alert' && errorObjName!='') {
			document.getElementById(errorObjName).innerHTML = '';	
		}
		
	}
	return false;
}

/**
 * Function Name : filenameValidate
 * Return Value : Boolean (true or false) When value is numeric, return true else false.
 * Description : Used to check the Form Element value is in file format or not.
 */
function filenameValidate(filename, errorString, errorObjName) {
	
	var filenameFilter=/^[^\\\/\:\*\?\"\<\>\|\.]+(\.[^\\\/\:\*\?\"\<\>\|\.]+)+$/;
	
	if (!(filenameFilter.test(filename))) {
	     
		ShowMessege(errorObjName, errorString);
		
		return true;
		
	} else {
		
		if( errorObjName && errorObjName!='alert' && errorObjName!='') {
			document.getElementById(errorObjName).innerHTML = '';	
		}
		
	}
	return false;
}

/**
 * Function Name : popupWindow
 * Description : Used to make pop window for specified url with the give hieght and width.
 * Parameter Description :
 * 		String url = Requesting URL.
 *		int width = Width of the window.
 *		int height = Height of the window.
 *		String extraparam = other Parameters.
 */

function popupWindow(url, width, height, extraparam) {
	if(!width){ width = 50; }
	if(!height){ height = 50; }
	if(!extraparam){
		extraparam = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,top=50,left=50';
	}
	window.open( url, 'popupWindow', 'width=' + width + ',height=' + height + ',' + extraparam );
}


/**
 * Function Name : FileTypeValidate
 * Return Value : Boolean (true or false) When value is numeric, return true else false.
 * Description : Used to check the given file name has the valid extention.
 * Parameter Description :
 * 		String filename = Filename to check.
 *		String valid_ext = Valid extensions of filename provide as String.
 *		int height = Height of the window.
 *		String extraparam = other Parameters.
 *		String errorString = String will be displayed when file extension is not valid
 *		String errorObjName = Element name to display a Error String, leave blank or pass 'alert' to alert the string.
 */

function FileTypeValidate(filename, valid_ext, errorString, errorObjName ) {
	
	if(filename!='' && valid_ext && valid_ext != '') {
		
		var fileArr = filename.split(".");
		
		cnfileArr = fileArr.length;
		ext = fileArr[cnfileArr-1];
		
		if(valid_ext.indexOf(ext) == -1){
			
			ShowMessege(errorObjName, errorString);
		
			return true;
			
		} else {
			if( errorObjName && errorObjName!='alert' && errorObjName!='') {
				document.getElementById(errorObjName).innerHTML = '';	
			}
		}
	}
	return false;
}

/**
 * Function Name : compareString
 * Return Value : Boolean (true or false) When value is numeric, return true else false.
 * Description : Used to check the given file name has the valid extention.
 * Parameter Description :
 * 		String filename = Filename to check.
 *		String valid_ext = Valid extensions of filename provide as String.
 *		int height = Height of the window.
 *		String extraparam = other Parameters.
 *		String errorString = String will be displayed when file extension is not valid
 *		String errorObjName = Element name to display a Error String, leave blank or pass 'alert' to alert the string.
 */
function compareString (cStr1, cStr2, errorString, errorObjName) {
	
	if (cStr1 != cStr2){
		
		ShowMessege(errorObjName, errorString);
		
		return true;
		
	} else {
		if( errorObjName && errorObjName!='alert' && errorObjName!='') {
			document.getElementById(errorObjName).innerHTML = '';	
		}
	}
	return false;
}

function ValidationRadioSelectedItem(RadioObj, errorString, errorObjName ) {

	chosen = ""
	len = RadioObj.length
	
	for (i = 0; i <len; i++) {
		if (RadioObj[i].checked) {
			chosen = RadioObj[i].value
		}
	}
	
	if (chosen == "") {
		
		ShowMessege(errorObjName, errorString);
		
		return true;
	//	alert("No Location Chosen")
	} else {
		if( errorObjName && errorObjName!='alert' && errorObjName!='') {
			document.getElementById(errorObjName).innerHTML = '';	
		}
	}
	return false;
}

/**
 * Function Name : redirect
 * @formName: name of the form
 * @redirectToLocation: location(file name) you want to redirect.
 * Description : Redirect to specified filename
 */
function redirect(formName,redirectToLocation)
{
	if(formName != '')
	{
		with(formName)
		{
			document.location =	redirectToLocation;
		}
	}
	else {
		location.href = redirectToLocation;
	}
}

/**
 * Function Name : checkAll
 * @formName: 	name of the form
 * @checkboxid: the id of the checkbox that need to select when clicked on common chkbox (this)
 * @currentObj: object clicking on which the other checkbox specified in "checkboxid" should be selected. Generaly set value as "this"
 * Description: This function will selecte all checkboxes "checkboxid" 
 				when clicked on common checkbox generally located on top of listing used to select all items.
*/
function checkAll(formName, checkboxid, currentObj) {
	var count = formName.elements.length;
	for(i=1;i<count;i++)
	if(formName.elements[i].type=="checkbox" && formName.elements[i].id==checkboxid)
	formName.elements[i].checked=currentObj.checked;
}
//Calender function
function setupCalendar(field,btn) {
	var fieldName = field;
	var btnName = btn;
	Calendar.setup(
		{
			inputField : fieldName,
			button : btn,
			align : "B1",
			singleClick : true
		}
	)
}

function trim(Value)
{
		return Value.replace(/^\s+|\s+$/g, "");
}


function isEmail(str)
{
	var regex = /^[-_.a-z0-9]+@(([-a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
   	
	return regex.test(str);
}

/**
*	FUNCTION TO CHECK THE ALPHANUMERIC VALUSE.
**/
function isAlphaNumeric(alphane)
{
	var inputValue = alphane;
	for(var j=0; j<inputValue.length; j++)
		{
		  var alphaa = inputValue.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		  {}
		else {
             return false;
		  }
 		}
	return true;
}

function isValidProviderNumber(pNumber) {
	var inputPNum = pNumber;
	if(isAlphaNumeric(inputPNum) && inputPNum.length==8) {
		return true;
	} else {
		return false;
	}
}

//Length validation

function isValidLength(givenValue,numlength){
	if(isAlphaNumeric(givenValue) && givenValue == numlength)
	{
	return true;
	} else {
		return false;
	}
	
}

function isValidPhone(phNumber) {
	var inputPh = phNumber;
	var iChars = "0123456789+- )(";
	for (var i = 0; i < inputPh.length; i++) {
	  	if (iChars.indexOf(inputPh.charAt(i)) == -1) {
			return false;
	  	}
	}
	return true;
}

function changePwd(){
	
	
	var CurrentPassword = document.getElementById("curr_password");
	if(trim(CurrentPassword.value) == ''){
		hideAllPasswordErrors();
		document.getElementById("currpasswordError").style.display = "inline";
		CurrentPassword.focus();
		return false;
	}
	var Password = document.getElementById("Password");
	if(trim(Password.value) == ''){
		hideAllPasswordErrors();
		document.getElementById("passwordError").style.display = "inline";
		Password.focus();
		return false;
	}
	if(Password.value.length<6 | Password.value.length>75){
		hideAllPasswordErrors();
		document.getElementById("passwordLenError").style.display = "inline";
		Password.focus();
		return false;
	}
	var ConfirmPassword = document.getElementById("CPassword");
	if(trim(ConfirmPassword.value) == ''){
		hideAllPasswordErrors();
		document.getElementById("cpasswordError").style.display = "inline";
		ConfirmPassword.focus();
		return false;
	}
	
	if(Password.value != ConfirmPassword.value){
		hideAllPasswordErrors();
		document.getElementById("cppError").style.display = "inline";
		ConfirmPassword.focus();
		return false;
	}
	return true;
}

function hideAllPasswordErrors() {
	document.getElementById("currpasswordError").style.display = "none";
    document.getElementById("passwordError").style.display = "none";
    document.getElementById("passwordLenError").style.display = "none";
	document.getElementById("cpasswordError").style.display = "none";
	document.getElementById("cppError").style.display = "none";
}


function hideAllErrors() {
	document.getElementById("firstnameError").style.display = "none";
	document.getElementById("lastnameError").style.display = "none";
	document.getElementById("usernameError").style.display = "none";
    document.getElementById("passwordError").style.display = "none";
    document.getElementById("passlengtherror").style.display = "none";
	document.getElementById("emailError").style.display = "none";
	document.getElementById("invalidemailError").style.display = "none";
	//document.getElementById("stateError").style.display = "none";
	document.getElementById("usertypeError").style.display = "none";
}
function user_personalinfo(){
	var Firstname = document.getElementById("Firstname");
	if(trim(Firstname.value) == ''){
		hideAllErrors();
		document.getElementById("firstnameError").style.display = "inline";
		Firstname.focus();
		return false;
	}
	var Lastname = document.getElementById("Lastname");
	if(trim(Lastname.value) == ''){
		hideAllErrors();
		document.getElementById("lastnameError").style.display = "inline";
		Lastname.focus();
		return false;
	}
	var Username = document.getElementById("Username");
	if(trim(Username.value) == ''){
		hideAllErrors();
		document.getElementById("usernameError").style.display = "inline";
		Username.focus();
		return false;
	}
	var Password = document.getElementById("Password");
	if(trim(Password.value) == ''){
		hideAllErrors();
		document.getElementById("passwordError").style.display = "inline";
		Password.focus();
		return false;
	}
	if(Password.value.length<4){
		hideAllErrors();
		document.getElementById("passlengtherror").style.display = "inline";
		Password.focus();
		return false;
	}
	var Email = document.getElementById("Email");
	if(trim(Email.value) == ''){
		hideAllErrors();
		document.getElementById("emailError").style.display = "inline";
		Email.focus();
		return false;
	}
	if(!isEmail(Email.value)){
		hideAllErrors();
		document.getElementById("invalidemailError").style.display = "inline";
		Email.focus();
		return false;
	}
	/*if(document.Frmaddclient.State.selectedIndex == 0 ){
		hideAllErrors();
		document.getElementById("stateError").style.display = "inline";
		document.Frmaddclient.State.focus();
		return false;
	}*/
	if(document.Frmaddclient.user_type.selectedIndex == 0 ){
		hideAllErrors();
		document.getElementById("usertypeError").style.display = "inline";
		document.Frmaddclient.user_type.focus();
		return false;
	}
	
	return true;
}

function ValidLogin()
{
    var Username = document.getElementById("LUsername");
	if(trim(Username.value) == ''){
		hideAllLoginErrors();
		document.getElementById("lusernameError").style.display = "inline";
		Username.focus();
		return false;
	}
	var Password = document.getElementById("LPassword");
	if(trim(Password.value) == ''){
		hideAllLoginErrors();
		document.getElementById("lpasswordError").style.display = "inline";
		Password.focus();
		return false;
	}
	return true;
}
function hideAllLoginErrors() {
	document.getElementById("lusernameError").style.display = "none";
    document.getElementById("lpasswordError").style.display = "none";
}

//Forgot password

function ValidForgotPass () {
	
	var Email = document.getElementById("Email");
	if(trim(Email.value) == ''){
		hideAllForPassErrors();
		document.getElementById("emailError").style.display = "inline";
		Email.focus();
		return false;
	}
	
	if(!isEmail(Email.value)){
		hideAllForPassErrors();
		document.getElementById("invalidemailError").style.display = "inline";
		Email.focus();
		return false;
	}
	
	
	return true;
	
}
function hideAllForPassErrors() {
	document.getElementById("emailError").style.display = "none";
	document.getElementById("invalidemailError").style.display = "none";
}

//SHow hide plus and minus image for provider
function showdes(id)
{
	str="pro_"+(parseInt(id)+1);
	document.getElementById(str).style.display="";
	strTextPro="dPprovider_number"+(parseInt(id)+1);  
	strTextState="dPprovider_state"+(parseInt(id)+1);  
	strTextDef="dPprovider_number"+(parseInt(id)+1);  
	document.getElementById(strTextPro).value="";     
	document.getElementById(strTextState).selectedIndex=0;     
	document.getElementById(strTextDef).value="";  
	
	if(str == "pro_"+(parseInt(id)+1)){
	plusId="plus_img"+(parseInt(id));
	minusId="minus_img"+(parseInt(id));
	document.getElementById(plusId).style.display="none";
	document.getElementById(minusId).style.display="none";
	}
	if(str == "pro_15"){
		plusMId="plus_img"+(parseInt(id)+1);
		document.getElementById(plusMId).style.display="none";
		}
}  
function hidedes(id)
{	
	strTextDef="dPdefault";
	if(document.frmAddEditDr.dPdefault[id-1].checked == true)
	{
		alert('You can not remove default Provider number.\n Please set another provider number as a default before removing this provider number');
		return false;
	}
	strhide="pro_"+(parseInt(id));
	document.getElementById(strhide).style.display="none";
	if(strhide == "pro_"+(parseInt(id))){
		
		if(strhide == "pro_2"){
		plusMId="plus_img"+(parseInt(id)-1);
		document.getElementById(plusMId).style.display="";
		}
		
		else{	
		plusMId="plus_img"+(parseInt(id)-1);
		minusId="minus_img"+(parseInt(id)-1);
		document.getElementById(plusMId).style.display="";
		document.getElementById(minusId).style.display="";
		}
	
	}
	
	strTextPro="dPprovider_number"+(parseInt(id));  
	strTextState="dPprovider_state"+(parseInt(id));  
	strTextDef="dPprovider_number"+(parseInt(id));  
	document.getElementById(strTextPro).value="";     
	document.getElementById(strTextState).selectedIndex=0;     
	document.getElementById(strTextDef).value="";    
	 
}   
//Edit provider function
function editRecordPro(id){
for(i=1;i<id;i++){
	plusId="plus_img"+(parseInt(i));
	minusId="minus_img"+(parseInt(i));
	document.getElementById(plusId).style.display="none";
	document.getElementById(minusId).style.display="none";
}
}

//Edit record for doctor provider 
function clearValue(id)
{
	strTextPro="dPprovider_number"+(parseInt(id));  
	strTextState="dPprovider_state"+(parseInt(id));  
	strTextDef="dPdefault";
	if(document.frmAddEditDr.dPdefault[id-1].checked == true)
	{
		alert('You can not remove default Provider number.\n Please set another provider number as a default before removing this provider number');
		return false;
	}
	strCv="clearproval_"+(parseInt(id));
	document.getElementById(strCv).style.display="none";
	document.getElementById(strTextPro).value="";     
	document.getElementById(strTextState).selectedIndex=0;     
	
}   
//End Doctor ADD-EDIT VALIDATIONS

//Patients ADD VALIDATION START
function check_box(frm,elementNumber,elementName)
{
	   with(frm)
	   {
		var boxChk = elementName+'['+elementNumber+']';
		document.getElementById(boxChk).checked=true;
	   }
}

var dtCh= "/";
var minotifyyear=1900;
var maxYear=2100;
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 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 isDate(dtStr){
	var daysInotifymonth = 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 strDay=dtStr.substring(0,pos1)
	var strMonth=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=eval(strMonth)
	day=eval(strDay)
	year=eval(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 > daysInotifymonth[month]){
		//alert("Please enter a valid day");
		return false
	}
	if (strYear.length != 4 || year==0 || year<minotifyyear || year>maxYear){
		var d = new Date();
		var upperlimityear = (eval(d.getFullYear()) > maxYear)? maxYear: d.getFullYear();
		//alert("Please enter a valid 4 digit year between "+minotifyyear+" and "+upperlimityear);
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date");
		return false
	}
//return true
return true
}

function GetDays(toyear, tomonth, today, fromyear, frommonth, fromday)
{
	DDate= new Date(toyear,tomonth-1,today);
	NDate=	new Date(fromyear,frommonth-1,fromday);
	var Days = new String((NDate-DDate)/86400000);
	return Math.floor(Days);
}

function futureDate(ddmmyy) {
  dateParts = ddmmyy.split('/');
  var myDate = new Date(dateParts[2],eval(dateParts[1])-1,dateParts[0]);
  var today  = new Date();  
  if(myDate>today) {
    return true;
  } else {
    return false;
  }
}

function futureMonthYr(monthValue,yearValue) {
   	dt= new Date ();
   	curYr = dt.getFullYear();
   	curMnt = dt.getMonth()+1;
   	tstdt= (curYr*12) + curMnt;
   	entryYR = yearValue;
	entryMN = monthValue; //(frm.eMonth.selectedIndex>0)? frm.eMonth.selectedIndex : 0;
   	entryval= eval(entryYR*12) + eval(entryMN);
   	if ((!isNaN(entryval)) && (entryval>=tstdt)) { return true; } //alert('date is valid');
	else { return false; }
}

function showhide(val, id)
{
        var hideshowid = document.getElementById(id);
        if(val == 'RVG_INVOICE')
        {
                hideshowid.style.display = "inline";
        }
        else
        {
                hideshowid.style.display = "none";
        }
}
function showhideWithCheckbox(checkboxId, hideshowId)
{
        var checkboxId = document.getElementById(checkboxId);
        var hideshowId = document.getElementById(hideshowId);
        if(checkboxId.checked == true)
        {
                hideshowId.style.display = "inline";
        }
        else
        {
                hideshowId.style.display = "none";
        }
}
//Function for field name that only allowed Digits...
function DigitsOnly(FieldName)
{
        if(FieldName.value != '')
        {
                var ValidChars = "0123456789";
                for (j = 0; j < FieldName.value.length; j++)
                {
                        var Char = FieldName.value.charAt(j);
                        if (ValidChars.indexOf(Char) == -1)
                        {
                                return  false;
                        }
                }
        }
}

//Function for field name that only allowed Digits, +, and -(for eg. telephone no: IN IN +91  2221113456  Call   Call )...
function DigitsPlusMinus(FieldName)
{
        if(FieldName.value != "")
        {
                var ValidChars = "0123456789-+( ) ";
                for (j = 0; j < FieldName.value.length; j++)
                {
                        var Char = FieldName.value.charAt(j);
                        if (ValidChars.indexOf(Char) == -1)
                        {
                                return  false;
                        }
                }
                return true;
        }
}

// NEWLY ADDED FUNCTIONS BY RUPAL 

function GetXmlHttpObject(handler) // for ajax
{
	var objXmlHttp=null

	if (navigator.userAgent.indexOf("Opera")>=0)
	{
		alert("This Site doesn't work in Opera")
		return
	}
	if (navigator.userAgent.indexOf("MSIE")>=0)
	{
		var strName="Msxml2.XMLHTTP"
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
		{
			strName="Microsoft.XMLHTTP"
		}
		try
		{
			objXmlHttp=new ActiveXObject(strName)
			objXmlHttp.onreadystatechange=handler
			return objXmlHttp
		}
		catch(e)
		{
			alert("Error. Scripting for ActiveX might be disabled")
			return
		}
	}
	if (navigator.userAgent.indexOf("Mozilla")>=0)
		{
			objXmlHttp=new XMLHttpRequest()
			objXmlHttp.onload=handler
			objXmlHttp.onerror=handler
			return objXmlHttp
		}
}


			var startDate;
			var endDate;
			var callbacks = 0;

			function resetDates() {
				startDate = endDate = null;
			}


			/*
			* Given two dates (in seconds) find out if date1 is bigger, date2 is bigger or
			 * they're the same, taking only the dates, not the time into account.
			 * In other words, different times on the same date returns equal.
			 * returns -1 for date1 bigger, 1 for date2 is bigger 0 for equal
			 */

			function compareDatesOnly(date1, date2) {
				var year1 = date1.getYear();
				var year2 = date2.getYear();
				var month1 = date1.getMonth();
				var month2 = date2.getMonth();
				var day1 = date1.getDate();
				var day2 = date2.getDate();

				if (year1 > year2) {
					return -1;
				}
				if (year2 > year1) {
					return 1;
				}

				//years are equal
				if (month1 > month2) {
					return -1;
				}
				if (month2 > month1) {
					return 1;
				}

				//years and months are equal
				if (day1 > day2) {
					return -1;
				}
				if (day2 > day1) {
					return 1;
				}

				//days are equal
				return 0;


				/* Can't do this because of timezone issues
				var days1 = Math.floor(date1.getTime()/Date.DAY);
				var days2 = Math.floor(date2.getTime()/Date.DAY);
				return (days1 - days2);
				*/
			}

			function filterDates1(cal) {
				startDate = cal.date;
				/* If they haven't chosen an
				end date before we'll set it to the same date as the start date This
				way if the user scrolls in the start date 5 months forward, they don't
				need to do it again for the end date.
				*/

				if (endDate == null) {
					Zapatec.Calendar.setup({
						inputField     :    "arrivalDate",
						button         :    "button8b",  // What will trigger the popup of the calendar
						ifFormat       :    "%Y-%m-%d ",
						timeFormat     :    "24",
						date           :     startDate,
						electric       :     false,
						showsTime      :     false,          //no time
						disableFunc    :    dateInRange2, //the function to call
						onUpdate       :    filterDates2
					});
				}
			}

			function filterDates2(cal) {
				endDate = cal.date;
			}

			/*
			* Both functions disable and hilight dates.
			*/

			/*
			* Can't choose days after the
			* end date if it is choosen, hilights start and end dates with one style and dates between them with another
			*/
			function dateInRange1(date) {

				if (endDate != null) {

					// Disable dates after end date
					var compareEnd = compareDatesOnly(date, endDate);
					if  (compareEnd < 0) {
						return (true);
					}

					// Hilight end date with "edges" style
					if  (compareEnd == 0) {
						{return "edges";}
					}


					// Hilight inner dates with "between" style
					if (startDate != null){
						var compareStart = compareDatesOnly(date, startDate);
						if  (compareStart < 0) {
							return "between";
						}
					}
				}

				//disable days prior to today
				var today = new Date();
				var compareToday = compareDatesOnly(date, today);
				if (compareToday > 0) {
					return(true);
				}


				//all other days are enabled
				return false;
				//alert(ret + " " + today + ":" + date + ":" + compareToday + ":" + days1 + ":" + days2);
				return(ret);
			}

			/*
			* Can't choose days before the
			* start date if it is choosen, hilights start and end dates with one style and dates between them with another
			*/

			function dateInRange2(date) {
				if (startDate != null) {
					// Disable dates before start date
					var compareDays = compareDatesOnly(startDate, date);
					if  (compareDays < 0) {
						return (true);
					}

					// Hilight end date with "edges" style
					if  (compareDays == 0) {
						{return "edges";}
					}

					// Hilight inner dates with "between" style
					if ((endDate != null) && (date > startDate) && (date < endDate)) {
						return "between";
					}
				}

				var now = new Date();
				if (compareDatesOnly(now, date) < 0) {
					return (true);
				}

				//all other days are enabled
				return false;
			}
/**
Call function disableEnterKey(event,true/false);
**/
function disableEnterKey(e,chkZip)
{
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     
	          
  
  if(chkZip){
    if((key>=47 && key<=57) || key==8 || key==13 || key==9 || key==12 || key==27 || key==0 || key==45)
    {
    	return true;
    }
    else{
    	return false;
    }
  }
  else {
  	 if((key>=48 && key<=57) || key==8 || key==13 || key==9 || key==12 || key==27 || key==0)
    {
    	return true;
    }
    else{
    	return false;
    }  	
  }    //return (key != 65);
}
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;
}

// common function used for new member registration - here i used fix form name and iits element 
// its not global function but common for front and admin side thats why defined here so dont have to define both side in pages
function trim(Value)
{
		return Value.replace(/^\s+|\s+$/g, "");
}
function isWhitespace(s)
{
  for(var i = 0; i < s.length; i++)
	 { //alert(i);
		if (s.charAt(i)==" ")
	 	  return true;	  		  	
	}
 return false;	
}
function ValidateLogin(chkAction){

	var iChars = "!#$%^&*()+=-[]\\\';,/{}|\":<>?";
//      var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
	if(trim(document.FrmRegister.Username.value) == '')
	{

		hideloginerror(chkAction);
		document.getElementById("usernameError").style.display = "inline";

		document.FrmRegister.Username.focus();
		return  false;
	}
	else {

		hideloginerror(chkAction);
		if(isWhitespace(document.FrmRegister.Username.value)){document.getElementById("usernameNoError").style.display = "inline";return false;}
		for (var i = 0; i < document.FrmRegister.Username.value.length; i++)
		 { //alert(i);		  	
		 	if (iChars.indexOf(document.FrmRegister.Username.value.charAt(i)) != -1)
		  	{
			  //  alert ("Special Characters and Number Should not Allowed");
			
			  	document.getElementById("usernameNoError").style.display = "inline";
			  	document.FrmRegister.Username.focus();
				return false;
		  	}
		}
		  var firstnamelength=document.FrmRegister.Username.value;
		  var firstlen = firstnamelength.length;
			if((firstlen < 3) | (firstlen > 25))
			{
				//alert('Password must be six character long');
				document.getElementById("usernameLenError").style.display = "inline";
				document.FrmRegister.Username.focus();
				return  false;
			}
	}
	
	
	var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
	 
	if(chkAction=="0"){	// Check password validation if data is send to add 
	if(trim(document.FrmRegister.Password.value) == '')
	{
		
		hideloginerror(chkAction);
		document.getElementById("passwordError").style.display = "inline";

		document.FrmRegister.Password.focus();
		return  false;
	}
	else {
		
		hideloginerror(chkAction);

		 var passwordval=document.FrmRegister.Password.value;
		 
		 if(isWhitespace(passwordval)){document.getElementById("passwordNoError").style.display = "inline";return false;}
		  for (var i = 0; i < document.FrmRegister.Password.value.length; i++) 
		  {
		  	if (iChars.indexOf(document.FrmRegister.Password.value.charAt(i)) != -1) {
			  	document.getElementById("passwordNoError").style.display = "inline";
			  	document.FrmRegister.Password.focus();
				return false;
		  	}
		}
		  var passlen = passwordval.length;
			if((passlen < 6) | (passlen > 75))
			{
				document.getElementById("passwordLenError").style.display = "inline";
				document.FrmRegister.Password.focus();
				return  false;
			}
	}
	
	
	if(trim(document.FrmRegister.CPassword.value) == '')
	{
		//alert('Enter Password');
		hideloginerror(chkAction);
		document.getElementById("cpasswordError").style.display = "inline";

		document.FrmRegister.CPassword.focus();
		return  false;
	}
	
	if(document.FrmRegister.Password.value.length > 0  && document.FrmRegister.CPassword.value.length > 0 )
	{
		if(document.FrmRegister.Password.value != document.FrmRegister.CPassword.value)
		{
			hideloginerror(chkAction);
			document.FrmRegister.CPassword.value='';
			document.getElementById("cppError").style.display = "inline";

			document.FrmRegister.CPassword.focus();
			return false;
		}
	}
	}
	
	if(trim(document.FrmRegister.Email.value) == '')
	{
		//alert('Enter Password');
		hideloginerror(chkAction);
		document.getElementById("emailError").style.display = "inline";

		document.FrmRegister.Email.focus();
		return  false;
	}

	else {
		emails=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
		var membermailid = document.FrmRegister.Email.value;
		result1=membermailid.search(emails);
		if(result1==-1)
		{
			//alert('Please Enter Valid Email');
			//hideAllErrorscontact();
			hideloginerror(chkAction);

			document.getElementById("emailErrorFormat").style.display = "inline";
			document.FrmRegister.Email.focus();
			return false;
		}
	}

	if(trim(document.FrmRegister.Firstname.value) == '')
	{
		hideloginerror(chkAction);
		document.getElementById("firstnameError").style.display = "inline";

		document.FrmRegister.Firstname.focus();
		return  false;
	}
	if(trim(document.FrmRegister.Lastname.value) == '')
	{
		hideloginerror(chkAction);
		document.getElementById("lastnameError").style.display = "inline";

		document.FrmRegister.Lastname.focus();
		return  false;
	}
	
	if(trim(document.FrmRegister.Current_address.value) == '')
	{
		hideloginerror(chkAction);
		document.getElementById("addressError").style.display = "inline";

		document.FrmRegister.Current_address.focus();
		return  false;
	}
	//alert(document.FrmRegister.Current_address.value);
	phone1 = document.FrmRegister.phone1.value
	phone2 = document.FrmRegister.phone2.value
	phone3 = document.FrmRegister.phone3.value
	Phone = phone1+phone2+phone3;
	//alert(Phone);return false;
	if(trim(phone1) == '' || trim(phone2) == '' || trim(phone3) == '')
	{
		hideloginerror(chkAction);
		document.getElementById("phoneError").style.display = "inline";
			//alert("test");
		document.FrmRegister.phone1.focus();
		return  false;
	}else{
		if(isInteger(Phone) == false){
			hideloginerror(chkAction);
		document.getElementById("phonenoError").style.display = "inline";

		document.FrmRegister.phone1.focus();

		return  false;
		}
	}
    if(chkAction=="0"){	// Check verification code if data is send to add 
        if(trim(document.FrmRegister.txtverification.value) == '')
    	{
    		hideloginerror(chkAction);
    		document.getElementById("verificationCodeError").style.display = "inline";
    
    		document.FrmRegister.txtverification.focus();
    		return  false;
    	}
        
    }	
	return true;
}

function hideloginerror(chkAction) {
	document.getElementById("usernameError").style.display = "none";
	document.getElementById("usernameNoError").style.display = "none";
	document.getElementById("usernameLenError").style.display = "none";
	
	if(chkAction=="0"){	// Check password validation if data is send to add 
	document.getElementById("passwordError").style.display = "none";
	document.getElementById("passwordNoError").style.display = "none";
	document.getElementById("passwordLenError").style.display = "none";
	document.getElementById("cpasswordError").style.display = "none";
	document.getElementById("cpasswordNoError").style.display = "none";
	//document.getElementById("cpasswordLenError").style.display = "none";
	document.getElementById("cppError").style.display = "none";
	}
	document.getElementById("emailError").style.display = "none";
	document.getElementById("emailErrorFormat").style.display = "none";
	document.getElementById("firstnameError").style.display = "none";
	document.getElementById("lastnameError").style.display = "none";
	document.getElementById("phoneError").style.display = "none";
	document.getElementById("phonenoError").style.display = "none";
	document.getElementById("addressError").style.display = "none";

}
//send message
function send_messageinfo(){
	
	var Manager = document.getElementById("rec_id");
	if(trim(Manager.value) == ''){
		hideAllMessageErrors();
		document.getElementById("managerError").style.display = "inline";
		Manager.focus();
		return false;
	}
	
	var Subject = document.getElementById("subject");
	if(trim(Subject.value) == ''){
		hideAllMessageErrors();
		document.getElementById("subjectError").style.display = "inline";
		Subject.focus();
		return false;
	}
	
	var Message = document.getElementById("message");
	if(trim(Message.value) == ''){
		hideAllMessageErrors();
		document.getElementById("messageError").style.display = "inline";
		Message.focus();
		return false;
	}
	
	
	return true;
}
function hideAllMessageErrors()
{
	document.getElementById("managerError").style.display = "none";
	document.getElementById("subjectError").style.display = "none";
	document.getElementById("messageError").style.display = "none";
}
function send_replymessage(){
	var Message = document.getElementById("message");
	if(trim(Message.value) == ''){
		document.getElementById("messageError").style.display = "inline";
		Message.focus();
		return false;
	}
}
/*
* For Check/Uncheck checkbox array 
* chkUncheck(document.FormName.elements['Checkbox[]']); // Checkbox = Checkbox name whcih you defined as array
*/
function chkUncheck(chkStatus,chk)
{
	if(chkStatus == true){
	for (i = 0; i < chk.length; i++)
	chk[i].checked = true ;
	}
	else{	
	for (i = 0; i < chk.length; i++)
	chk[i].checked = false ;
	}
}
/*
* For Expand/Collaps Div conent 
* switchMenu('yourdivid'); // yourdivid = Div id which you want to Expand/Collaps
*/
function switchMenu(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != "none" ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}
// Property main Details validations 

function trim(Value)
{
		return Value.replace(/^\s+|\s+$/g, "");
}
function ValidateProperty(UserId){

	// Commented because username not required for suggested property
	/*if(trim(document.FrmListProperty.user.value) == ''){
			
		hidepropertyerrors(UserId);	
		document.getElementById("userNameError").style.display = "inline";
		document.FrmListProperty.user.focus();
		return false;
	}
	else {
		hidepropertyerrors(UserId);
	}*/
	
	var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
	
	if(trim(document.FrmListProperty.PropertyName.value) == ''){
			
		hidepropertyerrors(UserId);	
		document.getElementById("propertynameError").style.display = "inline";
		document.FrmListProperty.PropertyName.focus();
		return  false;
	}
		
	var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";

	if(trim(document.FrmListProperty.Company.value) == ''){
						hidepropertyerrors(UserId);
						document.getElementById("companynameError").style.display = "inline";
						document.FrmListProperty.Company.focus();
						return  false;
					}
	else {
		hidepropertyerrors(UserId);
	      var firstnamelength=document.FrmListProperty.Company.value;
		  var firstlen = firstnamelength.length;
			if((firstlen < 3) | (firstlen > 50))
			{
				document.getElementById("companynameLenError").style.display = "inline";
				document.FrmListProperty.Company.focus();
				return  false;
			}
	}
if(trim(document.FrmListProperty.PropertyContact.value) == '')
	{

		hidepropertyerrors(UserId);
		document.getElementById("propertycontactError").style.display = "inline";

		document.FrmListProperty.PropertyContact.focus();
		return  false;
	}
	 var iChars = "0123456789";

	if(document.FrmListProperty.Units.value == ''){
						hidepropertyerrors(UserId);
						document.getElementById("unitsError").style.display = "inline";
						document.FrmListProperty.Units.focus();
						return  false;
					}
	else {
		hidepropertyerrors(UserId);

		for (var i = 0; i < document.FrmListProperty.Units.value.length; i++)
		 {
		  	if (iChars.indexOf(document.FrmListProperty.Units.value.charAt(i)) == -1) {

			  	document.getElementById("unitsNoError").style.display = "inline";

			  	document.FrmListProperty.Units.focus();
				return false;
		  	}
		}

	}
    if(trim(document.FrmListProperty.Year.value) == '')
	{
		hidepropertyerrors(UserId);
		document.getElementById("yearError").style.display = "inline";

		document.FrmListProperty.Year.focus();
		return  false;
	}
    if(trim(document.FrmListProperty.YearRe.value) != '')
	{
		if(document.FrmListProperty.YearRe.value<document.FrmListProperty.Year.value)
		{
		hidepropertyerrors(UserId);
		document.getElementById("lessyearreError").style.display = "inline";

		document.FrmListProperty.YearRe.focus();
		return  false;}
	}
	if(document.FrmListProperty.Email.value == '')
	{
		hidepropertyerrors(UserId);
		document.getElementById("emailError").style.display = "inline";

		document.FrmListProperty.Email.focus();
		return  false;
	}

	else {
		var emails=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
		var membermailid = document.FrmListProperty.Email.value;
		result1=membermailid.search(emails);
		if(result1==-1)
		{

			hidepropertyerrors(UserId);
			document.getElementById("emailErrorFormat").style.display = "inline";
			document.FrmListProperty.Email.focus();
			return false;
		}
	}
    if(trim(document.FrmListProperty.Address.value) == '')
	{

		hidepropertyerrors(UserId);
		document.getElementById("addressError").style.display = "inline";
		document.FrmListProperty.Address.focus();
		return false;
	}
       
	if(document.FrmListProperty.State.value == '')
	{
		
		hidepropertyerrors(UserId);
		document.getElementById("stateError").style.display = "inline";
		document.FrmListProperty.State.focus();
		return false;
	}

	if(document.FrmListProperty.City.value == '')
	{
		hidepropertyerrors(UserId);
		document.getElementById("cityError").style.display = "inline";
		document.FrmListProperty.City.focus();
		return false;
	}


	if(trim(document.FrmListProperty.Area.value) == '')
	{
		hidepropertyerrors(UserId);
		document.getElementById("areaError").style.display = "inline";

		document.FrmListProperty.Area.focus();
		return false;
	}
	
	if(trim(document.FrmListProperty.Zip.value) == '')
	{
		hidepropertyerrors(UserId);
		document.getElementById("zipError").style.display = "inline";
		document.FrmListProperty.Zip.focus();
		return false;
	}



	if(trim(document.FrmListProperty.ContactNo.value) == '')
	{
		hidepropertyerrors(UserId);
		document.getElementById("contactnoError").style.display = "inline";

		document.FrmListProperty.ContactNo.focus();
		return  false;
	}

 /*  if(trim(document.FrmListProperty.Fax.value) == '')
	{
		hidepropertyerrors(UserId);
		document.getElementById("faxError").style.display = "inline";
		document.FrmListProperty.Fax.focus();
		return false;
	}*/
	
	if(trim(UserId)!="0") // Check only if manager Add property
	{	
	if(trim(document.FrmListProperty.BillTo.value) == '')
	{
		hidepropertyerrors(UserId);
		document.getElementById("billtoError").style.display = "inline";

		document.FrmListProperty.BillTo.focus();
		return  false;
	}


	if(trim(document.FrmListProperty.BillAddress.value) == '')
	{
		
		hidepropertyerrors(UserId);
		document.getElementById("billaddressError").style.display = "inline";
		document.FrmListProperty.BillAddress.focus();
		return  false;
	}

	if(document.FrmListProperty.BillState.value == '')
	{
		
		hidepropertyerrors(UserId);
		document.getElementById("billstateError").style.display = "inline";
		document.FrmListProperty.BillState.focus();
		return  false;
	}

	if(document.FrmListProperty.BillCity.value == '')
	{
		hidepropertyerrors(UserId);
		document.getElementById("billcityError").style.display = "inline";
		document.FrmListProperty.BillCity.focus();
		return false;
	}

	if(trim(document.FrmListProperty.BillZip.value) == '')
	{
		hidepropertyerrors(UserId);
		document.getElementUserIdById("billzipError").style.display = "inline";
		document.FrmListProperty.BillZip.focus();
		return  false;
	}
    if(trim(document.FrmListProperty.BillPhone.value) == '')
	{
		hidepropertyerrors(UserId);
		document.getElementById("billphoneError").style.display = "inline";
		document.FrmListProperty.BillPhone.focus();
		return false;
	}
	if(trim(document.FrmListProperty.BillContact.value) == '')
	{
		hidepropertyerrors(UserId);
		document.getElementById("billcontactError").style.display = "inline";
		document.FrmListProperty.BillContact.focus();
		return false;
	}
	if(document.FrmListProperty.BillEmail.value == '')
	{
	
		hidepropertyerrors(UserId);
		document.getElementById("billemailError").style.display = "inline";
		document.FrmListProperty.BillEmail.focus();
		return  false;
	}

	else {
				
		hidepropertyerrors(UserId);
		var emails=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
		var membermailid = document.FrmListProperty.BillEmail.value;
		result1=membermailid.search(emails);
		if(result1==-1)
		{

			hidepropertyerrors(UserId);
			document.getElementById("billemailErrorFormat").style.display = "inline";
			document.FrmListProperty.BillEmail.focus();
			return false;
		}
	}

	/*if(trim(document.FrmListProperty.BillFax.value) == '')
	{
		hidepropertyerrors(UserId);
		document.getElementById("billfaxError").style.display = "inline";
		document.FrmListProperty.BillFax.focus();
		return false;
	}*/
	}
	return true;
}



function hidepropertyerrors(UserId) {
	document.getElementById("userNameError").style.display = "none";
	document.getElementById("propertynameError").style.display = "none";
	document.getElementById("propertynameLenError").style.display = "none";
	document.getElementById("companynameError").style.display = "none";
	document.getElementById("companynameLenError").style.display = "none";
	document.getElementById("propertycontactError").style.display = "none";
	document.getElementById("unitsError").style.display = "none";
	document.getElementById("unitsNoError").style.display = "none";
    document.getElementById("yearError").style.display = "none";
    document.getElementById("lessyearreError").style.display = "none";
	document.getElementById("emailError").style.display = "none";
	document.getElementById("emailErrorFormat").style.display = "none";
	document.getElementById("addressError").style.display = "none";
	document.getElementById("stateError").style.display = "none";
	document.getElementById("cityError").style.display = "none";
	document.getElementById("areaError").style.display = "none";
	document.getElementById("zipError").style.display = "none";
	document.getElementById("contactnoError").style.display = "none";
//	document.getElementById("faxError").style.display = "none";
	if(trim(UserId)!="0") // Check only if manager Add property
	{	
	document.getElementById("billtoError").style.display = "none";
	document.getElementById("billaddressError").style.display = "none";
	document.getElementById("billstateError").style.display = "none";
	document.getElementById("billcityError").style.display = "none";
	document.getElementById("billzipError").style.display = "none";
	document.getElementById("billphoneError").style.display = "none";
	document.getElementById("billcontactError").style.display = "none";
	document.getElementById("billemailError").style.display = "none";
//	document.getElementById("billfaxError").style.display = "none";
	}
	document.getElementById("officehourError").style.display = "none";
	
}
function copybillcontact(frm) {
	
	if (frm.chkCopyProperty.checked == true) {
		showbillcity(frm.State.value,frm.City.value,'BillCity');
		frm.BillPhone.value = frm.ContactNo.value;
		frm.BillContact.value = frm.PropertyContact.value;
		frm.BillEmail.value = frm.Email.value;
		frm.BillZip.value = frm.Zip.value;
		//showzones(frm.City.value,frm.State.value,'BillZip');
		frm.BillTo.value = frm.PropertyName.value;
		frm.BillFax.value =frm.Fax.value;
		frm.BillAddress.value= frm.Address.value;
		frm.BillCity.value = frm.City.value;
		frm.BillState.value = frm.State.value;
		
		
		
	}
	
}
///// Property Fllor plan validations

function ValidateFloorPlan(){

	if(trim(document.FrmAddPropertyFloorPlan.plan_type.value) == ''){
			
		hidefloorplanerrors();	
		document.getElementById("plantypeError").style.display = "block";
		document.FrmAddPropertyFloorPlan.plan_type.focus();
		return false;
	}
			
	if(trim(document.FrmAddPropertyFloorPlan.floor_plan.value) == ''){
		hidefloorplanerrors();
		document.getElementById("floorplanError").style.display = "block";
		document.FrmAddPropertyFloorPlan.floor_plan.focus();
		return  false;
	}
					
	if(trim(document.FrmAddPropertyFloorPlan.planname.value) == ''){
		hidefloorplanerrors();
		document.getElementById("plannameError").style.display = "block";
		document.FrmAddPropertyFloorPlan.planname.focus();
		return  false;
	}				

	var iChars = "0123456789";

	if(document.FrmAddPropertyFloorPlan.footage.value == ''){
		hidefloorplanerrors();
		document.getElementById("footageError").style.display = "block";
		document.FrmAddPropertyFloorPlan.footage.focus();
		return  false;
	}
	else {
		hidefloorplanerrors();
		for (var i = 0; i < document.FrmAddPropertyFloorPlan.footage.value.length; i++)
		 {
		  	if (iChars.indexOf(document.FrmAddPropertyFloorPlan.footage.value.charAt(i)) == -1) {
			  	document.getElementById("footageNumError").style.display = "block";
			  	document.FrmAddPropertyFloorPlan.footage.focus();
				return false;
		  	}
		}

	}
   
	if(document.FrmAddPropertyFloorPlan.starting_at.value == ''){
		hidefloorplanerrors();
		document.getElementById("priceError").style.display = "block";
		document.FrmAddPropertyFloorPlan.starting_at.focus();
		return  false;
	}
	else {
		hidefloorplanerrors();
		for (var i = 0; i < document.FrmAddPropertyFloorPlan.starting_at.value.length; i++)
		 {
		  	if (iChars.indexOf(document.FrmAddPropertyFloorPlan.starting_at.value.charAt(i)) == -1) {
			  	document.getElementById("priceNumError").style.display = "block";
			  	document.FrmAddPropertyFloorPlan.starting_at.focus();
				return false;
		  	}
		}

	}
	return true;
}
function hidefloorplanerrors() {
	document.getElementById("plantypeError").style.display = "none";
	document.getElementById("floorplanError").style.display = "none";
	document.getElementById("plannameError").style.display = "none";
	document.getElementById("footageError").style.display = "none";
	document.getElementById("footageNumError").style.display = "none";
	document.getElementById("priceError").style.display = "none";
	document.getElementById("priceNumError").style.display = "none";
	
}

function ValidateDate(CtrlSDate,CtrlEDate)
    {
    var SDate = document.getElementById(CtrlSDate).value;    	
    var EDate =  document.getElementById(CtrlEDate).value;
    var CDate =  document.getElementById('curr_date').value;
                   
    a = SDate.split('-');
	b = EDate.split('-');
	c = CDate.split('-');
	
	var sDate = new Date(a[2],a[0]-1,a[1]);
	var eDate = new Date(b[2],b[0]-1,b[1]);
	var cDate = new Date(c[2],c[0]-1,c[1]);
	
	if(SDate == '')	
    {
        return "Lived from date required";
    }
	else if(EDate == '')	
    {
       return "Lived to date require";
    }
    else
    {
    	if(cDate < eDate)
    	{
    		return "Lived to date must be less than or equal to current date"; 
    	}
		if (sDate < eDate )
		{
			return "0"; 
		}
		else
		{
		   return "Lived to must be greater than lived from date";
		}
    }   	    
}
/**
* Fade out div temporary message 
* fadeOutElement(Div id)
* Syntax in HTML : <div id="abc"><span>thank you</span></div>
* Syntax in javascript function call : fadeOutElement("abc");
**/
function fadeOutElement(Elemnt){
 setTimeout(function(){
  $("#"+Elemnt+" span").fadeOut("slow", function () {
  $("#"+Elemnt+" span").remove();
      });    
}, 2000);
}
/**
*	used for featured listing on index page
*   Hide previous div and display next div
*/
function shohide_div(divID,count)
{
	//alert(divID);
	//alert(count);
	//alert(document.getElementById(divID));
	for (i=1; i<= count; i++) {
		if (i == divID) {
			divObj = document.getElementById(divID);
			divObj.style.display = "block";
		}
		else {
			divObj = document.getElementById(i);
			divObj.style.display = "none";
		}
	}
}
////////////////////////////// registration validation function end ////////////////////////
//////////// find div position on page /////////////////////////////

// copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
// you may copy these functions but please keep the copyright notice as well
function pageWidth() 
{
return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?  document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
} 
function pageHeight() 
{
return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
} 
function posLeft() 
{
return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
} 
function posTop() 
{
return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
} 
function posRight() 
{
return posLeft()+pageWidth();
} 
function posBottom() 
{
return posTop()+pageHeight();
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
 // return [ scrOfX, scrOfY ];
 return scrOfY;
}
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Robert Nyman | http://robertnyman.com/ */
function removeHTMLTags(HTMLdata){
 	//if(document.getElementById && document.getElementById("input-code")){
 	if(HTMLdata){
 		//var strInputCode = document.getElementById("input-code").innerHTML;
 		var strInputCode = HTMLdata;
 		/* 
  			This line is optional, it replaces escaped brackets with real ones, 
  			i.e. < is replaced with < and > is replaced with >
 		*/	
 	 	strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
 		 	return (p1 == "lt")? "<" : ">";
 		});
 		var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
 		//alert(strTagStrippedText);	
 		return strTagStrippedText;
   // Use the alert below if you want to show the input and the output text
   //		alert("Input code:\n" + strInputCode + "\n\nOutput text:\n" + strTagStrippedText);	
 	}	
}

////////////////////////////////////////////////////////////////////////////////

