	/**  Function	: LTrim(value)
	*    ---------------------------------------------------------------- 
	*    Name		:	LTrim
	*    Purpose    :	To get the trim values from the Ltrim function
	*    Arguments  :	value
	*    Return		:	Get the replace values
	*/ 

 //---added--by--Thalavai.D--29-09-08-To show the multiple selection list box process---/
function LTrim( value )
{
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

	/**  Function	: RTrim(value)
	*    ---------------------------------------------------------------- 
	*    Name		:	RTrim
	*    Purpose    :	To get the trim values from the Rtrim function
	*    Arguments  :	value
	*    Return		:	Get the replace values
	*/ 

 //---added--by--Thalavai.D--29-09-08-To show the multiple selection list box process---/
function RTrim( value )
{
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

	/**  Function	: str_trim(fld)
	*    ---------------------------------------------------------------- 
	*    Name		:	str_trim
	*    Purpose    :	To get the trim values from the str_trim function
	*    Arguments  :	fld
	*    Return		:	Get the replace values by DOM
	*/ 

 //---added--by--Thalavai.D--29-09-08-To show the multiple selection list box process---/
function str_trim( fld ) 
{
	vl=document.getElementById(fld).value;
	document.getElementById(fld).value=LTrim(RTrim(vl));
}

	/**  Function	: toupperfirst(str)
	*    ---------------------------------------------------------------- 
	*    Name		:	toupperfirst
	*    Purpose    :	To change the string first char is change to upper case and also remove the continious space
	*    Arguments  :	str
	*    Return		:	Get the result values
	*/ 

 //---added--by--Thalavai.D--29-09-08-To show the multiple selection list box process---/
function toupperfirst(str){ 
	var strval="";
	var space=0;
	for (i=0;i<str.length ;i++ ){
		//if(strval=="")
		if(i==0 && i==1)
			strval=str.charAt(i).toUpperCase();
		else{
			if(!(str.charAt(i)==' ' && str.charAt(i+1)==' '))
				strval=strval+str.charAt(i);
		}
	}
	return strval;
}

function validateOrg( strValue ) 
{
    var objRegExp;
    objRegExp  = /^[a-zA-Z0-9\@\s\/\_\-\.\,\&\(\)]+$/;
    return objRegExp.test(strValue);
}

function validateAlpha1( strValue ) {
    var objRegExp;
    objRegExp  = /^[a-zA-Z\s]+$/;
    return objRegExp.test(strValue);
}

function validateInteger1( strValue ) 
{
	var objRegExp;
    objRegExp  = /^[0-9]+$/;
    return objRegExp.test(strValue);
}

function onloadfunction(){
	document.referalform.txtName.focus();
}

function checkNumeric()
{

	if(event.keyCode<=45 || event.keyCode>57)
    {
		event.returnValue=false

		}
}

function post_value(d){
	
	var dt=new String(d);
	var d1=dt.split("?");
	var d2=d1[1];
		d2=d2.split("&");
	var d3=d2[0];
	var m1=d2[1];
	var y1=d2[2];

	var day=d3.split("=");
	var mon=m1.split("=");
	var year=y1.split("=");
		day=day[1];
		if(day<10) { day="0"+day; }
		mon=mon[1];
		if(mon<10) { mon="0"+mon; }
		year=year[1];

	opener.document.referalform.date2.value =day+"/"+mon+"/"+year;
	self.close();
}

	/**  Function	: submitcontact(operation)
	*    ---------------------------------------------------------------- 
	*    Name		:	submitcontact
	*    Purpose    :	To submit the form with checking of all mandatory fields
	*    Arguments  :	operation
	*    Return		:	Get the result values
	*/ 

 //---added--by--Thalavai.D--29-09-08-To show the multiple selection list box process---/
function submitcontact(operation)
{  
	var alertlist="";
	var fcs="";
	
	if(document.referalform.title.value=="" || document.referalform.title.value== '--Select--')
		{alertlist+="Please select \"Title\"\n";fcs+="-title";}

	if(!validateNotEmpty(document.referalform.fullname.value)){alertlist+="Please enter \"Full Name\"\n";fcs+="-fullname";}
	
	/*if(validateNotEmpty(document.referalform.fullname.value) && !validateAlpha1(document.referalform.fullname.value))
	{
		alert("Please enter valid full name")
		document.referalform.fullname.focus();
		return false;
	}*/
	
	for (var i=0; i<document.referalform.gender.length; i++) 
	{ 
		if (document.referalform.gender[i].checked) 
		{ 
			var gen=document.referalform.gender[i].value
		}
	}
	if(!gen){alertlist+="Please select \"Gender\"\n";fcs+="-radio_gen";}
	if(!validateNotEmpty(document.referalform.email.value)){alertlist+="Please enter \"E-mail ID\"\n";fcs+="-emailid";}
	
	if(validateNotEmpty(document.referalform.email.value) && !validateEmail(document.referalform.email.value))
	{
		alert("Please enter valid email id");
		document.referalform.email.focus();
		return false;
	}
	

  // Address Field Validation  added SrinivasMani  on 27 - Oct -2007 
   if(!validateNotEmpty(document.referalform.address1.value)){alertlist+="Please enter \"Address Line 1\"\n";fcs+="-address1";}
   if(validateNotEmpty(document.referalform.address1.value) && document.referalform.address1.value== 0)
	{
	  alert("Please enter valid address 1");
	  document.referalform.address1.focus();
	  return false;
	}
	if(document.referalform.address1.value!='')
	{
	if(!checkaddress(document.referalform.address1.value))
	{
	  alert("Please enter valid address 1");
	  document.referalform.address1.focus();
	  return false;
	}
	}
	else if(validateNotEmpty(document.referalform.address2.value) && document.referalform.address2.value== 0)
	{
	  alert("Please enter valid address 2");
	  document.referalform.address2.focus();
	  return false;
	} 
	if(document.referalform.address2.value!='')
	{
		if(!checkaddress(document.referalform.address2.value))
		{
		alert("Please enter valid address 2");
		document.referalform.address2.focus();
		return false;
		}
	}

	if(!validateNotEmpty(document.referalform.city.value)){alertlist+="Please enter \"City\"\n";fcs+="-city";}
	if(validateNotEmpty(document.referalform.city.value) && !validateAlphaSpaceCity(document.referalform.city.value))
	{
		alert("Please enter valid city")
		document.referalform.city.focus();
		return false;
	}

if(document.referalform.country.value=="" || document.referalform.country.value== '--Select--')
		{alertlist+="Please select \"Country\"\n";fcs+="-country";}
	var txtval=document.referalform.country.options[document.referalform.country.selectedIndex].text;
	if(txtval=="India")
	{
		if(document.getElementById("state").value=='--Select--'){alertlist+="Please select \"State\"\n";fcs+="-state";}
	}else if(txtval!="India")
	{
		if(!validateNotEmpty(document.getElementById("otherstate").value)){alertlist+="Please enter \"State\"\n";fcs+="-otherstate";}
		if(validateNotEmpty(document.getElementById("otherstate").value))
		{
			if(!validateAlphaSpaceCity(document.getElementById("otherstate").value) || document.getElementById("otherstate").value.length<2)
			{
				alert("Please enter valid state");
				document.getElementById("otherstate").focus();
				return false;
			}
		}
	}
//alert('stat '+document.referalform.state.value);
//if(document.referalform.state.value=="" || document.referalform.state.value== '--Select--')
//		{alertlist+="Please select \"State\"\n";fcs+="-state";}
	if(validateNotEmpty(document.referalform.zipcode.value))
	{

		if(document.referalform.zipcode.value==0 || document.referalform.zipcode.value.length<2)
		{
			alert("Please enter valid Postal Code");
			document.referalform.zipcode.focus();
			return false;
		}
	}
	
	if(!validateNotEmpty(document.referalform.zipcode.value)){alertlist+="Please enter \"Postal Code\"\n";fcs+="-zipcode";}
	if(validateNotEmpty(document.referalform.zipcode.value))
	{
		
			if(!validateInteger(document.referalform.zipcode.value) || document.referalform.zipcode.value==0)
			{
				alert("Please enter valid Postal Code");
				document.referalform.zipcode.focus();
				return false;
			}
	}

	if(validateNotEmpty(document.referalform.zipcode.value) && document.referalform.country.options[document.referalform.country.selectedIndex].text=="India")
		{

			if(document.referalform.zipcode.value.length==7 || document.referalform.zipcode.value.length<6 || document.referalform.zipcode.value.length>8)
			{
				alert("Please enter valid Postal Code");
				document.referalform.zipcode.focus();
				return false;
			}
		}

	if(!validateNotEmpty(document.referalform.phone.value)){alertlist+="Please enter \"Phone Number or Mobile Number\"\n";fcs+="-phone";}
	if(validateNotEmpty(document.referalform.phone.value) && validate_Phone_mobilenumber('phone','phone','yes','','')==false)
	{
		return false;
	}
	if(validate_Phonenumber('fax','fax','no','','')==false)
	{
		return false;
	}

	if(document.getElementById("termscond_y").checked==false)
	{
		alertlist+="Please agree \"Terms and Conditions\"\n";
		fcs+="-termscond_y";
	}
	if(alertlist!="")
	{
		alert(alertlist);
		fcs_splt=fcs.split("-");
		document.getElementById(fcs_splt[1]).focus();
		alertlist="";
		fcs="";
		return false;
	}

	document.referalform.operation.value=operation
	document.referalform.submit();
}

	/**  Function	: change_state(country_id)
	*    ---------------------------------------------------------------- 
	*    Name		:	change_state
	*    Purpose    :	To change the state by country selection based
	*    Arguments  :	country_id
	*    Return		:	Get the result values by DOM object
	*/ 

 //---added--by--Thalavai.D--29-09-08-To show the multiple selection list box process---/
function change_state(country_id)
{	
	var txtval=document.referalform.country.options[document.referalform.country.selectedIndex].text;
	if(txtval=="India")
	{
		document.getElementById("otherstate").value='';
		document.getElementById("state").value='--Select--';
		document.getElementById("otherstate").style.display='none';
		document.getElementById("state").style.display='inline';
		
	}else if(txtval!="India")
	{
		document.getElementById("otherstate").value='';
		document.getElementById("state").value='--Select--';
		document.getElementById("otherstate").style.display='inline';
		document.getElementById("state").style.display='none';
	}
}

	/**  Function	: createRequestObject1()
	*    ---------------------------------------------------------------- 
	*    Name		:	createRequestObject1
	*    Purpose    :	To create the ajax object initialization
	*    Arguments  :	-
	*    Return		:	Get the result values by DOM object
	*/ 

 //---added--by--Thalavai.D--29-09-08-To show the multiple selection list box process---/
function createRequestObject1() {
   var req;
   if(window.XMLHttpRequest){
      // Firefox, Safari, Opera...
      req = new XMLHttpRequest();
   } else if(window.ActiveXObject) {
	   
      // Internet Explorer 5+
      req = new ActiveXObject("Microsoft.XMLHTTP");
   } else {
      // There is an error creating the object, just as an old browser is being used.
      alert('Problem creating the XMLHttpRequest object');
   }
   return req;
}


	/**  Function	: loadmajax1(url,method,para,dv)
	*    ---------------------------------------------------------------- 
	*    Name		:	loadmajax1
	*    Purpose    :	To call the ajax functions 
	*    Arguments  :	url,method,para,dv
	*    Return		:	Get the result values by return
	*/ 

 //---added--by--Thalavai.D--29-09-08-To show the multiple selection list box process---/
var req = createRequestObject1();
var rfg;
function loadmajax1(url,method,para,dv){	
rfg=dv;
if(method=="GET"){
	if(para){
	para='?para='+para;
	}
  req.open(method,url+para);
  req.onreadystatechange = handleResponse1;
  req.send(null);
}
else
{
	if(para){
	para='para='+para;
	}
  req.open(method,url);
  req.onreadystatechange = handleResponse1;
  req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  req.send(para);
}


}
function handleResponse1(){
	
   if(req.readyState == 4 && req.status == 200){
      // Text returned FROM the PHP script
      var response = req.responseText;
	  
		if(response)
		{
			
			var response_splt=response.split("||");

			//  'If' condition and 'split' functionality added by Ganesan.D.16-05-2008- for call another js function after executing ajaxphp file. Used in 'Advertise Form'
			if(response_splt[1]!="" && response_splt[1]!=null)
			{
				
				var fnctn_splt=response_splt[1].split(",");
				var args="";
				var comma=",";
				for(i=0;i<=fnctn_splt.length-1;i++)
				{
					if(i==0)
					{
						fnctn=fnctn_splt[i];
					}
					if(i>0)
					{
						if(i==fnctn_splt.length-1)
						{
							comma="";
						}
						args=args+fnctn_splt[i]+comma;
					}
					
				}
				var t=setTimeout(""+fnctn+"("+args+");",10);
				document.getElementById(rfg).innerHTML = response_splt[0];
					
			}else if(response_splt[1]==null || response_splt[1]=="")
			{
			//alert(response);
			//alert(rfg);
				document.getElementById(rfg).innerHTML = response;
			
			}
			
		}
   }		

}
