	
	/****************************************************************************************
	*		    File Name: 	   org_registration.js				     						*
	*		  Author Name:     Nabeel Bin Ezad						    					*
	* 		  Description:	   Used for organization registration functionality 			*	
	*		 Created Date:	   10 March 2008   											    *
	*	     Modified Date:	   03 Sept 2008	    											*
	*	 Last Modified By:	   Ramish Hashmi	 											*
	*																						*
	****************************************************************************************/	
					
					
	/************************************************************************
	*	 Function Name:GetOrgForm()									
	*	  Synopsis: gets the organization registration forom
	*  	 Author Name: Ramish Hashmi 																		
	*************************************************************************/	
	var intEdit=0;
	function GetOrgForm()
	{
		
		var url = 'GUIService/OrganizationService.php?action=OrgRegisterform'; 
		var myRequest= new Ajax.Request(
						url, 
						{   
							method: 'post',
							onSuccess: function(transport) 
							{      
								document.getElementById("registrationForm").innerHTML="";
								document.getElementById("registrationForm").innerHTML=transport.responseText;
								GetStatesByCountryIdInitial(3);
								
							} 
						}); 
	}
	/************************************************************************
	*
	*	Function Name:	GetStatesByCountryId									
	*	Author Name: 	Ramish Hashmi																		
	*************************************************************************/	
	function GetStatesByCountryIdInitial(pIntCountryId)
	 {
		if(pIntCountryId==0)
		 {
			pIntCountryId=document.getElementById("cmbCountry").value;	
		 }
		
		var url = 'GUIService/CountryService.php?action=stateInitial&cid='+pIntCountryId;
		document.getElementById("DivState").innerHTML="<img src=ImageFiles/indicator_medium.gif>";
		var myRequest= new Ajax.Request(
		url, 
		{   
			method: 'post',
			onSuccess: function(transport) 
			{
				document.getElementById("DivState").innerHTML=transport.responseText;
			} 
		});
		
	 }
	/****************************************************************************************************
    * 	Function Name	: 	orgRegister() 
	* 	Author			: 	Ramish Hashmi
	* 	Synopsis		: 	Saves the organization registration  info to the database
	*****************************************************************************************************/
   function orgRegister()
   {
	   	
		document.getElementById("orgNameError").innerHTML="";
		document.getElementById("userNameError").innerHTML="";
		document.getElementById("contactPersonError").innerHTML="";
		document.getElementById("contactTitleError").innerHTML="";
		document.getElementById("passwordError").innerHTML="";
		document.getElementById("passwordError2").innerHTML="";
		document.getElementById("emailError").innerHTML="";
		document.getElementById("industryError").innerHTML="";
		document.getElementById("approxemployeesError").innerHTML="";
		document.getElementById("employeesError").innerHTML="";
		document.getElementById("addressError").innerHTML="";
		document.getElementById("cityError").innerHTML="";
		document.getElementById("provinceError").innerHTML="";
		document.getElementById("countryError").innerHTML="";
		document.getElementById("cityError").innerHTML="";
		document.getElementById("zipCodeError").innerHTML="";
		document.getElementById("phoneError").innerHTML="";
		
		var strEmail= document.getElementById("email").value;
		var strZip = document.getElementById('zipCode').value;
		intEdit=0;
         CheckOrgSettings();
   }
		//if(CheckAvailableEmail())
	function SaveData()
		{
				
				var url = 'GUIService/OrganizationService.php?action=addOrganization'; 
				var par='orgName='+document.getElementById("orgName").value
						 +'&userName='+document.getElementById("userName").value
						 +'&password='+document.getElementById("password").value
						 +'&email='+document.getElementById("email").value
						 +'&industry='+document.getElementById("cmbIndustry").value
						 +'&address='+document.getElementById("address").value
						 +'&city='+document.getElementById("city").value
						 +'&state='+document.getElementById("cmbState").value
						 +'&country='+document.getElementById("cmbCountry").value				 
						 +'&zipCode='+document.getElementById("zipCode").value
						 +'&phone='+document.getElementById('phone1part1').value+document.getElementById('phone1part2').value+document.getElementById('phone1part3').value
 						 +'&secondphone='+document.getElementById('phone2part1').value+document.getElementById('phone2part2').value+document.getElementById('phone2part3').value
						 +'&person='+document.getElementById("contactPerson").value
						 +'&title='+document.getElementById("contactTitle").value
						 +'&employees='+document.getElementById("employees").value
						 +'&approxEmp='+document.getElementById('cmbEmployees').value;
				
				var temp = par; //new String('This is a te!!!!st st>ring... So??? What...');
				//temp =  temp.replace(/[^a-zA-Z 0-9 & = @ . - _ ' ' ' /]+/g,'');	
				
				document.getElementById("registrationForm").style.visibility="hidden";
				document.getElementById("registrationForm").style.display="none";
				document.getElementById("done_Reg").style.visibility="visible";
				document.getElementById("done_Reg").style.display="inline";	
				document.getElementById("regStatus").innerHTML="<img src=ImageFiles/indicator_medium.gif> Please wait...";
				var myRequest= new Ajax.Request(
					url, 
					{   
						method: 'post',
						parameters:temp,
						onSuccess: function(transport) 
						{ 
							
							if(transport.responseText==1)
							{
								document.getElementById("regStatus").innerHTML='Registration Successful! Please check your email for further details.';
							}
							else
							{
							   document.getElementById("regStatus").innerHTML='Registration Failed';
							}
							 document.getElementById("home_page").focus();
						} 
					});
		//}
   }
    /************************************************************************
	*
	*	Function Name:	CheckOrgSettings									
	*	Author Name: 	Nabeel Bin Ezad
	*																		
	*************************************************************************/	
   function CheckOrgSettings()
   {
	 var  allow=1;
		if(document.getElementById("orgName").value=='')
		{
			allow=0;
			document.getElementById("orgNameError").innerHTML="Field Required";
			document.getElementById("orgName").focus();
			return false;
		}
		else if(!CheckSpaces(document.getElementById("orgName").value))
		{
			allow=0;
			document.getElementById("orgNameError").innerHTML="Invalid Data Entry";
			document.getElementById("orgName").focus();
		    return false; 
		}
		CheckOrgName()
		/*else if (CheckOrgName()==0)
		{
			document.getElementById("orgNameError").innerHTML="This organization has already applied";
			document.getElementById("orgName").focus();
			allow=0;
			
			return false;
		
		}*/
		/*else if(document.getElementById("userName").value=='')
		{
			document.getElementById("userNameError").innerHTML="Field Required";
			document.getElementById("userName").focus();
			allow=0;
		}
		else if (!CheckSpaces(document.getElementById("userName").value))
		{
			document.getElementById("userNameError").innerHTML="Invalid Data Entry";
			document.getElementById("userName").focus();
		    allow=0;
		}
	    else if(! ChechUserName())
		{
			document.getElementById("userNameError").innerHTML="This username is already taken";
			document.getElementById("userName").focus();
		    allow=0;

			
		}
		*/
   }
	/************************************************************************
	*
	*	Function Name:	CheckPassword									
	*	Author Name: 	Nabeel Bin Ezad
	*																		
	*************************************************************************/	
   function CheckPassword()
   {
    	if(document.getElementById("password").value=='')
		{
			document.getElementById("password").focus();
			document.getElementById("passwordError").innerHTML="Field Required";
			return false;
		}
		else 
		{
			if(!CheckSpaces(document.getElementById("password").value))
			{										   
				document.getElementById("passwordError").innerHTML="Invalid Data Entry";
				document.getElementById("password").focus();
				return false;
			}
			if(document.getElementById("password").value.length<6)
			{
				document.getElementById("password").focus();
				document.getElementById("passwordError").innerHTML="Password should be more than 6 characters";
				return false;
			}
			else
			{
				document.getElementById("passwordError").innerHTML="";
			}
		}
		if(document.getElementById("password2").value=='')
		{
			document.getElementById("passwordError2").innerHTML="Field Required";
			document.getElementById("password2").focus();
			return false;
		}
		else
		{
			if(!CheckSpaces(document.getElementById("password2").value))
			{
				document.getElementById("passwordError2").innerHTML="Invalid Data Entry";
				document.getElementById("password2").focus();
				return false;
			}
			
			if(document.getElementById("password2").value.length<6)
			{
				document.getElementById("password2").focus();
				document.getElementById("passwordError2").innerHTML="Password should be more than 6 characters";
				return false;
			}
			else
			{
				document.getElementById("passwordError2").innerHTML="";
			}
		}
		if(document.getElementById("password2").value!=document.getElementById("password").value)
		{
			document.getElementById("passwordError2").innerHTML="Password fields do not match";
			document.getElementById("password2").focus();
			return false;
		}		 			
		return true;
   }
   /************************************************************************
	*
	*	Function Name:	ChechUserName									
	*	Author Name: 	Nabeel Bin Ezad
	*																		
	*************************************************************************/	
   function ChechUserName()
   {
	   var check2="";
		var url = 'GUIService/UserService.php?action=checkUserName'; 
			var par='username='+document.getElementById("userName").value
			var myRequest= new Ajax.Request(
							url, 
							{ 
								method: 'post',
								parameters:par,
								onSuccess: function(transport) 
									{  
									  if(transport.responseText==1)
								  	  {
											document.getElementById("userNameError").innerHTML="This username is already taken";
											document.getElementById("userName").focus();
											check2=0;
											return false;
									  }
									  else
									  {
									 		check2=1;
									  }
									  
									  if(check2==1)
									  {
										
										if(!CheckPassword())
										{
										  return false;
										}
										if(CheckValidEmailAddress(document.getElementById("email").value)==false)
										{
											document.getElementById("email").focus();
											return false;
										}
										 
										 CheckAvailableEmail()
										 
									  }
										 
									}
							});
											
   }
	/************************************************************************
	*
	*	Function Name:	CheckValidEmailAddress									
	*	Author Name: 	Nabeel Bin Ezad
	*																		
	*************************************************************************/	
   function CheckValidEmailAddress(pStrEmailAddress)
   {
	   
	   if(pStrEmailAddress=='')
	   {
			document.getElementById("emailError").innerHTML="Field Required";
			return false;
	   }
	   
	   if(pStrEmailAddress.indexOf('@')==-1) //arslanyahoo.com no @ aign
	   {
			document.getElementById("emailError").innerHTML="Invalid email address";
			return false;
	   }
	   if(pStrEmailAddress.indexOf('@')!=pStrEmailAddress.lastIndexOf('@'))
	   {
			document.getElementById("emailError").innerHTML="Invalid email address";
			return false;
	   }
	   
	   if(pStrEmailAddress!='')
	   {
			var chunks=pStrEmailAddress.split('@');
			var user=chunks[0];
			if(!user || user.length==0)
			{
				document.getElementById("emailError").innerHTML="Invalid email address";
				return false;
			}
			if(user.substring(0,1)=='.'||user.substring(0,1)=='-'||user.substr(user.length-1,1)=='.')	
			{
				document.getElementById("emailError").innerHTML="Invalid email address";
				return false;
			}
			if(!CheckValidCharacters(user))//check user name contains all valid characters
			{
				document.getElementById("emailError").innerHTML="Invalid email address";
				return false;		
			}					
			domain=chunks[1];
			if(!CheckDomain(domain))
			{
				document.getElementById("emailError").innerHTML="Invalid email address";
				return false;
			}
	   }
       return true;
   }
		
		
	/****************************************************************************************************
    * 	Function Name	: 	homePage() 
	* 	Author			: 	Ramish Hashmi
	* 	Synopsis		: 	take back to the  dashboard						              
	*************************************************************************************************/
	function homePage()
	{
		window.location="index.php";
	}
	/***************************************************************************
    * 	Function Name	: 	CheckDomain() 
	* 	Synopsis		: 	Check for valid domain
	****************************************************************************/
	function CheckDomain(domain)
	{
		var flag = true;
		if(!domain || domain.length==0)
			flag = false;
		
		
		if(domain.substring(0,1)=='.' || domain.substring(0,1)=='-' || domain.substr(domain.length-1,1)=='.' || domain.substr(																														
		   domain.length-1,1)=='-')
			flag =  false;
		
		if(domain.indexOf('.')==-1)//msn.co.uk , yahoo.com
			flag =  false;
		
		
		if(!CheckValidCharacters(domain))
			flag =  false;
		
		return flag;
	}//end function
			
	/***************************************************************************
    * 	Function Name	: 	CheckValidCharacters() 
	* 	Synopsis		: 	Check for valid input string charecters
	****************************************************************************/
	function CheckValidCharacters(string)
	{
		if(!string || string.length==0)
		{
			return false;
		}
		for(var i=0;i<string.length;i++)
		{
			code=string.charCodeAt(i);
			//if user name has . or - or _ in anywhere in user name, and also between a-z,0-9, caps does not matter
			if(code==45 || code==46 || code==95 || (code>47 && code<58) || (code>96 && code<123) || (code>64 && code<91))
			{
				continue;
			}
			else
			{
				return false;
			}		
		}
		return true;
	}//end function
	
	/***************************************************************************
    * 	Function Name	: 	CheckNumbers() 
	* 	Synopsis		: 	Check for valid input string charecters
	****************************************************************************/
	function CheckNumbers(string)
	{
		
	
		for(var i=0;i<string.length;i++)
		{
			code=string.charCodeAt(i);
			//if user name has . or - or _ in anywhere in user name, and also between a-z,0-9, caps does not matter
			
			if((code>=48) &&(code<=57))
			{
				continue;
			}
			else
			{
				return false;
			}		
		}
		return true;
	}//end function
	/***************************************************************************
    * 	Function Name	: 	CheckSpaces() 
	* 	Synopsis		: 	Check for spaces and valid string input
	*	Author			:	Ramish Hashmi
	****************************************************************************/
	function CheckSpaces(string)
	{
		if(!string || string.length==0)
		{
			return false;
		}
		code=string.charCodeAt(0);
		if(code == 32)
		{
			return false
		}
		else
		{
			return true;
		}
	}
	/***************************************************************************
    * 	Function Name	: 	EditOrgDetails() 
	* 	Synopsis		:   Editing the organization details
	*	Author			:	Ramish Hashmi
	****************************************************************************/
	function EditOrgDetails(pIntUserId,pIntCompanyId)
	{
		document.getElementById("orgNameError").innerHTML="";
		document.getElementById("contactPersonError").innerHTML="";
		document.getElementById("contactTitleError").innerHTML="";
		document.getElementById("userNameError").innerHTML="";
		document.getElementById("passwordError").innerHTML="";
		document.getElementById("passwordError2").innerHTML="";
		document.getElementById("emailError").innerHTML="";
		document.getElementById("industryError").innerHTML="";
		document.getElementById("approxemployeesError").innerHTML="";
		document.getElementById("employeesError").innerHTML=""
		document.getElementById("addressError").innerHTML="";
		document.getElementById("cityError").innerHTML="";
		document.getElementById("provinceError").innerHTML="";
		document.getElementById("countryError").innerHTML="";
		document.getElementById("cityError").innerHTML="";
		document.getElementById("zipCodeError").innerHTML="";
		document.getElementById("phoneError").innerHTML="";
		
		var strEmail= document.getElementById("email").value;
		var strZip = document.getElementById('zipCode').value;
		intEdit=1;
		if(document.getElementById("orgName").value=='')
		{
			allow=0;
			document.getElementById("orgNameError").innerHTML="Field Required";
			document.getElementById("orgName").focus();
			return false;
		}
		else if(!CheckSpaces(document.getElementById("orgName").value))
		{
			allow=0;
			document.getElementById("orgNameError").innerHTML="Invalid Data Entry";
			document.getElementById("orgName").focus();
		    return false; 
		}
	    if(document.getElementById("contactPerson").value=='')
		{
			document.getElementById("contactPersonError").innerHTML="Field Required";
			document.getElementById("contactPerson").focus();
			return false;
		}
		else if (!CheckSpaces(document.getElementById("contactPerson").value))
		{
			document.getElementById("contactPersonError").innerHTML="Invalid Data Entry";
			document.getElementById("contactPerson").focus();
			return false;
		}
		/*else if(!CheckValidCharacters(document.getElementById("contactPerson").value))
		{
			document.getElementById("contactTitleError").innerHTML="Invalid Data Entry";
			document.getElementById("contactTitle").focus();
			return false;
		}*/
		
		if(document.getElementById("contactTitle").value=='')
		{
			document.getElementById("contactTitleError").innerHTML="Field Required";
			document.getElementById("contactTitle").focus();
			return false;
		}
		else if (!CheckSpaces(document.getElementById("contactTitle").value))
		{
			document.getElementById("contactTitleError").innerHTML="Invalid Data Entry";
			document.getElementById("contactTitle").focus();
			return false;
		}
		/*else if(!CheckValidCharacters(document.getElementById("contactTitle").value))
		{
			document.getElementById("contactTitleError").innerHTML="Invalid Data Entry";
			document.getElementById("contactTitle").focus();
			return false;
		}*/
		if(!CheckPassword())
		{
		  return false;
		}
		if(CheckValidEmailAddress(document.getElementById("email").value)==false)
		{
			document.getElementById("email").focus();
			return false;
		}
		
		if(document.getElementById('cmbIndustry').value=='')
		{
			document.getElementById("cmbIndustry").focus();
			document.getElementById("industryError").innerHTML="Field Required";
			return false;
		}
		
		if(document.getElementById('cmbEmployees').value=='')
		{
			document.getElementById("cmbEmployees").focus();
			document.getElementById("approxemployeesError").innerHTML="Field Required";
			return false;
		}
		
		if(document.getElementById('employees').value=='')
		{
			document.getElementById("employees").focus();
			document.getElementById("employeesError").innerHTML="Field Required";
			return false;
		}
		
		if(!CheckNumbers(document.getElementById('employees').value))
		{
			document.getElementById("employees").focus();
			document.getElementById("employeesError").innerHTML="Invalid data entry.";
			return false; 
		}

		if(document.getElementById('address').value=='')
		{
		document.getElementById("address").focus();
		document.getElementById("addressError").innerHTML="Field Required";
		return false;
		}
		
		else 
		{
			if(!CheckSpaces(document.getElementById("address").value))
			{
				document.getElementById("address").focus();
				document.getElementById("addressError").innerHTML="Invalid Data Entry";
				return false;
			}
			else
			{
				document.getElementById("addressError").innerHTML="";
			}
		}
		if(document.getElementById('city').value=='')
		{
			document.getElementById("city").focus();
			document.getElementById("cityError").innerHTML="Field Required";
			return false;
		}
		else
		{
			if(!CheckSpaces(document.getElementById("city").value))
			{
				document.getElementById("city").focus();
				document.getElementById("cityError").innerHTML="Invalid Data Entry";
				return false;
			}
			else
			{
				document.getElementById("cityError").innerHTML="";
			}
		}
										
		if((document.getElementById('cmbCountry').value==3)&&(document.getElementById('cmbState').value==''))
		{
			document.getElementById("cmbState").focus();
			document.getElementById("provinceError").innerHTML="Field Required";
			return false;
		}   
		if(document.getElementById('cmbCountry').value=='')
		{
			document.getElementById("cmbState").focus();
			document.getElementById("countryError").innerHTML="Field Required";
			 return false;
		}
		if(document.getElementById('zipCode').value.length<5)
		{
			document.getElementById("zipCode").focus();
			document.getElementById("zipCodeError").innerHTML="Invalid data entry, please enter the correct code";
			return false;
		}
		if(!CheckNumbers(document.getElementById('zipCode').value))
		{
			document.getElementById("zipCode").focus();
			document.getElementById("zipCodeError").innerHTML="Invalid data entry, please enter the correct code";
			return false; 
		}
		if(document.getElementById('phone1part1').value==''|| document.getElementById('phone1part2').value==''||document.getElementById('phone1part3').value=='')
		{		
			document.getElementById("phoneError").innerHTML="Field Required";
			document.getElementById('phone1part1').focus();
			return false;	
		}
		if(!CheckNumbers(document.getElementById('phone1part1').value)||!CheckNumbers(document.getElementById('phone1part2').value)||!CheckNumbers(document.getElementById('phone1part3').value))
		{
			document.getElementById("phoneError").innerHTML="Invalid Data Entry";
			document.getElementById('phone1part1').focus();
			return false;
		}
		var pIntPhone1 = document.getElementById('phone1part1').value+document.getElementById('phone1part2').value+document.getElementById('phone1part3').value;
		if(pIntPhone1.length<10)
		{
			 document.getElementById("phoneError").innerHTML="Invalid Data Entry";
			 document.getElementById('phone1part1').focus();
			 return false;
		}
		else
		{
			document.getElementById("phoneError").innerHTML="";
		}
		if(document.getElementById('phone2part1').value!='')//||document.getElementById('phone2part2').value!=''||document.getElementById('phone2part3').value!='')
		{
			if(!CheckNumbers(document.getElementById('phone2part1').value)||!CheckNumbers(document.getElementById('phone2part2').value)||!CheckNumbers(document.getElementById('phone2part3').value))
			{
				document.getElementById("phone2Error").innerHTML="Invalid Data Entry";
				document.getElementById('phone2part1').focus();
				return false;
			}
			var pIntPhone2 = document.getElementById('phone2part1').value+document.getElementById('phone2part2').value+document.getElementById('phone2part3').value;
			if(pIntPhone2.length<10)
			{
				document.getElementById("phone2Error").innerHTML="Invalid Data Entry";
				document.getElementById('phone2part1').focus();
				return false;
			}
			else
			{
				document.getElementById("phone2Error").innerHTML="";
				
			}
		}
		
		//else
		//{
		  
			var url = 'GUIService/OrganizationService.php?action=editOrganizationInfo&userId='+pIntUserId+'&compId='+pIntCompanyId; 
			 var par='orgName='+document.getElementById("orgName").value
							 +'&userName='+document.getElementById("userName").value
							 +'&password='+document.getElementById("password").value
							 +'&email='+document.getElementById("email").value
							 +'&industry='+document.getElementById("cmbIndustry").value
							 +'&address='+document.getElementById("address").value
							 +'&city='+document.getElementById("city").value
							 +'&state='+document.getElementById("cmbState").value
							 +'&country='+document.getElementById("cmbCountry").value				 
							 +'&zipCode='+document.getElementById("zipCode").value
							 +'&phone='+document.getElementById('phone1part1').value+document.getElementById('phone1part2').value+document.getElementById('phone1part3').value
							 +'&secondphone='+document.getElementById('phone2part1').value+document.getElementById('phone2part2').value+document.getElementById('phone2part3').value
							 +'&person='+document.getElementById("contactPerson").value
						 	 +'&title='+document.getElementById("contactTitle").value
							 +'&employees='+document.getElementById("employees").value
							 +'&approxEmp='+document.getElementById('cmbEmployees').value;
			
				
			var temp = par; //new String('This is a te!!!!st st>ring... So??? What...');
				//temp =  temp.replace(/[^a-zA-Z 0-9 - & = @ . - ,  _  ' /]+/g,'');	
			
			document.getElementById("divDashBoard").innerHTML="<img src=ImageFiles/indicator_medium.gif>";
					 var myRequest= new Ajax.Request(
						url, 
					 	{   
						 method: 'post',
						 parameters:temp,
						 onSuccess: function(transport) 
						  { 
							if(transport.responseText==1)
							{
						  		window.location="index.php?q=programmanager";
							}
						  }
				    	});

		 
		 
		//}
   
   }
		//if(CheckAvailableEmail())
	/*function SaveData()  
		//if(CheckAvailableEmail())
		{
			var url = 'GUIService/OrganizationService.php?action=editOrganizationInfo&userId='+pIntUserId+'&compId='+pIntCompanyId; 
			 var par='orgName='+document.getElementById("orgName").value
							 +'&userName='+document.getElementById("userName").value
							 +'&password='+document.getElementById("password").value
							 +'&email='+document.getElementById("email").value
							 +'&industry='+document.getElementById("cmbIndustry").value
							 +'&address='+document.getElementById("address").value
							 +'&city='+document.getElementById("city").value
							 +'&state='+document.getElementById("cmbState").value
							 +'&country='+document.getElementById("cmbCountry").value				 
							 +'&zipCode='+document.getElementById("zipCode").value
							 +'&phone='+document.getElementById('phone1part1').value+document.getElementById('phone1part2').value+document.getElementById('phone1part3').value;
			
				
			var temp = par; //new String('This is a te!!!!st st>ring... So??? What...');
			temp =  temp.replace(/[^a-zA-Z 0-9 & = @ . - _ ' ' /]+/g,'');	
			
			document.getElementById("divDashBoard").innerHTML="<img src=ImageFiles/indicator_medium.gif>";
					 var myRequest= new Ajax.Request(
						url, 
					 	{   
						 method: 'post',
						 parameters:temp,
						 onSuccess: function(transport) 
						  { 
						  							
							if(transport.responseText==1)
							{
						  	 window.location="index.php?q=programmanager";
							}
						  }
				    	});
			
		  //} //if ends
		  
		}//function ends	
		*/
		function CheckOrgName()
		{
			var  check = "";
			var url = 'GUIService/OrganizationService.php?action=checkOrgName'; 
			var par='orgname='+document.getElementById("orgName").value;
			var myRequest= new Ajax.Request(
					url, 
					{   
						method: 'post',
						parameters:par,
						onSuccess: function(transport) 
						{      
							if(transport.responseText>0)
							{
								check = 0;
							}
							else
							{
								check=1;
							}
							
						if (check==0)
						{
								document.getElementById("orgNameError").innerHTML="This organization has already applied";
								document.getElementById("orgName").focus();
				//			allow=0;
			
							return false;
						}						
						else
						{
						  if(document.getElementById("contactPerson").value=='')
							{
								document.getElementById("contactPersonError").innerHTML="Field Required";
								document.getElementById("contactPerson").focus();
								return false;
							}
							else if (!CheckSpaces(document.getElementById("contactPerson").value))
							{
								document.getElementById("contactPersonError").innerHTML="Invalid Data Entry";
								document.getElementById("contactPerson").focus();
								return false;
							}
							/*else if(!CheckValidCharacters(document.getElementById("contactPerson").value))
							{
								document.getElementById("contactTitleError").innerHTML="Invalid Data Entry";
								document.getElementById("contactTitle").focus();
								return false;
							}
							*/
							if(document.getElementById("contactTitle").value=='')
							{
								document.getElementById("contactTitleError").innerHTML="Field Required";
								document.getElementById("contactTitle").focus();
								return false;
							}
							else if (!CheckSpaces(document.getElementById("contactTitle").value))
							{
								document.getElementById("contactTitleError").innerHTML="Invalid Data Entry";
								document.getElementById("contactTitle").focus();
								return false;
							}
							/*else if(!CheckValidCharacters(document.getElementById("contactTitle").value))
							{
								document.getElementById("contactTitleError").innerHTML="Invalid Data Entry";
								document.getElementById("contactTitle").focus();
								return false;
							}	*/
		
							if(document.getElementById("userName").value=='')
							{
								document.getElementById("userNameError").innerHTML="Field Required";
								document.getElementById("userName").focus();
								return false;
							}
							else if (!CheckSpaces(document.getElementById("userName").value))
							{
								document.getElementById("userNameError").innerHTML="Invalid Data Entry";
								document.getElementById("userName").focus();
								return false;
							}
							else if(!CheckValidCharacters(document.getElementById("userName").value))
							{
								document.getElementById("userNameError").innerHTML="Invalid Data Entry";
								document.getElementById("userName").focus();
								return false;
							}
							
							
							
							 ChechUserName()
						}						
							
							
							
						}
					});
			//return check;
			}
		function CheckAvailableEmail()
		{
			var check3=""
			var url = 'GUIService/UserService.php?action=checkEmailAddress'; 
			var par='email='+document.getElementById("email").value;
			var myRequest= new Ajax.Request(
							url, 
							{   
							method: 'post',
							parameters:par,
							onSuccess: function(transport) 
							{      
								if(transport.responseText > 0)
									{
									  check3=0;
									  document.getElementById("emailError").innerHTML="Email address already registered";
									  document.getElementById("email").focus();
									 return false;
									}	
									else
									{
									  check3=1;
									}
									
									if(check3==1)
									{
										
										
										if(document.getElementById('cmbIndustry').value=='')
										{
											document.getElementById("cmbIndustry").focus();
											document.getElementById("industryError").innerHTML="Field Required";
											return false;
										}
										if(document.getElementById('employees').value=='')
 										{
											document.getElementById("employees").focus();
											document.getElementById("employeesError").innerHTML="Field Required";
											return false;
										}
											
										if(!CheckNumbers(document.getElementById('employees').value))
										{
											document.getElementById("employees").focus();
											document.getElementById("employeesError").innerHTML="Invalid data entry.";
											return false; 
										}
								
									    if(document.getElementById('address').value=='')
									    {
										document.getElementById("address").focus();
										document.getElementById("addressError").innerHTML="Field Required";
										return false;
										}
										
										else 
										{
											if(!CheckSpaces(document.getElementById("address").value))
											{
												document.getElementById("address").focus();
												document.getElementById("addressError").innerHTML="Invalid Data Entry";
												return false;
											}
											else
											{
												document.getElementById("addressError").innerHTML="";
											}
										}
										if(document.getElementById('city').value=='')
										{
											document.getElementById("city").focus();
											document.getElementById("cityError").innerHTML="Field Required";
											return false;
										}
										else
										{
											if(!CheckSpaces(document.getElementById("city").value))
											{
												document.getElementById("city").focus();
												document.getElementById("cityError").innerHTML="Invalid Data Entry";
												return false;
											}
											else
											{
												document.getElementById("cityError").innerHTML="";
											}
										}
										
										if((document.getElementById('cmbCountry').value==3)&&(document.getElementById('cmbState').value==''))
										{
											document.getElementById("cmbState").focus();
											document.getElementById("provinceError").innerHTML="Field Required";
											return false;
										}   
										if(document.getElementById('cmbCountry').value=='')
										{
											document.getElementById("cmbState").focus();
											document.getElementById("countryError").innerHTML="Field Required";
											 return false;
										}
										if(document.getElementById('zipCode').value.length<5)
										{
											document.getElementById("zipCode").focus();
											document.getElementById("zipCodeError").innerHTML="Invalid data entry, please enter the correct code";
											return false;
										}
										if(!CheckNumbers(document.getElementById('zipCode').value))
										{
											document.getElementById("zipCode").focus();
											document.getElementById("zipCodeError").innerHTML="Invalid data entry, please enter the correct code";
											return false; 
										}
										if(document.getElementById('phone1part1').value==''|| document.getElementById('phone1part2').value==''||document.getElementById('phone1part3').value=='')
										{		
											document.getElementById("phoneError").innerHTML="Field Required";
											document.getElementById('phone1part1').focus();
											return false;	
										}
										if(!CheckNumbers(document.getElementById('phone1part1').value)||!CheckNumbers(document.getElementById('phone1part2').value)||!CheckNumbers(document.getElementById('phone1part3').value))
										{
											document.getElementById("phoneError").innerHTML="Invalid Data Entry";
											document.getElementById('phone1part1').focus();
											return false;
										}
										var pIntPhone1 = document.getElementById('phone1part1').value+document.getElementById('phone1part2').value+document.getElementById('phone1part3').value;
										if(pIntPhone1.length<10)
										{
											 document.getElementById("phoneError").innerHTML="Invalid Data Entry";
											 document.getElementById('phone1part1').focus();
											 return false;
										}
										else
										{
											document.getElementById("phoneError").innerHTML="";
										}
										if(document.getElementById('phone2part1').value!='')//||document.getElementById('phone2part2').value!=''||document.getElementById('phone2part3').value!='')
										{
											if(!CheckNumbers(document.getElementById('phone2part1').value)||!CheckNumbers(document.getElementById('phone2part2').value)||!CheckNumbers(document.getElementById('phone2part3').value))
											{
												document.getElementById("phone2Error").innerHTML="Invalid Data Entry";
												document.getElementById('phone2part1').focus();
												return false;
											}
											var pIntPhone2 = document.getElementById('phone2part1').value+document.getElementById('phone2part2').value+document.getElementById('phone2part3').value;
											if(pIntPhone2.length<10)
											{
												document.getElementById("phone2Error").innerHTML="Invalid Data Entry";
												document.getElementById('phone2part1').focus();
												return false;
											}
											else
											{
												document.getElementById("phone2Error").innerHTML="";
												SaveData();
												
												
											}
										}
										
										else
										{
										  SaveData();
										}
										//return true;
									}
									else
									{
										
										//return true;
									}
								}
							});
		//return  true;	
		}
	