

/***************************  Validation for Phone Number******************/
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()-./ ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 7;
var maxDigitsInIPhoneNumber = 12;

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 trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
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++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && (strPhone.indexOf(")")==-1 || strPhone.indexOf(")") < brchr+2))return false
//if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber && s.length <= maxDigitsInIPhoneNumber);
}




/* check for pin/zip code */
function zip(s)
{
var s=trim(s);
return (isInteger(s) && (s.length == 5 || s.length == 8));
}


/*Validation for price,Bedroom/Bathroom & Square feet  *************/


function numbercheck(field) { 
        var pattern = /^[1-9][0-9,]*$/; 
        if (!pattern.test(field.value)) { 
            alert('Enter Only numeric value' + '\n' + 'Value format:- 1234'); 
			document.form1.sf.value="";
			document.form1.sf.focus();
			            
        } 
    }

function bedbath(field) { 
        var pattern = /^[1-9][,][1-9]$/; 
        if (!pattern.test(field.value)) { 
            alert('Enter value in correct format' + '\n' + 'Value format(BR/BA):- 2,3'); 
			document.form1.br_ba.value="";
			document.form1.br_ba.focus();
			            
        } 
    }
	function pricecheck(field) { 
        var pattern = /^\$[1-9][0-9,]*$/; 
        if (!pattern.test(field.value)) { 
            alert('Enter value in correct format' + '\n' + 'Value format:- $1234'); 
			document.form1.price.value="$";
			document.form1.price.focus();
			
			            
        } 
    }
	
	/*******************************  Checklist Guide popup window open  ******************************/
	
		/*******************************  Email Validation Start ***********************************************/
	function email(str)
	{
	var emailfilter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (!emailfilter.test(str)) 
		{
		return false;
		}
	return str;
	}
	
	
	/*******************************  Email Validation End  ***********************************************/

	
	
	 var win=null;
function openWin(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);
}

/***************************************************   Email friend link  ************************/
function emailfrnd(lid)
{
var u="emailfriend.php?lid=" + lid;
emailfrndwindow =  window.open (u,"emailfrndwindow","status=0,toolbar=0, directories=no, location=no, width=550,height=400,left=200,top=150");
//exit;
}
