// JavaScript Document

function image_part()
{
	var image_file =document.form1.uploaditem.value;
	var c1,c2;
	c1 = image_file.lastIndexOf('.');
	c2 = image_file.substring(c1);
	
	if( (c2 == '.jpg') || (c2 == '.gif') || (c2 == '.JPG') || (c2 == '.GIF') )
	{
		document.form1.submit.disabled=false;
		return false;
	}
	else
	{
		alert("Please select an image of type JPG or GIF.");
		document.form1.uploaditem.focus();
		document.form1.submit.disabled=true;
		return false;
	}
}
	
var rd;	
function check()
{
	var FName			= document.form1.Name.value;
	var REBAffiliation	= document.form1.REBaffiliation.value;
	var Office_Name 	= document.form1.offname.value;
	
	var Office_City		= document.form1.offcity.value;
	var Office_Email 	= document.form1.offemail.value;
	
	
	if(Trim(FName) == 0)
	{
		alert("Please enter your full name");
		document.form1.Name.select(); 
		document.form1.Name.focus();
		return false;
	}

	if(Trim(REBAffiliation) == 0)
	{
		alert("Please enter your real estate board affiliation");
		document.form1.REBaffiliation.select(); 
		document.form1.REBaffiliation.focus();
		return false;
	}

	if(Trim(Office_Name) == 0)
	{
		alert("Please enter your office name");
		document.form1.offname.select(); 
		document.form1.offname.focus();
		return false;
	}

	if(Trim(Office_City) == 0)
	{
		alert("Please enter your office city");
		document.form1.offcity.select(); 
		document.form1.offcity.focus();
		return false;
	}

	if( document.form1.offcountry.value == "" )
	{
		alert("Please select your office country");
		return false;
	}

	if(Trim(Office_Email) == 0)
	{
		alert("Please enter your email id");
		document.form1.offemail.select(); 
		document.form1.offemail.focus();
		return false;
	}
	else
	{
		var email1 = document.form1.offemail.value;
		var e3,e4;
		var err1 = new Array(0,0);
		e3 = email1.indexOf("@");
		e4 = email1.lastIndexOf("@");
		
		if(e3 != -1 && e3 == e4)
		{
			var a = email1.indexOf(".",e3);
			if((a-e3) < 2)
			err1[0] = 1;
		}
		else{	err1[0] = 1;		}
		
		if(err1[0] == 1)
		{
			alert("The email id you have entered is in an invalid format. Please check and re-enter again");
			document.form1.offemail.select();	
			document.form1.offemail.focus();
			return false;			
		}
	}

	title();
	return false;
}
	
// for Title Checking .
function title()
{
	if( (document.form1.Title1.checked ) || (document.form1.Title2.checked ) || 
		(document.form1.Title3.checked ) || (document.form1.Title4.checked ) || 
		(document.form1.Title5.checked ) || (document.form1.Title6.checked ) )
	{
		check_country();
		return false;
	}
	else
	{
		alert("Please select at least one title.");
		return false;
	}
}
	
function check_country()
{
	if(!(document.form1.offcountry.value=="United States"))
	{
		language();
		return false;
	}
	else
	{
		citystate();
		return false;
	}
}
	
// for City and State  Checking .
function citystate()
{
	if( ( ( document.form1.cities1.value=="" ) &&  ( document.form1.state1.value=="" ) &&  ( document.form1.country1.value=="" ) ) &&
		( ( document.form1.cities2.value=="" ) &&  ( document.form1.state2.value=="" ) &&  ( document.form1.country2.value=="" ) ) &&
		( ( document.form1.cities3.value=="" ) &&  ( document.form1.state3.value=="" ) &&  ( document.form1.country3.value=="" ) ) &&
		( ( document.form1.cities4.value=="" ) &&  ( document.form1.state4.value=="" ) &&  ( document.form1.country4.value=="" ) ) &&
		( ( document.form1.cities5.value=="" ) &&  ( document.form1.state5.value=="" ) &&  ( document.form1.country5.value=="" ) ) &&
		( ( document.form1.cities6.value=="" ) &&  ( document.form1.state6.value=="" ) &&  ( document.form1.country6.value=="" ) )  )
		{
			alert("Please fill an area(s) you serve.");
			return false;
		}
		else
		{
			citystate1();
			return false;
		}
}
	
	// for City and state checking each and every thing.
function citystate1()
{
	 var a1,a2,a3,a4,a5,a6;
	// first state and city.
	if( (document.form1.cities1.value=="") && (document.form1.state1.value=="") && (document.form1.country1.value=="") ) 
	{
			a1 =0; 		 
	}
	else if( (!(document.form1.cities1.value=="")) && (!(document.form1.state1.value=="")) && (!(document.form1.country1.value=="")) )
	{
			a1 =0; 
	}
	else	
	{		
			a1 =1; 	
	}
		
	// second state and city.
	if( (document.form1.cities2.value=="") && (document.form1.state2.value=="") && (document.form1.country2.value=="") ) 
	{
			a2 =0;  
	}
	else if( (!(document.form1.cities2.value=="")) && (!(document.form1.state2.value=="")) && (!(document.form1.country2.value=="")) )
	{
			a2 =0; 		
	}
	else	
	{ 		
			a2 =1;  
	}
		
		
	// third state and city.
	if( (document.form1.cities3.value=="") && (document.form1.state3.value=="") && (document.form1.country3.value=="") ) 
	{		
			a3 =0;  
	}
	else if( (!(document.form1.cities3.value=="")) && (!(document.form1.state3.value=="")) && (!(document.form1.country3.value=="")) )
	{		
			a3 =0; 	
	}
	else	
	{ 		
			a3 =1; 
	}
	
		
	// fourth state and city.
	if( (document.form1.cities4.value=="") && (document.form1.state4.value=="") && (document.form1.country4.value=="") ) 
	{ 		
			a4 =0; 
	}
	else if( (!(document.form1.cities4.value=="")) && (!(document.form1.state4.value=="")) && (!(document.form1.country4.value=="")) )
	{		
			a4 =0;
	}
	else	
	{	
			a4 =1; 
	}
		
	// fifth state and city.
	if( (document.form1.cities5.value=="") && (document.form1.state5.value=="") && (document.form1.country5.value=="") ) 
	{ 		
			a5 =0; 
	}
	else if( (!(document.form1.cities5.value=="")) && (!(document.form1.state5.value=="")) && (!(document.form1.country5.value=="")) )
	{ 		
			a5 =0; 		
	}
	else	
	{ 		
			a5 =1; 	
	}
		
	// sixth state and city.
	if( (document.form1.cities6.value=="") && (document.form1.state6.value=="") && (document.form1.country6.value=="") ) 
	{ 		
			a6 =0; 	
	}
	else if( (!(document.form1.cities6.value=="")) && (!(document.form1.state6.value=="")) && (!(document.form1.country6.value=="")) )
	{		
			a6 =0; 	
	}
	else 
	{		
			a6 =1; 	
	}
		 
	 if( (a1 == 0) && (a2 == 0) && (a3 == 0) && (a4 == 0) && (a5 == 0) && (a6 == 0) )
	 {
		language();
		return false;
	 }
	 else
	 {
		 alert("Please select the corresponding City/State for the areas you serve.");
		 return false;
	 }
}
	
// for Language Checking .
function language()
{
	if( (document.form1.c1.checked ) || (document.form1.c2.checked ) || 
		(document.form1.c3.checked ) || (document.form1.c4.checked ) || 
		(document.form1.c5.checked ) || (document.form1.c6.checked ) || 
		(document.form1.c7.checked ) || (document.form1.c8.checked ) 
		|| ( !(document.form1.otherlanguage.value == "")  ) )
		{
			accept();
			return false;
		}
		else
		{
			alert("Please select at least one language.");
			return false;
		}
}
	
function sele(mari)
{
	rd=mari.value;
}

function accept()
{
	if(rd == 1)
	{
		chec();
		return false;
	}
	else
	{
		alert("You have to Accept our Terms and Conditions to become a member of SAREAA.");
		return false;
	}
}

// for passing the hidden field for uploading a file or not.
function chec()
{
	if (document.form1.uploaditem.value == "")
	{
		document.form1.pass.value=0;
		document.form1.action="Insert_membership.jsp";
		document.form1.submit(); 
		return true;
	}
	else
	{
		document.form1.pass.value=1;
		document.form1.action="Insert_membership.jsp";
		document.form1.submit(); 
		return true;
	}
}
	
// Trims all spaces to the left of a specific string
function LTrim(str)
{
	var whitespace = new String(" \t\n\r "); 
	var s = new String(str);
	if (whitespace.indexOf(s.charAt(0)) != -1) 
	{
		var j=0, i = s.length;
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
			j++;
		s = s.substring(j, i);
	}
	return s;
}
// Trims all spaces to the right of a specific string
function RTrim(str)
{
	var whitespace = new String(" \t\n\r "); 
	var s = new String(str);
	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) 
	{
		var i = s.length - 1;       // Get length of string
		while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
			i--;
		s = s.substring(0, i+1);
	}
	return s;
}

// Trims all spaces to the left and right of a specific string by calling RTim and LTrim
function Trim(str)
{
	return RTrim(LTrim(str));
}