	function SavePrimaryContact()
	{
		SavePartnerships();	
		SaveCertification();
		SaveAffiliation();
		SaveNewsletter();
	}
	
	//Save Partnerships Informations
	function SaveNewsletter()
	{
		//Get Input Hidden
		var hNewsletter = document.getElementById("hNewsletter");				
		//Populate Checkbox Pertnerships
		var newsletter = document.getElementsByName("newsletter");				
		//Get Checkbox Length
		
		var Length = newsletter.length;
		//Find Partnerships Checked
		
		var TempPartnerships = "";
		for (var i = 0; i < Length; i++)
		{
			if(newsletter[i].checked == true)
			{
				TempPartnerships += newsletter[i].id + "," + newsletter[i].value + "#";
				
			}
		}
		//Save to temp Table
		TempPartnerships = TempPartnerships.substring(0, TempPartnerships.length - 1);
		
		//Save to Input Hidden
		hNewsletter.value = TempPartnerships;	
		
	}
	function SavePartnerships()
	{
		//Get Input Hidden
		var hPartnerships = document.getElementById("hPartnerships");				
		//Populate Checkbox Pertnerships
		var Partnerships = document.getElementsByName("cbPartnerships");				
		//Get Checkbox Length
		
		var Length = Partnerships.length;
		//Find Partnerships Checked
		
		var TempPartnerships = "";
		for (var i = 0; i < Length; i++)
		{
			if(Partnerships[i].checked == true)
			{
				TempPartnerships += Partnerships[i].id + "," + Partnerships[i].value + "#";
				
			}
		}
		//Save to temp Table
		TempPartnerships = TempPartnerships.substring(0, TempPartnerships.length - 1);
		
		//Save to Input Hidden
		hPartnerships.value = TempPartnerships;	
		
	}
	function SaveCertification()
	{
		//Get Input Hidden
		var hCertification = document.getElementById("hCertification");				
		//Populate Checkbox Pertnerships
		var Certificate = document.getElementsByName("cbCertificate");				
		//Get Checkbox Length
		
		var Length = Certificate.length;
		
		//Find Partnerships Checked
		var TempCertificate = "";
		for (var i = 0; i < Length; i++)
		{
			if(Certificate[i].checked == true)
			{
				TempCertificate += Certificate[i].id + "," + Certificate[i].value + "#";
				
			}
		}
		//Save to temp Table
		TempCertificate = TempCertificate.substring(0, TempCertificate.length - 1);
		
		//Save to Input Hidden
		hCertification.value = TempCertificate;		
		
	}
	function SaveAffiliation()
	{
		//Get Input Hidden
		var hAffiliations = document.getElementById("hAffiliations");				
		//Populate Checkbox Pertnerships
		var affiliation = document.getElementsByName("Affiliations");				
		//Get Checkbox Length
		var Length = affiliation.length;
		//Find Partnerships Checked
		var Tempaffiliation = "";
		for (var i = 0; i < Length; i++)
		{
			if(affiliation[i].checked == true)
				Tempaffiliation += affiliation[i].id + "," + affiliation[i].value + "#";
		}
		//Save to temp Table
		Tempaffiliation = Tempaffiliation.substring(0, Tempaffiliation.length - 1);
		
		//Save to Input Hidden
		hAffiliations.value = Tempaffiliation;		
	}
	function ShowPrimaryContact()
	{
		var sPrimaryContact = document.getElementById("sprimarycontact");
		
		//Check to The Last Control if null it's mean the all control not yet Rendered otherwise the control is rendered and bind data to that control
		//Content Not yet Rendered
		if(sPrimaryContact == null)
		{
			setTimeout("ShowPrimaryContact();", 300);
		}
		//Content Rendered
		else
		{
			ShowPartnerships();
			ShowCertification();
			ShowAffiliation();
			ShowNewsletter();
		}

	}
	function ShowPartnerships()
	{
		//Get Input Hidden
		var hPartnerships = document.getElementById("hPartnerships");		
		//Check if There is no Partnerships selected				
		if(hPartnerships.value != "" && hPartnerships.value != null)
		{
			//Split Partnerships from Hidden Input		
			var AllPartnerships = hPartnerships.value.split("#");
			//Populate Partnerships Checked
			for(var i = 0; i < AllPartnerships.length; i++)
			{
				//Get Index
				var PartnershipId = AllPartnerships[i].split(",");
				var PartnershipsChecked = document.getElementById(PartnershipId[0]);
				PartnershipsChecked.checked = true;
			}
		}
	}	
	 

	 function ShowNewsletter()
	{
		//Get Input Hidden
		var hNewsletter = document.getElementById("hNewsletter");				
		
		
		//Check if There is no Partnerships selected				
		if(hNewsletter.value != "" && hNewsletter.value != null)
		{
			//Split Partnerships from Hidden Input		
			var AllPartnerships = hNewsletter.value.split("#");
			//Populate Partnerships Checked
			for(var i = 0; i < AllPartnerships.length; i++)
			{
				//Get Index
				var PartnershipId = AllPartnerships[i].split(",");
				var PartnershipsChecked = document.getElementById(PartnershipId[0]);
				PartnershipsChecked.checked = true;
			}
		}
	}	

	function ShowCertification()
	{
		//Get Input Hidden Industry Control
		var hCertification = document.getElementById("hCertification");
		//Check if there is no industry selected

		if(hCertification.value != "" && hCertification.value != null)
		{
			//Split Industry from Input Hidden
			var AllCertification = hCertification.value.split("#");
			//Populate Partnerships Checked
			for(var i = 0; i < AllCertification.length; i++)
			{
				var cbCertificate = AllCertification[i].split(",");
				var CertificationChecked = document.getElementById(cbCertificate[0]);
				CertificationChecked .checked = true;
			}
		}
	}

	function ShowAffiliation()
	{
		//Get Input Hidden Industry Control
		var hAffiliations = document.getElementById("hAffiliations");
		//Check if there is no industry selected
		
		if(hAffiliations.value != "" && hAffiliations.value != null)
		{
			//Split Industry from Input Hidden
			var AllAffiliations = hAffiliations.value.split("#");
			//Populate Partnerships Checked
			for(var i = 0; i < AllAffiliations.length; i++)
			{
				var Affiliations = AllAffiliations[i].split(",");
				var AffiliationsChecked = document.getElementById(Affiliations[0]);
				AffiliationsChecked .checked = true;
			}
		}
	}
	function PrimaryContactValidation()
	{
		//Statue Check
		
		var ValidationPrimaryContact = false;
		var vFirstName = false;
		var vLastName = false;
		var vPhone = false;
		var vFax = false;
		var vTollFree = false;
		var vEmail = false;
		
		//Get All object to be check the value
		var sIndicates = document.getElementById("sIndicates");
		var txtFirstName = document.getElementById("txtFirstName");
		var txtLastName = document.getElementById("txtLastName");
		var txtPhone = document.getElementById("txtPhone");
		//~ var txtFax = document.getElementById("txtFax");
		//~ var txtTollFree = document.getElementById("txtTollFree");
		var txtEmail = document.getElementById("txtEmail");
		
		//get object validation star
		var vtxtFirstName = document.getElementById("vtxtFirstName");
		var vtxtLastName = document.getElementById("vtxtLastName");
		var vtxtPhone = document.getElementById("vtxtPhone");
		//~ var vtxtFax = document.getElementById("vtxtFax");
		//~ var vtxtTollFree = document.getElementById("vtxtTollFree");
		var vtxtEmail = document.getElementById("vtxtEmail");	

		//~ var PatternEmail =  /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
		
		//Check Text FirstName value
		if(txtFirstName.value != null && txtFirstName.value != "")
		{
			vtxtFirstName.style.display = "none";
			vFirstName = true;
		}
		else
		{
			vtxtFirstName.style.display = "";
			vFirstName = false;
		}
		
		//Check Text LastName value
		if(txtLastName.value != null && txtLastName.value != "")
		{
			vtxtLastName.style.display = "none";
			vLastName = true;
		}
		else
		{
			vtxtLastName.style.display = "";
			vLastName = false;
		}
		
		//Check Text Phone value
		if(txtPhone.value != null && txtPhone.value != "")
		{			
			//Check Phone numeric or not
			var checkPhone = IsPhoneNumber(txtPhone.value);
			
			//Phone in numeric format
			if(checkPhone == true)
			{
				vtxtPhone.style.display = "none";			
				vPhone = true;
			}
			//Phone not in numeric format
			else
			{				
				vtxtPhone.style.display = "";				
				vtxtPhone.innerHTML = "* phone must be numeric";
				vPhone = false;
			}
		}
		else
		{
			vtxtPhone.style.display = "";
			vPhone = false;
		}
		
		
		if(PatternEmail.test(txtEmail.value))
		{
			vtxtEmail.style.display = "none";
			vEmail = true;
		}
		else
		{
			vtxtEmail.style.display = "";
			vtxtEmail.innerHTML = "* Invalid email format";
			vEmail = false;
		}
		
		//Check all control have value or not have value
		if(vFirstName == true && vLastName == true && vPhone == true && vEmail == true)
		{
			sIndicates.style.display = "none";
			ValidationPrimaryContact = true;
		}
		else
		{
			sIndicates.style.display = "";
			ValidationPrimaryContact = false;
		}
		
		
		return ValidationPrimaryContact;
	}
	
	function IsPhoneNumber(value)
	{
		//Number
		var validChars  = "0123456789-() ";
		//Get value to check
		var strValue = value;
		//Status value
		var isNumber = true;
		
		for(i = 0; i < strValue.length; i++)
		{
			ch = strValue.charAt(i);
			
			if (validChars.indexOf(ch) == -1) 
				isNumber = false;
		}
		
		return isNumber;
	}


	//=====================================savephoto========================================================
	function ShowPhotoSetup()
	{
		
		//Get input hidden object for show temp value Account Setup
		var hPhotoSetup = document.getElementById("hPhotoSetup");
		var sPhotoSetup = document.getElementById("sphotosetup");
		
		if(sPhotoSetup == null)
		{
			setTimeout("ShowPhotoSetup();", 300);
		}
		//Content Rendered
		//else
		//{
			if(hPhotoSetup.value != "" && hPhotoSetup.value != null)
			{
				
		
				//Split value from input hidden
				var AllValue = hPhotoSetup.value.split("#");
				
				
			}

			//##############################################image
              
			var sUpload = document.getElementById("sUpload");
				//There is A photo uploaded
				if(AllValue[0] != "" && AllValue[0] != "" && AllValue[0].length > 0)
				{					
					//Get span object for render uploaded image
					var sImgPhoto = document.getElementById("sImgPhoto");
					var PhotoName = AllValue[0].split(",");
					
					//There is a 3 photos then hide the span link add more photos, otherwise show the span
					if(PhotoName.length == 3)					
						sUpload.style.display = "none";					
					else
						sUpload.style.display = "";
						
					var RenderedPhotos = "<table><tr>";
					
					for(var i = 0; i < PhotoName.length; i++)
						RenderedPhotos += "<td>" +
											"<div id=\"dEditPhoto" + i + "\">" +
												"<div id=\"dEditPhoto\">" +
													"<a href=\"javascript:RenderControlUpload('Photo');javascript:OpenDialogUpload('EditPhoto" + i + "');\">edit</a>&nbsp;&nbsp;&nbsp;" +
													"<a href=\"javascript:RemovePhoto('dEditPhoto" + i + "')\">Remove</a>" +
												"</div>" +
												"<div id=\"dImgPhoto\" class=\"ImgPhoto\">" + 
													"<table height=\"100%\" width=\"100%\">" +
														"<tr>" +
															"<td>" +
																"<img id=\"imgPhoto" + i + "\" name=\"imgPhoto\" src=\"" + PhotoName[i] + "\" title=\"" + PhotoName[i] + "\"/>" +
															"</td>" +
														"</tr>" +
													"</table>" +
												"</div>" +
											"</div>" + 
										"</td>";
					
					RenderedPhotos += "</tr></table>";										
						
					sImgPhoto.innerHTML = RenderedPhotos;
				}
				else
				{
					sUpload.style.display = "";
				}

				var sUpload = document.getElementById("sUpload");
				//Check if there is a Company Logo
				//There is a company logo
				if(AllValue[1] != null && AllValue[1] != "")
				{
					sUpload.style.display = "none";
					
					if(AllValue[1] != "Upload/no_logo.gif")
					{
						//Get span object for render uploaded image
						var sImgLogo = document.getElementById("sImgLogo");
						//Render Uploaded Logo
						//New Style
						sImgLogo.innerHTML = "<div>" + 
												"<div id=\"dEditLogo\">" +
													"<a href=\"javascript:RenderControlUpload('Logo');javascript:OpenDialogUpload('Logo');\">edit company logo</a>" + 
												"</div>" +
												"<div id=\"dImgLogo\" class=\"ImgLogo\">" +
													"<table height=\"100%\" width=\"100%\">" +
														"<tr>" +
															"<td>" +
																"<img id=\"imgCompanyLogo\" name=\"" + AllValue[1] + "\" src=\"" + AllValue[1] + "\" />" +
															"</td>" +
														"</tr>" +
													"</table>" +
												"</div>" +
										   "</div>";
						
					}
					else
					{
						sUpload.style.display = "";
					}
				}
				//Nothing Company logo
				else
				{
					sUpload.style.display = "";
				}

		//}
	}

	function SavePhotoSetup()
	{
		//Get input hidden object for save temp value Account Setup
		var hPhotoSetup = document.getElementById("hPhotoSetup");		
		
		
		var imgPhoto = document.getElementsByName("imgPhoto");			
		if(imgPhoto.length > 0)
		{
			var PhotoFileName = "";
			for(var i = 0;  i < imgPhoto.length; i++)
			{
				PhotoFileName += imgPhoto[i].title + ",";
			}
			
			PhotoFileName = PhotoFileName.substring(0, PhotoFileName.length - 1);			
			hPhotoSetup.value = PhotoFileName;
		}else{
		   hPhotoSetup.value="Upload/no_logo.gif";
		}
		
		//###########################end##################################################
		var imgCompanyLogo = document.getElementById("imgCompanyLogo");
		//There is the Logo
		if(imgCompanyLogo != null)
			hPhotoSetup.value +="#"+imgCompanyLogo.name;
			//~ hCompanyProfile.value += imgCompanyLogo.name;
		else
			hPhotoSetup.value += "#Upload/no_logo.gif";	
		
		
	}