// JavaScript Document
//Highlight form element- © Dynamic Drive (www.dynamicdrive.com)
//For full source code, 100's more DHTML scripts, and TOS,
//visit http://www.dynamicdrive.com
var highlightcolor="yellow"
var ns6=document.getElementById&&!document.all
var previous=''
var eventobj
//Regular expression to highlight only form elements
var intended=/INPUT|TEXTAREA|SELECT|OPTION/
//Function to check whether element clicked is form element
function checkel(which){
if (which.style&&intended.test(which.tagName)){
if (ns6&&eventobj.nodeType==3)
eventobj=eventobj.parentNode.parentNode
return true
}
else
return false
}

//Define Root Directory For Greybox

//var GB_ROOT_DIR = "http://dhakad/propertyagentsindia/greybox/";
var GB_ROOT_DIR = "http://www.propertyagentsindia.com/greybox/";

//Function to highlight form element
function highlight(e){
eventobj=ns6? e.target : event.srcElement
if (previous!=''){
if (checkel(previous))
previous.style.backgroundColor=''
previous=eventobj
if (checkel(eventobj))
eventobj.style.backgroundColor=highlightcolor
}
else{
if (checkel(eventobj))
eventobj.style.backgroundColor=highlightcolor
previous=eventobj
}
}
/////////////////
function isEmail(str)
{
	/*if(str=="")
	{
		//alert("Please Enter Email Address");
	}
	else
	{*/
		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 isValidNumber(ph)
{
	var phlen=ph.length;
	var phchar=ph.charAt(0);
	if (ph == "")
	{
		alert("Please Enter your Contact Number so that the concerned person can contact you");
		//document.getElementById("ph").focus();
		return false; 
	}
	else if (isNaN(ph))
	{
		alert("Contact number should be numeric");
		//document.getElementById("ph").focus();
		return false;
	}
	else if(phlen<10)
	{
		alert("Please enter correct number in 10 digits. If you are going to enter Landline No. then please add STD Code before no.(like : 731)");
		//document.getElementById("ph").focus();
		return false;
	} 
	else if(phchar=='0')
	{ 
		alert("Please do not add 0 before Number"); 
		//document.getElementById("ph").focus();
		return false;
	} 
	else
	{
	 	return true;
	}
}

function isValidLength(item, len, greaterorless)
  {
  	if (greaterorless = 1) 
	{
    	return (item.length >= len);
	}
	if (greaterorless = 2)
	{
		return (item.length <= len);
	}
	if (greaterorless = 3)
	{
		return (item.length == len);
	}
  }	
  
// Removes leading whitespaces
function LTrim( value ) 
{
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");	
	
}

// Removes ending whitespaces
function RTrim( value )
{
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) 
{
	//alert(value);
	return LTrim(RTrim(value));
	
}

function setListField(fieldId, fieldValue)
{
	//alert("test1 ");
	//alert(fieldId+"::"+fieldValue+"::"); 
	//alert(document.getElementById(fieldId).options);
	try
	{	
		if (fieldValue == "")
		{
			document.getElementById(fieldId).value = "";
		}
		for (i = 0; i < document.getElementById(fieldId).options.length;i++)
		{
			if (document.getElementById(fieldId).options[i].value == fieldValue)
			{
				document.getElementById(fieldId).options[i].selected = true;	
			}
		}
	}
	catch(exception)
	{
		alert(exception);
	}
}
function setMultipleList(fieldId, fieldValue)
{
	//alert(fieldId+"::"+fieldValue+"::");
	//alert(document.getElementById(fieldId).options);
	try
	{	
		if (fieldValue == "")
		{
			document.getElementById(fieldId).value = "";
		}
		//alert("Field Value: "+fieldValue);
		var values = fieldValue.split(",");
		//alert("VALUES: "+values+"::"+values.length);
		for (i = 0; i < values.length;i++)
		{
			var presentValue = values[i];
			//alert(i + "::" + presentValue);
			for (j = 0; j < document.getElementById(fieldId).options.length;j++)
			{
				if (document.getElementById(fieldId).options[j].value == presentValue)
				{
					document.getElementById(fieldId).options[j].selected = true;	
				}
			}
		}
	}
	catch(exception)
	{
		alert("error: "+exception);
	}
}


function validatetextarea(frm,field,cntfield,maxlimit) 
{
	//alert("cntfield==" + cntfield);
	//alert("field==" + field);
	//alert("maxlimit" + maxlimit);

	/////alert("Length" + field.value.length);
	if (field.value.length > maxlimit)
	{// if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	}
	// otherwise, update 'characters left' counter
	else if(cntfield!=null)
	{
		cntfield.value = maxlimit - field.value.length;
	}
	
}

function changeWindowStatus(text)
{
	window.status = text;
}


//////////////////////////////////////////////////////////////////////////////////////////////////
function showFormNew(which)
{
	//alert(which);
	if (which == "1") 
	{
		location.href = "reg_agent.php";
	}	
	else if (which == "2") 
	{
		location.href = "reg_coloniser.php";
	}
	else if (which == "3") 
	{
		location.href = "reg_corporates.php";
	}
	else if (which == "4") 
	{
		location.href = "reg_cust.php";
	}
	
}


function isValidCompanyName(cname)
{
	if (cname == "")
	{
		alert("Please Enter your Company Name");		
		return false; 
	}
	else
	{
	 	return true;
	}
}
function isValidName(name)
{
	if (name == "")
	{
		alert("Please Enter your Name");
		return false; 
	}
	else
	{
	 	return true;
	}
}

function isValidAddress(address)
{
	if (address == "")
	{
		alert("Please Enter your address");
		return false; 
	}
	else
	{
	 	return true;
	}
}

function isValidState(state)
{
	if (state == "")
	{
		alert("Please Enter your state name");
		return false; 
	}
	else
	{
	 	return true;
	}
}

function isValidCity(city)
{
	if (city == "")
	{
		alert("Please Enter your city name");
		return false; 
	}
	else
	{
	 	return true;
	}
}

function isValidZip(zip)
{
	if (zip == "")
	{
		alert("Please Enter zip code");
		return false; 
	}
	else
	{
	 	return true;
	}
}

////////////////////////////////////////////////////////////////////////////////////////////

function validateFields(opr)
{
	if(opr=='1' || opr=='3')
	{
		if(!isValidCompanyName(trim(document.getElementById("cname").value)))
		{
			document.getElementById("cname").focus();
			return false;
		} 
	}
	if(!isValidName(trim(document.getElementById("fname").value)))
	{
		document.getElementById("fname").focus();
		return false;
	} 
	if(!isValidAddress(trim(document.getElementById("address").value)))
	{
		document.getElementById("address").focus();
		return false;
	} 
	if(!isValidState(trim(document.getElementById("state").value)))
	{
		document.getElementById("statecombo").focus();
		return false;
	} 
	if(!isValidCity(trim(document.getElementById("city").value)))
	{
		document.getElementById("citycombo").focus();
		return false;
	} 
	if(!isValidZip(trim(document.getElementById("zip").value)))
	{
		document.getElementById("zip").focus();
		return false;
	} 
	if(!isEmail(trim(document.getElementById("email").value)))
	{
		alert("Please enter Correct Email address for exp:-abc@yahoo.com");
		document.getElementById("email").focus();
		return false;
	} 
	if(!isValidNumber(trim(document.getElementById("mobile").value)))
	{
		document.getElementById("mobile").focus();
		return false;
	}  
}
//alert('testing'); 
function ValidateEnquiry()
{
	if (trim(document.getElementById("fname").value) == "")
	{
		alert("Please Enter your name");
		document.getElementById("fname").focus();
		return false;
	}	
	if (!isValidNumber(trim(document.getElementById("phno").value)))
	{
		document.getElementById("phno").focus();
		return false;
	}
	if (!isEmail(trim(document.getElementById("email").value)))
	{
		alert("Please enter a valid email address");
		document.getElementById("email").focus();
		return false;
	}	
	if (trim(document.getElementById("state").value) == "")
	{
		alert("Please enter state name");
		document.getElementById("state").focus();
		return false;
	}	
	if (trim(document.getElementById("city").value) == "")
	{
		alert("Please enter city name");
		document.getElementById("city").focus();
		return false;
	}
	if(trim(document.getElementById("message").value) == "")
	{  
		alert("Enter the Enquiry Details");
		document.getElementById("message").focus();
		return false;
	}
	else
	{
		if(trim(document.getElementById("message").value).length < 20)
		{
			alert("The Enquiry Details are too short for the concerned person to understand. Please Enter your enquiry correctly");
			document.getElementById("message").focus();
			return false;			
		}
	}
	return true;
}

