// Market validation code start Here - Bakkiyaraj//
//-----------------------------------------------//
// code start Here //

var curDomain = document.domain;

function ShowHidden() {
	document.getElementById("rest1").style.display = "none";
	document.getElementById("feedresult").style.display = "block";
	document.getElementById("feedresult").innerHTML = '<div><div style="float:left;width:140px;"><img src="http://imgs.bharatmatrimony.com/bmimages/small_loading.gif" border="0" alt="" ></font></div>';
}

function ShowHiddenPartner() {
	document.getElementById("rest2").style.display = "none";
	document.getElementById("feedresult1").style.display = "block";
	document.getElementById("feedresult1").innerHTML = '<div><div style="float:left;width:140px;"><img src="http://imgs.bharatmatrimony.com/bmimages/small_loading.gif" border="0" alt="" ></font></div>';

}

function ValidateNo( NumStr, String )
{
	for( var Idx = 0; Idx < NumStr.length; Idx ++ )
	{
		 var Char = NumStr.charAt( Idx );
		 var Match = false;

		for( var Idx1 = 0; Idx1 < String.length; Idx1 ++)
		{
		 if( Char == String.charAt( Idx1 ) )
		 Match = true;
		}

		if ( !Match )
		return false;
 	}
   	return true;
}

function ValidateEmail( Email ){
	var atCharPresent = false;
	var dotPresent = false;
	var filter=/^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;														

	if (filter.test(Email)){
		atCharPresent = true;
		dotPresent = true;
		}
	else {
		return false;
	}
		return true;
	}


/// for partner with us//

function validateqry1(){
	
	var BussiMatriForm = this.document.BussiMatriForm1;
	
	if(IsEmpty(BussiMatriForm.YOURNAME1,"text"))
	{
	document.getElementById('namespan1').innerHTML="Enter the Name";
	BussiMatriForm.YOURNAME1.value="";
	BussiMatriForm.YOURNAME1.focus();
	return false;
	}
	if(IsEmpty(BussiMatriForm.COMPANYNAME1,"text"))
	{
	document.getElementById('company1').innerHTML = "Enter the Company Name";
	BussiMatriForm.COMPANYNAME1.value="";
	BussiMatriForm.COMPANYNAME1.focus();
	return false;
	}
	if(IsEmpty(BussiMatriForm.BUSINESSNATURE1,"text"))
	{
	document.getElementById('business1').innerHTML = "Enter Business Nature";
	BussiMatriForm.BUSINESSNATURE1.value="";
	BussiMatriForm.BUSINESSNATURE1.focus();
	return false;
	}
	if(IsEmpty(BussiMatriForm.CONTACTPHONE1,"text"))
	{
	document.getElementById('contactph1').innerHTML = "Enter Contact phone.";
	BussiMatriForm.CONTACTPHONE1.value=""; 
	BussiMatriForm.CONTACTPHONE1.focus();
	return false;
	}
	if(IsEmpty(BussiMatriForm.CONTACTADDRESS1,"text"))
	{
	document.getElementById('contactadd1').innerHTML = "Enter Email Id";
	BussiMatriForm.CONTACTADDRESS1.value="";
	BussiMatriForm.CONTACTADDRESS1.focus();
	return false;
	}
	if(BussiMatriForm.CONTACTADDRESS1.value != ""){
	  var emailvalue = TrimEmail(BussiMatriForm.CONTACTADDRESS1.value);
	   var emailalert = chkEmail(emailvalue);	
	   if(emailalert == false){
		   document.getElementById("contactadd1").innerHTML = "Enter Valid Email Id";
			BussiMatriForm.CONTACTADDRESS1.value="";
			BussiMatriForm.CONTACTADDRESS1.focus();
		   return false;
	   }     
	}

	if(IsEmpty(BussiMatriForm.COMMENTS1,"text"))
	{
	document.getElementById('comment1').innerHTML = "Enter Contact Address";
	BussiMatriForm.COMMENTS1.value="";
	BussiMatriForm.COMMENTS1.focus();
	return false;
	}
	if(IsEmpty(BussiMatriForm.QUERY1,"text"))
	{
	document.getElementById('details1').innerHTML = "Details / queries about Partnership.";
	BussiMatriForm.QUERY1.value="";
	BussiMatriForm.QUERY1.focus();
	return false;
	}
  
	var Name = BussiMatriForm.YOURNAME1.value;
	var companyname = BussiMatriForm.COMPANYNAME1.value;
	var business = BussiMatriForm.BUSINESSNATURE1.value;
	var contact = BussiMatriForm.CONTACTPHONE1.value;
	var comment = BussiMatriForm.COMMENTS1.value;
	var conaddress = BussiMatriForm.CONTACTADDRESS1.value;
	var details = BussiMatriForm.QUERY1.value;
	ShowHiddenPartner();
	var parameters = "Name="+Name+"&companyname="+companyname+"&business="+business+"&comment="+comment+"&contact="+contact+"&conaddress="+conaddress+"&details="+details;
	//var url = "http://"+curDomain+"/contactpage/mailsend.php";
	MakePostRequest('http://'+curDomain+'/contactpage/mailsend.php',parameters,dispmessage1);
	return true;
}




//for associates
function validateqry(){
	
	var BussiMatriForm = this.document.BussiMatriForm;
	if(IsEmpty(document.BussiMatriForm.YOURNAME,"text"))
	{
	document.getElementById('namespan').innerHTML="Enter the Name";
	BussiMatriForm.YOURNAME.value="";
	BussiMatriForm.YOURNAME.focus();
	return false;
	}
	if(IsEmpty(document.BussiMatriForm.COMPANYNAME,"text"))
	{
	document.getElementById('company').innerHTML = "Enter the Company Name";
	BussiMatriForm.COMPANYNAME.value="";
	BussiMatriForm.COMPANYNAME.focus();
	return false;
	}
	if(IsEmpty(document.BussiMatriForm.BUSINESSNATURE,"text"))
	{
	document.getElementById('business').innerHTML = "Enter Business Nature";
	BussiMatriForm.BUSINESSNATURE.value="";
	BussiMatriForm.BUSINESSNATURE.focus();
	return false;
	}
	if(IsEmpty(document.BussiMatriForm.CONTACTPHONE,"text"))
	{
	document.getElementById('contactph').innerHTML = "Enter Contact phone.";
	BussiMatriForm.CONTACTPHONE.value=""; 
	BussiMatriForm.CONTACTPHONE.focus();
	return false;
	}
	if(IsEmpty(document.BussiMatriForm.CONTACTADDRESS,"text"))
	{
	document.getElementById('contactadd').innerHTML = "Enter Email Id";
	BussiMatriForm.CONTACTADDRESS.value="";
	BussiMatriForm.CONTACTADDRESS.focus();
	return false;
	}
	var Email = document.BussiMatriForm.CONTACTADDRESS.value;
	if(!ValidateEmail( Email )){
	
		document.getElementById('contactadd').innerHTML = "Enter Valid Email Id";
		BussiMatriForm.CONTACTADDRESS.value="";
		BussiMatriForm.CONTACTADDRESS.focus();
		return true;
	}
	if(IsEmpty(document.BussiMatriForm.COMMENTS,"text"))
	{
	document.getElementById('comment').innerHTML = "Enter Comments";
	BussiMatriForm.COMMENTS.value="";
	BussiMatriForm.COMMENTS.focus();
	return false;
	}
	if(IsEmpty(document.BussiMatriForm.QUERY,"text"))
	{
	document.getElementById('details').innerHTML = "Details / queries about Partnership.";
	BussiMatriForm.QUERY.value="";
	BussiMatriForm.QUERY.focus();
	return false;
	}
	var Name = document.BussiMatriForm.YOURNAME.value;
	var companyname = document.BussiMatriForm.COMPANYNAME.value;
	var business = document.BussiMatriForm.BUSINESSNATURE.value;
	var contact = document.BussiMatriForm.CONTACTPHONE.value;
	var comment = document.BussiMatriForm.COMMENTS.value;
	var conaddress = document.BussiMatriForm.CONTACTADDRESS.value;
	var details = document.BussiMatriForm.QUERY.value;

	var parameters = "Name="+Name+"&companyname="+companyname+"&business="+business+"&contact="+comment+"&contact="+contact+"&conaddress="+conaddress+"&details="+details;
	//var url = "http://"+curDomain+"/contactpage/mailsend.php";
	MakePostRequest('http://'+curDomain+'/contactpage/mailsend.php',parameters,dispmessage);
	return true;
}

function dispmessage1(){
		if(ajobj.readyState == 4) {				
		
		if(ajobj.status == 200){	
			
				 
			    document.getElementById("feedresult1").style.display="block";
				document.getElementById("feedresult1").innerHTML = ajobj.responseText;
				document.getElementById("rest2").style.display="none";
 			 }
			else {
					document.getElementById("sectab_content_4").innerHTML = 'There was a problem with the request';
				}
			}
	}


function dispmessage(){
		if(ajobj.readyState == 4) {
			if(ajobj.status == 200){
			    document.getElementById("businessresp").style.display="block";
				document.getElementById("sectab_content_3").style.display="none";
				document.getElementById("businessresp").innerHTML = ajobj.responseText;
			 }
			else {
					document.getElementById("sectab_content_3").innerHTML = 'There was a problem with the request';
				}
			}
	}
function buss_respdisplay(){
	 document.getElementById("feedresult").style.display="none";
	 document.getElementById("custfeedback").style.display="block";
 	 document.getElementById("partners").style.display="none";
 	 document.getElementById("rest1").style.display="block";
	 //document.getElementById("feedres").style.display="none";
}
function businessclearall(){
	 	document.BussiMatriForm.YOURNAME.value = "";
		document.BussiMatriForm.COMPANYNAME.value = "";
		document.BussiMatriForm.BUSINESSNATURE.value = "";
		document.BussiMatriForm.CONTACTPHONE.value = "";
		document.BussiMatriForm.COMMENTS.value = "";
		document.BussiMatriForm.CONTACTADDRESS.value = "";
		document.BussiMatriForm.QUERY.value = "";
		document.getElementById('namespan').innerHTML='';
		document.getElementById('company').innerHTML='';
		document.getElementById('business').innerHTML='';
		document.getElementById('contactph').innerHTML='';
		document.getElementById('contactadd').innerHTML='';
		document.getElementById('comment').innerHTML='';
		document.getElementById('details').innerHTML='';
		document.getElementById('businessresp').innerHTML='';
		//document.getElementById('feedres').innerHTML='';
 }


//------------------ End Here ------------------- //

//Feed back validation Start Here - Padma Latha//

//-------------------------- Code Start Here ------------------//


function validate_feedback()
{ 
  if(document.feedbackform.fbName.value == ""){
	 document.getElementById("name").innerHTML = "Enter your name";
	 document.feedbackform.fbName.value = "";
	 document.feedbackform.fbName.focus();
     return false;
	}
	if(document.feedbackform.fbEmail.value == ""){
	 document.getElementById("email").innerHTML = "Enter your e-mail ID";
	 document.feedbackform.fbEmail.value = "";
	 document.feedbackform.fbEmail.focus();
     return false;
	}
	if(document.feedbackform.fbEmail.value != ""){
		var emailvalue = TrimEmail(document.feedbackform.fbEmail.value);
	   var emailalert = chkEmail(emailvalue);	
	   if(emailalert == false){
		   document.getElementById("email").innerHTML = "Invalid e-mail ID";
		   document.feedbackform.fbEmail.focus();
		   return false;
	   }     
	}
    if(document.feedbackform.fbFeedback.value == "")
	{
	 document.getElementById("feedback").innerHTML = "Enter your suggestions or feedback";
	 document.getElementById("email").innerHTML = "";
	 document.feedbackform.fbFeedback.focus();
     return false;
	}
	var fbFeedback = document.feedbackform.fbFeedback.value;
	var fbEmail = document.feedbackform.fbEmail.value;
	var fbName = document.feedbackform.fbName.value;
	var fbPhone = document.feedbackform.fbPhone.value;
	var fbEnv = document.feedbackform.fbEnv.value;
	ShowHidden();
	var params = "fbFeedback="+escape(fbFeedback)+"&fbEmail="+fbEmail+"&fbName="+fbName+"&fbPhone="+fbPhone+"&fbEnv="+fbEnv+"&rand="+genNumbers();
	MakePostRequest('http://'+curDomain+'/contactpage/contactprocess.php',params,responseFeedback);
//fade(maindivfb,'fadediv','dispdiv','450','feedbackform','feedback.js','http://'+curDomain+'/contactpage/contactprocess.php?rand='+genNumbers(),'','dispcontent','','refreshDivfb');
		
}

function chkEmail(field)
	{
	var emailPat = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
	var matchArray = field.match(emailPat);
	if(!emailPat.test(field)){
		//alert("Your email address is invalid.  Please try again !!");
  		return false;
		}
		
	}
function responseFeedback()
{
	if(ajobj.readyState == 4) {
		if(ajobj.status == 200) {
			document.getElementById("feedresult").style.display="block";
			//document.getElementById("feedres").style.display = "none";
			// document.getElementById("feedresult").innerHTML = ajobj.responseText;
			document.getElementById("feedresult").innerHTML = ajobj.responseText;
				document.getElementById("rest1").style.display="none";
		  } 
		else {
			document.getElementById("sectab_content_4").innerHTML = 'There was a problem with the request';
		}
	}
}


function clearfeedbackall(){
		document.feedbackform.fbName.value ="";
		document.feedbackform.fbEmail.value="";
		document.feedbackform.fbFeedback.value="";
		document.feedbackform.fbPhone.value = "";
		document.feedbackform.fbEnv.value = "";
		document.getElementById('name').innerHTML='';

		document.getElementById('email').innerHTML='';
		document.getElementById('feedback').innerHTML='';

		//document.getElementById('feedres').innerHTML='';
		/* Start For Partner with us*/
		document.BussiMatriForm1.QueryType1.value = "";
	 	document.BussiMatriForm1.YOURNAME1.value = "";
		document.BussiMatriForm1.COMPANYNAME1.value = "";
		document.BussiMatriForm1.BUSINESSNATURE1.value = "";
		document.BussiMatriForm1.CONTACTPHONE1.value = "";
		document.BussiMatriForm1.COMMENTS1.value = "";
		document.BussiMatriForm1.CONTACTADDRESS1.value = "";
		document.BussiMatriForm1.QUERY1.value = "";

		document.getElementById('QueryTypespan1').innerHTML='';
		document.getElementById('namespan1').innerHTML='';
		document.getElementById('company1').innerHTML='';
		document.getElementById('business1').innerHTML='';
		document.getElementById('contactph1').innerHTML='';
		document.getElementById('contactadd1').innerHTML='';
		document.getElementById('comment1').innerHTML='';
		document.getElementById('details1').innerHTML='';

		/* Start For Partner with us */
}

function TrimEmail(str)
{  while(str.charAt(0) == (" ") )
  {  str = str.substring(1);
  }
  while(str.charAt(str.length-1) == " " )
  {  str = str.substring(0,str.length-1);
  }
  return str;
}