	function SavePrimaryContact()
	{
		var hPrimaryContact = document.getElementById("hPrimaryContact");
		
		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");
		
		hPrimaryContact.value = txtFirstName.value + "#" + txtLastName.value + "#" + txtPhone.value + "#" + txtFax.value + "#" + txtTollFree.value + "#" + txtEmail.value + "#";
		
		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);
			
			hPrimaryContact.value += PhotoFileName;
		}
	}
	
	function ShowPrimaryContact()
	{
		var hPrimaryContact = document.getElementById("hPrimaryContact");
		
		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");
		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
		{
			if(hPrimaryContact.value != "" && hPrimaryContact.value != null)
			{		
				var AllValue = hPrimaryContact.value.split("#");
				
				txtFirstName.value = DecodeTag(AllValue[0]);
				txtLastName.value = DecodeTag(AllValue[1]);
				txtPhone.value = DecodeTag(AllValue[2]);
				txtFax.value = DecodeTag(AllValue[3]);
				txtTollFree.value = DecodeTag(AllValue[4]);
				txtEmail.value = DecodeTag(AllValue[5]);
				
				var sUpload = document.getElementById("sUpload");
				//There is A photo uploaded
				if(AllValue[6] != "" && AllValue[6] != "" && AllValue[6].length > 0)
				{					
					//Get span object for render uploaded image
					var sImgPhoto = document.getElementById("sImgPhoto");
					var PhotoName = AllValue[6].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 += "<img id=\"" + PhotoName[i] + "\" name=\"imgPhoto\" src=\"" + PhotoName[i] + "\" /><br/>" +
										      //~ "<a href=\"javascript:RenderControlUpload('Photo');javascript:OpenDialogUpload('EditPhoto" + i + "');\">edit</a><br/><br/><br/>";
										      
					sImgPhoto.innerHTML = RenderedPhotos;
				}
				else
				{
					sUpload.style.display = "";
				}
			}
		}
	}
	
	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;
		}
		
		//~ //Check Text Fax value
		//~ if(txtFax.value != null &&  txtFax.value != "")
		//~ {
			//~ //Check Fax numeric or not
			//~ var checkFax = IsPhoneNumber(txtPhone.value);
			
			//~ //Fax in numeric format
			//~ if(checkFax == true)
			//~ {
				//~ vtxtFax.style.display = "none";
				//~ vFax = true;
			//~ }
			//~ //Fax not in numeric format
			//~ else
			//~ {				
				//~ vtxtFax.style.display = "";
				//~ vtxtFax.innerHTML = "* fax must be numeric";
				//~ vFax = false;
			//~ }
		//~ }
		//~ else
		//~ {
			//~ vtxtFax.style.display = "";
			//~ vFax = false;
		//~ }
		
		//~ //Check Text Toll Free value
		//~ if(txtTollFree.value != null &&  txtTollFree.value != "")
		//~ {
			//~ vtxtTollFree.style.display = "none";
			//~ vTollFree = true;
		//~ }
		//~ else
		//~ {
			//~ vtxtTollFree.style.display = "";
			//~ vTollFree = false;
		//~ }
		
		//Email True format
		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;
	}