function setDisplay()
{   var fld=document.registration.noofSubagents;
    if(fld.value==0)
    {  
    document.getElementById("contactPerson2").style.display ="block";
	document.registration.noofSubagents.value=1;
	document.registration.addSubagents.disabled=false;
	document.registration.removeSubagents.disabled=false;
	
    }
    else if(fld.value==1)
    {   
    document.getElementById("contactPerson3").style.display ="block"
	document.registration.noofSubagents.value=2;
	document.registration.addSubagents.disabled=true;
	document.registration.removeSubagents.disabled=false;
    }
    
}
function removeDisplay()
{
     if(document.registration.noofSubagents.value==1)
     {   
      document.getElementById("contactPerson2").style.display = "none"
	  document.registration.noofSubagents.value=0;
	  document.registration.addSubagents.disabled=false;
	  document.registration.removeSubagents.disabled=true;
     }
     else if(document.registration.noofSubagents.value==2)
     {   
      document.getElementById("contactPerson3").style.display = "none"
	  document.registration.noofSubagents.value=1;
	  document.registration.addSubagents.disabled=false;
	  document.registration.removeSubagents.disabled=false;
     }
		
}

function reset()
{ 
 document.registration.reset();
 document.registration.noofSubagents.value=0;
 document.getElementById("contactPerson2").style.display = "none"
 document.getElementById("contactPerson3").style.display = "none"
 document.registration.addSubagents.disabled=false;
 document.registration.removeSubagents.disabled=true;

}
function contactDetailsOpen()
{if(document.getElementById("contactDetails").style.display == "block")
{	
 document.getElementById("contactDetails").style.display = "none"
 document.getElementById("contactDetailsimage").src=rootpath+"/images/plus.gif"	 
}
else if(document.getElementById("contactDetails").style.display == "none")
{	
 document.getElementById("contactDetails").style.display = "block"
 document.getElementById("contactDetailsimage").src=rootpath+"/images/clseimg.gif"	 
}

}
function contactPersonDetailsOpen()
{
	if(document.getElementById("contactPersonDetails").style.display == "block")
	{	
	 document.getElementById("contactPersonDetails").style.display = "none"
     document.getElementById("contactPersonDetailsimage").src=rootpath+"/images/plus.gif"	 
	}
	else if(document.getElementById("contactPersonDetails").style.display == "none")
	{	
	 document.getElementById("contactPersonDetails").style.display = "block"
	 document.getElementById("contactPersonDetailsimage").src=rootpath+"/images/clseimg.gif"	
	}	
}

String.prototype.trim = function()
{
  return this.replace(/^\s+|\s+$/g,"");
 }

function validateFormOnSubmit(theForm) {
var reason = "";
var reason1;

reason +=reason1= validatenameOftheOrganization(theForm.nameOftheOrganization);
document.getElementById('nameOftheOrganizationSpan').innerHTML = reason1;
reason +=reason1= validatesizeOfAgency(theForm.sizeOfAgency);
document.getElementById('sizeOfAgencySpan').innerHTML = reason1;
reason +=reason1= validateurl(theForm.url);
document.getElementById('urlSpan').innerHTML = reason1;
reason +=reason1= validatephone1(theForm.phone1);
document.getElementById('phone1Span').innerHTML = reason1;
reason +=reason1= validatephone2(theForm.phone2);
document.getElementById('phone2Span').innerHTML = reason1;
reason +=reason1= validatefax(theForm.fax);
document.getElementById('faxSpan').innerHTML = reason1;
reason +=reason1= validateaddress(theForm.address);
document.getElementById('addressSpan').innerHTML = reason1;
reason +=reason1= validatecountry(theForm.country);
document.getElementById('countrySpan').innerHTML = reason1;
reason +=reason1= validateapproxVolumetoIndia(theForm.approxVolumetoIndia);
document.getElementById('approxVolumetoIndiaSpan').innerHTML = reason1;
reason +=reason1= validateapproxTurnoverFortheLastFinancialYear(theForm.approxTurnoverFortheLastFinancialYear);
document.getElementById('approxTurnoverFortheLastFinancialYearSpan').innerHTML = reason1;
reason +=reason1= validationaccreditation3(theForm.accreditation3);
document.getElementById('accreditation3Span').innerHTML = reason1;
reason +=reason1=validationcontactPersonName1(theForm.contactPersonName1);
//contactperson1=primaryagent validation
document.getElementById('contactPersonName1Span').innerHTML = reason1;
reason +=reason1=validationcontactPersonEmail1(theForm.contactPersonEmail1);
document.getElementById('contactPersonEmail1Span').innerHTML = reason1;
reason +=reason1=validationcontactPersonDesignation1(theForm.contactPersonDesignation1);
document.getElementById('contactPersonDesignation1Span').innerHTML = reason1;

//subagents validation
if(theForm.noofSubagents.value==1 || theForm.noofSubagents.value==2)
{	
reason +=reason1=validationcontactPersonName2(theForm.contactPersonName2);
document.getElementById('contactPersonName2Span').innerHTML = reason1;
reason +=reason1=validationcontactPersonEmail2(theForm.contactPersonEmail2);
document.getElementById('contactPersonEmail2Span').innerHTML = reason1;
reason +=reason1=validationcontactPersonDesignation2(theForm.contactPersonDesignation2);
document.getElementById('contactPersonDesignation2Span').innerHTML = reason1;

}
if (theForm.noofSubagents.value==2)
{ 
 reason +=reason1=validationcontactPersonName3(theForm.contactPersonName3);
 document.getElementById('contactPersonName3Span').innerHTML = reason1;
 reason +=reason1=validationcontactPersonEmail3(theForm.contactPersonEmail3);
 document.getElementById('contactPersonEmail3Span').innerHTML = reason1;
 reason +=reason1=validationcontactPersonDesignation3(theForm.contactPersonDesignation3);
 document.getElementById('contactPersonDesignation3Span').innerHTML = reason1;
	  
}
  	  
if (reason != "") {
  alert("Some fields need correction.");
  //contactDetailsOpen();
 // contactPersonDetailsOpen();
  return false;
}

return true;
}
function validatenameOftheOrganization(fld) {
  var error = "";
  if (fld.value == "" || fld.value == null) {
      fld.style.background = 'Yellow'; 
      error = "You didn't enter Name of the Organization.\n";
  } 
	else if (fld.value.trim().length==0)
	{  fld.style.background = 'Yellow'; 
     error = "You didn't enter Name of the Organization.\n";
	}
	else if ((fld.value.trim().length >50)) {
      fld.style.background = 'Yellow'; 
      error = "The Name of the Organization can have maximum 50 characters.\n";
  } 
	else {
      fld.style.background = 'White';
  }
  return error;
}
function validatesizeOfAgency(fld){
var error = "";
var allowedChars = /^[\d]+$/;
if (fld.value == "" || fld.value == null) {
      fld.style.background = 'Yellow'; 
      error = "You didn't enter Agency Size.\n";
  }
else if(fld.value.trim().length==0)
{ fld.style.background = 'Yellow'; 
  error = "You didn't enter Agency Size.\n";
}
else if (!allowedChars.test(fld.value.trim()))
	{  fld.style.background = 'Yellow'; 
     error = "The Agency Size must be numeric.\n";
	}
else if (fld.value.trim()>2147483647)
{  fld.style.background = 'Yellow'; 
 error = "The Agency Size must be less than or equal to 2147483647.\n";
}
else {
      fld.style.background = 'White';
  }
  return error;

}
function validateurl(fld){
var error = "";
var allowedChars = /^(((ht|f){1}(tp:[/][/]){1})|((www\.){1}))[-a-zA-Z0-9@:%_\+\.~#\?&/=]+$/;
if (fld.value != "" && fld.value != null) {
   if (fld.value.trim().length!=0 && !allowedChars.test(fld.value.trim()))
	{  fld.style.background = 'Yellow'; 
     error = "The Business URL must be valid (Example: www.abc.com).\n";
	}
	else if(fld.value.trim().length>100)
	{  fld.style.background = 'Yellow'; 
     error = "The Business URL can have maximum 100 characters.\n";
	}
	else {
      fld.style.background = 'White';
  }
	}
else {
      fld.style.background = 'White';
  }

  return error;
}

function validatephone1(fld)
{ var error="";
 var allowedChars =/^[a-zA-Z0-9- ]{6,20}$/;
 if (fld.value == "" || fld.value == null) {
      fld.style.background = 'Yellow'; 
      error = "You didn't enter Phone Number1.\n";
  } 
 else if (fld.value.trim().length==0)
	{  fld.style.background = 'Yellow'; 
     error = "You didn't enter Phone Number1.\n";
	}
 else if (!allowedChars.test(fld.value.trim()))
	{  fld.style.background = 'Yellow'; 
     error = "The Phone Number1 must contain alphanumeric characters having length 6 to 20 characters (Example: 011-345-5454).\n";
	}
	else {
      fld.style.background = 'White';
  }
  return error;

}
function validatephone2(fld)
{
	var error = "";
	var allowedChars =/^[a-zA-Z0-9- ]{6,20}$/;
	  if (fld.value != "" && fld.value != null) {
	     if (fld.value.trim().length!=0 && !allowedChars.test(fld.value.trim()))
		{  fld.style.background = 'Yellow'; 
		error = "The Phone Number2 must contain alphanumeric characters having length 6 to 20 characters (Example: 011-345-5454).\n";
		}
		else {
	        fld.style.background = 'White';
	       }
		}
	  else {
	        fld.style.background = 'White';
	    }
	  
	    return error;
}
function validatefax(fld)
{
 var error = "";
var allowedChars = /^[a-zA-Z0-9- ]{6,16}$/;
if (fld.value != "" && fld.value != null) {
   if (fld.value.trim().length!=0 && !allowedChars.test(fld.value.trim()))
	{  fld.style.background = 'Yellow'; 
     error = "The Fax Number must contain alphanumeric characters having length 6 to 16 characters (Example: 100-345-5342).\n";
	}
	else {
      fld.style.background = 'White';
  }
	}
else {
      fld.style.background = 'White';
  }

  return error;
}
function validateaddress(fld)
{
 var error = "";
  if (fld.value == "" || fld.value == null) {
      fld.style.background = 'Yellow'; 
      error = "You didn't enter Address.\n";
  } 
	else if (fld.value.trim().length==0)
	{  fld.style.background = 'Yellow'; 
     error = "You didn't enter Address.\n";
	}
	else if ((fld.value.trim().length >50)) {
      fld.style.background = 'Yellow'; 
      error = "The Address can have maximum 50 characters.\n";
  } 
	else {
      fld.style.background = 'White';
  }
  return error;
}

function validatecountry(fld)
{ var error = "";
  if (fld.value == "" || fld.value == null) {
      fld.style.background = 'Yellow'; 
      error = "You didn't select Country.\n";
  } 
	else if (fld.value.trim().length==0)
	{  fld.style.background = 'Yellow'; 
     error = "You didn't select Country.\n";
	}
	else {
      fld.style.background = 'White';
  }
  return error;
}

function validateapproxVolumetoIndia(fld)
{
var error = "";
var allowedChars = /^[\d]+$/;
if (fld.value != "" && fld.value != null) {
   if (fld.value.trim().length!=0 && !allowedChars.test(fld.value.trim()))
	{  fld.style.background = 'Yellow'; 
     error = "The Approx Volume to India must be numeric.\n";
	}
   else if (fld.value.trim().length!=0 && fld.value.trim()>2147483647)
	{  fld.style.background = 'Yellow'; 
    error = "The Approx Volume to India must be less than or equal to 2147483647.\n";
	}
   
	else {
      fld.style.background = 'White';
  }
	}
else {
      fld.style.background = 'White';
  }

  return error;
}
function validateapproxTurnoverFortheLastFinancialYear(fld)
{
var error = "";
var allowedChars = /^[\d]+$/;
if (fld.value != "" && fld.value != null) {
   if (fld.value.trim().length!=0 && !allowedChars.test(fld.value.trim()))
	{  fld.style.background = 'Yellow'; 
     error = "The Approx Turnover must be numeric.\n";
	}
   else if (fld.value.trim().length!=0 && fld.value.trim()>2147483647)
	{  fld.style.background = 'Yellow'; 
       error = "The Approx Turnover must be less than or equal to 2147483647.\n";
	}
	else {
      fld.style.background = 'White';
  }
	}
else {
      fld.style.background = 'White';
  }

  return error;
}
function validationaccreditation3(fld)
{ var error = "";
var allowedChars = /^[a-zA-Z ,]{1,10}$/;
if (fld.value != "" && fld.value != null) {
   if (fld.value.trim().length!=0 && !allowedChars.test(fld.value.trim()))
	{  fld.style.background = 'Yellow'; 
     error = "The accreditation can only contain alphabatical words seperated by comma having maximum 10 characters length (Example: IATA,ASTA).\n";
	}
	else {
      fld.style.background = 'White';
  } 
	}
else {
      fld.style.background = 'White';
  }

  return error;

}
function validationcontactPersonName1(fld)
{
	var error="";
	var allowedChars = /^((([a-zA-Z]{1,20}[ ]){1,2}[a-zA-Z]{1,20})|([a-zA-Z]{1,20}))$/;
		if (fld.value == "" || fld.value == null) {
	        fld.style.background = 'Yellow';
	        error = "You didn't enter First Contact Person's Name.\n";
	    } 
		else if (fld.value.trim().length==0)
		{  fld.style.background = 'Yellow'; 
	       error = "You didn't enter First Contact Person's Name.\n";
		}
		else if (!allowedChars.test(fld.value.trim()))
		{  fld.style.background = 'Yellow'; 
	       error = "The First Contact Person's Name must contain only alphabatic words seperated by single space with each word having maximum 20 characters length (Example: rahul kumar dikshit).\n";
		}
		else {
	        fld.style.background = 'White';
	    }
	    return error;
	}
			
function validationcontactPersonName2(fld)
{
	var error="";
	var allowedChars = /^[a-zA-Z ]{1,100}$/;
		if (fld.value == "" || fld.value == null) {
	        fld.style.background = 'Yellow';
	        error = "You didn't enter Second Contact Person's Name.\n";
	    } 
		else if (fld.value.trim().length==0)
		{  fld.style.background = 'Yellow'; 
	       error = "You didn't enter Second Contact Person's Name.\n";
		}
		else if (!allowedChars.test(fld.value.trim()))
		{  fld.style.background = 'Yellow'; 
	       error = "The Second Contact Person's Name must contain only alphabatic letters having maximum 100 characters(Example: rahul kumar dikshit).\n";
		}
		else {
	        fld.style.background = 'White';
	    }
	    return error;
	}
			

function validationcontactPersonName3(fld)
{
	var error="";
	var allowedChars = /^[a-zA-Z ]{1,100}$/;
		if (fld.value == "" || fld.value == null) {
	        fld.style.background = 'Yellow';
	        error = "You didn't enter Third Contact Person's Name.\n";
	    } 
		else if (fld.value.trim().length==0)
		{  fld.style.background = 'Yellow'; 
	       error = "You didn't enter Third Contact Person's Name.\n";
		}
		else if (!allowedChars.test(fld.value.trim()))
		{  fld.style.background = 'Yellow'; 
	       error = "The Third Contact Person's Name must contain only alphabatic letters having maximum 100 characters(Example: rahul kumar dikshit).\n";
		}
		else {
	        fld.style.background = 'White';
	    }
	    return error;
}
			
function validationcontactPersonEmail1(fld)
{var error = "";
var allowedChars= /^([a-zA-Z0-9_\.-])+@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (fld.value == "" || fld.value == null) {
  fld.style.background = 'Yellow'; 
  error = "You didn't enter First Contact Person's Email.\n";
} 
else if (fld.value.trim().length==0)
{  fld.style.background = 'Yellow'; 
 error = "You didn't enter First Contact Person's Email.\n";
}
else if (!allowedChars.test(fld.value.trim()))
{  fld.style.background = 'Yellow'; 
 error = "The First Contact Person's Email must be valid email address (Example: rahul@yahoo.co.in).\n";
}
else if ((fld.value.trim().length >50)) {
  fld.style.background = 'Yellow'; 
  error = "The First Contact Person's Email can have maximum 50 characters.\n";
}
else {
  fld.style.background = 'White';
}
return error;
	
}
function validationcontactPersonEmail2(fld)
{var error = "";
var allowedChars= /^([a-zA-Z0-9_\.-])+@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (fld.value == "" || fld.value == null) {
  fld.style.background = 'Yellow'; 
  error = "You didn't enter Second Contact Person's Email.\n";
} 
else if (fld.value.trim().length==0)
{  fld.style.background = 'Yellow'; 
 error = "You didn't enter Second Contact Person's Email.\n";
}
else if (!allowedChars.test(fld.value.trim()))
{  fld.style.background = 'Yellow'; 
 error = "The Second Contact Person's Email must be valid email address (Example: rahul@yahoo.co.in).\n";
}
else if ((fld.value.trim().length >50)) {
  fld.style.background = 'Yellow'; 
  error = "The Second Contact Person's Email can have maximum 50 characters.\n";
} 
else {
  fld.style.background = 'White';
}
return error;
	
}
function validationcontactPersonEmail3(fld)
{var error = "";
var allowedChars= /^([a-zA-Z0-9_\.-])+@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (fld.value == "" || fld.value == null) {
  fld.style.background = 'Yellow'; 
  error = "You didn't enter Third Contact Person's Email.\n";
} 
else if (fld.value.trim().length==0)
{  fld.style.background = 'Yellow'; 
 error = "You didn't enter Third Contact Person's Email.\n";
}
else if (!allowedChars.test(fld.value.trim()))
{  fld.style.background = 'Yellow'; 
 error = "The Third Contact Person's Email must be valid email address (Example: rahul@yahoo.co.in).\n";
}
else if ((fld.value.trim().length >50)) {
  fld.style.background = 'Yellow'; 
  error = "The Third Contact Person's Email can have maximum 50 characters.\n";
} 
else {
  fld.style.background = 'White';
}
return error;
	
}
function validationcontactPersonDesignation1(fld)
{
	var error = "";
	var allowedChars = /^[a-zA-Z ]{1,50}$/;
	if (fld.value != "" && fld.value != null) {
	   if (fld.value.trim().length!=0 && !allowedChars.test(fld.value.trim()))
		{  fld.style.background = 'Yellow'; 
		error = "The First Contact Person's Designation can only contain alphabatical words seperated by space having maximum 50 characters length.\n"
		}
		else {
	      fld.style.background = 'White';
	  } 
		}
	else {
	      fld.style.background = 'White';
	  }

	  return error;	
}
function validationcontactPersonDesignation2(fld)
{
	var error = "";
	var allowedChars = /^[a-zA-Z ]{1,50}$/;
	if (fld.value != "" && fld.value != null) {
	   if (fld.value.trim().length!=0 && !allowedChars.test(fld.value.trim()))
		{  fld.style.background = 'Yellow'; 
		error = "The Second Contact Person's Designation can only contain alphabatical words seperated by space having maximum 50 characters length.\n"
		}
		else {
	      fld.style.background = 'White';
	  } 
		}
	else {
	      fld.style.background = 'White';
	  }

	  return error;	
}
function validationcontactPersonDesignation3(fld)
{
	var error = "";
	var allowedChars = /^[a-zA-Z ]{1,50}$/;
	if (fld.value != "" && fld.value != null) {
	   if (fld.value.trim().length!=0 && !allowedChars.test(fld.value.trim()))
		{  fld.style.background = 'Yellow'; 
		error = "The Third Contact Person's Designation can only contain alphabatical words seperated by space having maximum 50 characters length.\n"
		}
		else {
	      fld.style.background = 'White';
	  } 
		}
	else {
	      fld.style.background = 'White';
	  }

	  return error;	
}

