// JavaScript Document
//=============== isDate ========================

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 TrimString(sInString) {
	var re = /\s/g; //Match any white space including space, tab, form-feed, etc.
	return str = sInString.replace(re, "");
	
    }

	function isAlphabetic(val)
	{

		val = TrimString(val)
		if(val != "")
		{
		if (val.match(/^[a-zA-Z]+$/))
		{
			return true;
		}
		else
		{
			return false;
		}
		}
		else 
			return true;
	}
	function check_it(theurl)
	{
		if(theurl != "")
		{
		 var tomatch= /[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
		 if (tomatch.test(theurl))
		 {
		 return true;
		 }
		 else
		 {
		 window.alert("Please enter valid url of web site !");
		 return false; 
		 }
		}
		else 
			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
	}


	//========================== email validation function =============================
	function isEmail(fieldObj)
	{
		var str = fieldObj.value;
		var re = /^([a-zA-Z0-9-_\.]+@([a-zA-Z0-9-_]+\.)+[a-zA-Z]{2,4})$/;
		if (re.test(str)) {
			return true;
		} else {				
			return false;
		}
	
	}
	function isEmailValid(str)
	{
		var re = /^([a-zA-Z0-9-_\.]+@([a-zA-Z0-9-_]+\.)+[a-zA-Z]{2,4})$/;
		if (re.test(str)) {	
			return true; 
		} else {				
			return false;
		}
	}

//------------- us phone no check

	function validPhoneUS(fieldObj)
	{
		var str = fieldObj.value;
		re = /^\(?\d{3}\)?\s|-\d{3}-\d{4}$/;
		if (re.test(str)) {
			return true;
		} else {
			return false;
		}
	}
	function isPhoneNumber(str){
	  var stripped = str.replace('-', '');
	  	  stripped = stripped.replace('-', '');
		//strip out acceptable non-numeric characters
		if (isNaN(parseInt(stripped))) {
		  return false;
		} else if (stripped.length != 10) {
			return false;
		}
		return true;
	}
	
	function validPhone(mixnumber)
	{
		var str = mixnumber;
		if (str.length <= 0)
		{ return false }
		var i;
		for (i = 0; i < str.length; i++){   
		// Check that current character is number.
		var c = str.charAt(i);
		if (((c < 0) || (c > 9))) return false; //  && c!="-" removed
		}
		// All characters are numbers.
		return true;
	}
	function validCreditCard(mixnumber)
	{
		var str = mixnumber;
		var i;
		for (i = 0; i < str.length; i++){   
		// Check that current character is number.
		var c = str.charAt(i);
		if (((c < 0) || (c > 17))) return false; //  && c!="-" removed
		}
		// All characters are numbers.
		return true;
	}

	//------------- zip check
	function validZip(fieldObj)
	{
		var str = fieldObj.value;
		var re = /\d{5}(-\d{4})?/;
		if (!isNaN(str)===false) {
			return false;
		} else if (str.length <=3 || str.length >=6) {
			return false;
		} else {			
			return true;
		}	
	}

//==============  CC Checks ====================================

	function isVisa( cc )
	{
		if( (cc.substring(0,1) == 4) && (cc.length == 16) || (cc.length == 13) ) {
			return true; // isCreditCard( cc );
		}
		return (false);
	}
		
	function isMC( cc )
	{
		if( (cc.length == 16) && (cc.substring(0,2) == 51) || (cc.substring(0,2) == 52) || (cc.substring(0,2) == 53) || (cc.substring(0,2) == 54) || (cc.substring(0,2) == 55) ) {
			return true;//isCreditCard( cc );
		}
		return (false);
	}

	function isAmex( cc )
	{
		if( (cc.length == 15) && (cc.substring(0,2) == 34) || (cc.substring(0,2) == 37) ) {
			return true;//isCreditCard( cc );
		}
		return (false);
	}


	function isDiscover( cc ) {
		if( (cc.length == 16) && (cc.substring(0,4) == 6011) )
		{
			return true;//isCreditCard( cc );
		}
			return (false);
	}
	
	function showDOM()
	{
		for (it in document)
		{
		alert(it);
		}
	}

	function getFileSize(obj)
	{	
		var oas = new ActiveXObject("Scripting.FileSystemObject");
		var e = oas.getFile(obj.value);
		var f = e.size;
		return f;
	}



/****************************************************************/
/****************************************************************/

function backtoEdit()
{
	location.href = "agent_registration.php?action=ch_info";
}


// whitespace characters
var whitespace = " \t\n\r";


// Check whether string s is empty.
function isEmpty(s)
{ return ((s == null) || (s.length == 0)) }



function isWhitespace (s)
{
var i;

// Is s empty?
if (isEmpty(s)) return true;

// Search through string's characters one by one
// until we find a non-whitespace character.
// When we do, return false; if we don't, return true.

for (i = 0; i < s.length; i++)
{
// Check that current character isn't whitespace.
var c = s.charAt(i);

if (whitespace.indexOf(c) == -1) return false;
}

// All characters are whitespace.
return true;
}

/****************************************************************/

function ForceEntry(val, str) {
var strInput = new String(val.value);

if (isWhitespace(strInput)) {
alert(str);
return false;
} else
return true;

}

/****************************************************************/

function ValidateRanking() {
// This function ensures document.forms[0].nRanking.value >=1 && <= 10

if (parseInt(document.forms[0].nRanking.value) >= 1 && parseInt(document.forms[0].nRanking.value) <=10)
return true;
else
return false;
}

/****************************************************************/

function ValidateData() {
var CanSubmit = false;

// Check to make sure that the full name field is not empty.
CanSubmit = ForceEntry(document.forms[0].txtName,"You supply a full name.");

// Check to make sure ranking is between 1 and 10
if (CanSumbit) CanSubmit = ValidRanking();

return CanSubmit;
}
function isLeadingWhitespace (s)
{

// Is s empty?
if (isEmpty(s)) return true;

// Search through string's characters one by one
// until we find a non-whitespace character.
// When we do, return false; if we don't, return true.
var c = s.charAt(0);
if (c == ' ') return true;           

// All characters are whitespace.
return false;
}

function confirmation(msg) {
	if (confirm(msg)===false) {
		return false;
	}
}

function toEditPage()
{
	location.href = "edit_profile.php";
}
function ChangePass()
{
	location.href = "change_pass.php";
}
function EnterLicenceNum(choice)
{
	if(choice == '0')
	{		
		document.frmReg.estate_licence_number.value = "";

		document.frmReg.estate_licence_number.disabled = true;
	}
	else if(choice == '1')
	{
		document.frmReg.estate_licence_number.disabled = false;
	}
	
}
function EditLicenceNum(choice)
{
	if(choice == '0')
	{		
		document.frmProfile.estate_licence_number.value = "";

		document.frmProfile.estate_licence_number.disabled = true;
	}
	else if(choice == '1')
	{
		document.frmProfile.estate_licence_number.disabled = false;
	}
}
function FileUploadValid(field,msg) 
{
	var msg="";
if(field.value != '')
	{
if((field.value.lastIndexOf(".jpg")==-1) && (field.value.lastIndexOf(".JPG")==-1) && (field.value.lastIndexOf(".jpeg")==-1) && (field.value.lastIndexOf(".JPEG")==-1) && (field.value.lastIndexOf(".png")==-1) && (field.value.lastIndexOf(".PNG")==-1) && (field.value.lastIndexOf(".gif")==-1) && (field.value.lastIndexOf(".GIF")==-1))
	{
   alert('Please upload jpg/jgeg, gif or png file only.	');
   field.select();
   return false;
	}
	}
	return true;
}
// FUNCTION TO CHANGE THE CURRENCY ON CLICK OF RADIO
function change_currency(frm, actionURL)
{
	frm.action = actionURL;
	frm.submit();
}