        //Variable for xmlHttpRequest
	var xmlhttpRequestPage;
	
	//Index of Page
	var IndexPage = 0;
	var MyPages = new Array();
	MyPages[0] = "home.php";
	MyPages[1] = "accountsetup.php";
	MyPages[2] = "company.php";
	MyPages[3] = "companyprofile.php";
	MyPages[4] = "primarycontact.php";
	MyPages[5] = "servicearea.php";
	MyPages[6] = "servicecapabilities.php";
	MyPages[7] = "submit.php";
	MyPages[8] = "loginpage.php";
	
	var PatternEmail =  /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
	var AccountSetupToConfirmation = false;
	
	function FirstLoad()
	{
		//Go to Home Page
		IndexPage = 0;
		RequestPage(MyPages[IndexPage]);
		//Hide Div with content button continue
		var divContent = document.getElementById("content2");
		divContent.style.display = "none";
		
		// value on Input Hidden
		ClearValueOnInputHidden();
	}
	
	function Register()
	{
		//Go to register page
		IndexPage = 1;
		RequestPage(MyPages[IndexPage]);
		//Show Div with content button continue
		var divContent2 = document.getElementById("content2");
		divContent2.style.display = "";
		//Change to Continue
		var btnContinue = document.getElementById("btnContinue");
		btnContinue.value = "Continue";
		btnContinue.src = "Images/continue_but.gif";
	}
	
	function LoginPage()
	{
		//Go to LoginPage			
		IndexPage = 8;
		RequestPage(MyPages[IndexPage]);
		//Hide Div with content button continue
		var divContent = document.getElementById("content2");
		divContent.style.display = "none";
	}
	
	function GoToConfirmation()
	{
		//Account Setup Page
		if(IndexPage == 1)
			AccountSetupToConfirmation = true;
			
		var CheckValidation = ValidationInput();
		
		if(CheckValidation == true)
		{
			//Get Button Continue Id
			var btnContinue = document.getElementById("btnContinue");
			//Change Button Continue value
			btnContinue.value = "Submit";
			btnContinue.src = "Images/submit_but.gif";
			
			//Save Value Information to Hidden Input
			SaveValue();				
			
			IndexPage = 7;
			
			//Request Confirmation Page
			RequestPage(MyPages[IndexPage]);
			//Show Confirmation
			ShowConfirmation('register');
			//hide click here
			var sGoToConfirmation = document.getElementById("sGoToConfirmation");
			sGoToConfirmation.style.display = "none";
		}
	}

	function btnBack()
	{			
		var btnBack = document.getElementById("btnBack");
		var btnContinue = document.getElementById("btnContinue");

		//Save the Current Page and Go to the Previous Page
		SaveValue();		
		
		//Check Register or Editing
		var CheckedRegOrEdit = CheckRegOrEdit();
			
		//Editing Page then Show Service Area / Additional Location
		if(!CheckedRegOrEdit && IndexPage == 6)
			//Decrease Index Page
			IndexPage -= 2;
		//Register Page then skip Service Area / Additional Location
		else
			IndexPage -= 1;			
		
		//Request Previous Page
		RequestPage(MyPages[IndexPage]);
		
		//Not Last page and Change to Continue
		if(IndexPage != 7)
		{
			btnContinue.value = "Continue";
			btnContinue.src = "Images/continue_but.gif";
		}
		
		//Hide Back Button
		if(IndexPage == 1)
			btnBack.style.display = "none";		
		
		//Set Time Out to 300 milisecond and Show Value Information From Hidden Input after 300 Milisecond
		setTimeout("ShowValue();", 300);
	}
	
	function btnContinue()
	{			
		var btnBack = document.getElementById("btnBack");		
		var btnContinue = document.getElementById("btnContinue");
		var CheckValidation = ValidationInput();
		
		if(CheckValidation == true)
		{
			//Save Value Information to Hidden Input
			SaveValue();
			
			//Insert Registration value to database
			if(btnContinue.value == "Submit")
			{
				Insert();
				return;
			}
		
			//Check Register or Editing
			var CheckedRegOrEdit = CheckRegOrEdit();
			
			//Editing Page then Show Service Area / Additional Location
			if(!CheckedRegOrEdit && IndexPage == 4)
				//Increase Index Page
				IndexPage += 2;
			//Register Page then skip Service Area / Additional Location
			else
				IndexPage += 1;
			
			//Request Next Page
			RequestPage(MyPages[IndexPage]);
			
			//alert(IndexPage);
		
			//Last Page change Continue to Submit
			if(IndexPage == 7)
			{
				btnContinue.value = "Submit";
				btnContinue.src = "Images/submit_but.gif";				
			}
			
			//~ alert(IndexPage);
			
			//Show Back Button
			if(IndexPage != 1)
				btnBack.style.display = "";
			
			//Set Time Out to 300 milisecond and Check Value Hidden  Input, if not null than show the value
			setTimeout("CheckValueInputHidden();", 300);
		}
	}
	
	function SaveValue()
	{			
		//Account Setup Information
		if(IndexPage == 1)				
			SaveAccountSetup();
			
		//Company Information
		else if(IndexPage == 2)
			SaveCompany();
			
		//Company Profile Information
		else if(IndexPage == 3)
			SaveCompanyProfile();
			
		//Primary Contact Information
		else if(IndexPage == 4)
			SavePrimaryContact();

		//~ //Service Area Information
		//~ else if(IndexPage == 5)
			//~ SaveServiceArea();
			
		//Service Capabilities Information
		else if(IndexPage == 6)
			SaveServiceCapabilities();
	}	
	
	function ShowValue()
	{
		//Account Setup Information
		if(IndexPage == 1)
			ShowAccountSetup();
			
		//Company Information
		else if(IndexPage == 2)				
			ShowCompany();
			
		//Company Profile Information
		else if(IndexPage == 3)
			ShowCompanyProfile();
			
		//Primary Contact Information
		else if(IndexPage == 4)
			ShowPrimaryContact();
			
		//Service Area Information
		else if(IndexPage == 5)			
			ShowServiceArea();
			//~ //If on Page Service Area then Check the Button Add More				
			//~ btnAddMore();			

		//Service Capabilities Information
		else if(IndexPage == 6)
			ShowServiceCapabilities();
	}
	
	function ValidationInput()
	{
		var Validation = true;
		
		//Check Validation Account Setup
		if(IndexPage == 1)
			Validation = AccountValidation();
		
		//Check Validation Company Information
		else if(IndexPage == 2)
			Validation = CompanyValidation();
			
		//Check Validation Company Profile
		else if(IndexPage == 3)
			Validation = CompanyProfileValidation();
		
		//Check Validation Primary Contact
		else if(IndexPage == 4)
			Validation = PrimaryContactValidation();
		
		//~ else if(IndexPage == 6)
			//~ Validation = ServiceCapabilitiesValidation();
		
		return Validation;
	}
	
	//Check Value Hidden  Input, if not null than show the value
	function CheckValueInputHidden()
	{
		//Company Information
		if(IndexPage == 2)
			ShowCompany();
			
		//Company Profile Information
		else if(IndexPage == 3)
			ShowCompanyProfile();
			
		//Primary Contact information
		else if(IndexPage == 4)
			ShowPrimaryContact();
			
		//Service Area Information
		else if(IndexPage == 5)
			ShowServiceArea();
			//~ //If on Page Service Area then Check the Button Add More				
			//~ btnAddMore();
			
		//Service Capabilities Information
		else if(IndexPage == 6)
			ShowServiceCapabilities();
			
		//Show All value input to Confirmation Page
		else if(IndexPage == 7)
			ShowConfirmation('register');
	}
	
	function ClearValueOnInputHidden()
	{
		var hAccountSetup = document.getElementById("hAccountSetup");
		var hCompany = document.getElementById("hCompany");			
		var hLanguageSupport = document.getElementById("hLanguageSupport");
		var hCompanyProfile = document.getElementById("hCompanyProfile");
		var hPrimaryContact = document.getElementById("hPrimaryContact");
		var hServiceArea = document.getElementById("hServiceArea");
		var hIndustry = document.getElementById("hIndustry");
		var hServiceVar = document.getElementById("hServiceVar");
		var hPartnerships = document.getElementById("hPartnerships");
		
		hAccountSetup.value = "";
		hCompany.value = "";
		hLanguageSupport.value = "";
		hCompanyProfile.value = "";
		hPrimaryContact.value = "";
		hServiceArea.value = "";
		hIndustry.value = "";
		hServiceVar.value = "";
		hPartnerships.value = "";
	}	

	//Edit Specific Information From Confirmation Page
	function EditConfirmation(id)
	{
		//Get Object Button Edit
		var btnEdit = document.getElementById(id);
		//Get Button Edit Id
		var btnEditId = btnEdit.id;		
		//Get Index of Page and Convert to Int
		IndexPage = parseInt(btnEditId.substring(btnEditId.length - 1, btnEditId.length));
		
		//When edit company clicked change to Account Setup Page
		if(IndexPage == 2)
			IndexPage = 1;
		
		RequestPage(MyPages[IndexPage]);
		
		//Show Account Setup Information
		if(IndexPage == 1)
			setTimeout("ShowAccountSetup();", 300);
		
		//Show Company Information
		if(IndexPage == 2)
			setTimeout("ShowCompany();", 300);			
			
		//Show Company Profile Information
		else if(IndexPage == 3)
			setTimeout("ShowCompanyProfile();", 300);
			
		//Show Primary Contact Information
		else if(IndexPage == 4)
			setTimeout("ShowPrimaryContact();", 300);
			
		//Show Service Area Information
		else if(IndexPage == 5)
			setTimeout("ShowServiceArea();", 300);
		
		//Show Service Capabilities Information
		else if(IndexPage == 6)
			setTimeout("ShowServiceCapabilities();", 300);
		
		var btnBack = document.getElementById("btnBack");
		var btnContinue = document.getElementById("btnContinue");
		
		btnContinue.value = "Continue";
		btnContinue.src = "Images/continue_but.gif";
		
		//Hide Back Button
		if(IndexPage == 1)
			btnBack.style.display = "none";
	}
	
	function OpenDialogUpload(Type)
	{		
		
		//Get iFrame Object
		var iFrameUpload = document.getElementById("imgUpload");
		//Get Company Name
		var hCompany = document.getElementById("hCompany");
		var AllValue =  hCompany.value.split("#");
		var CompanyName = iFrameUpload.contentWindow.document.getElementById("CompanyName");
		var lAddMorePhoto = iFrameUpload.contentWindow.document.getElementById("lAddMorePhoto");
		//Check if iFrame Content is Rendered
		if(lAddMorePhoto == null)
		{
			setTimeout("OpenDialogUpload('" + Type + "');", 300);
		}
		else
		{
			//Set Company Name inside iFrame
			CompanyName.value = AllValue[0];
			iFrameUpload.contentWindow.document.getElementById("LogoOrPhoto").value = Type;				
			//Type Upload is Logo or Photo, if Logo the Hide btnAddMOre otherwise Show btnAddMore
			if(Type == "Logo")
				iFrameUpload.contentWindow.document.getElementById("lAddMorePhoto").style.display = "none";
			else if(Type == "Photo")
				//~ iFrameUpload.contentWindow.document.getElementById("lAddMorePhoto").style.display = "";
				iFrameUpload.contentWindow.document.getElementById("lAddMorePhoto").style.display = "none";
			else
				iFrameUpload.contentWindow.document.getElementById("lAddMorePhoto").style.display = "none";
				
			revealModal('modalPage2', '');
		}
	}
	
	function CloseDialogUpload()
	{
		//Hide Modal
		hideModal('modalPage2');
	}
	
	//Upload Control
	function RenderControlUpload(Type)
	{
		var TitleUploadControl = "";
		
		if(Type == "Logo")
			TitleUploadControl = "<span id=\"TitleUpload\">Upload your company logo</span>";
		else
			TitleUploadControl = "<span id=\"TitleUpload\">Upload Your Photo</span>";
		
		var ModalContainer2 = document.getElementById("modalContainer2");
		ModalContainer2.innerHTML = 	//"<div id=\"boxUpload\">" + 
									"<div id=\"headerUpload\">" + TitleUploadControl + "<a href=\"javascript:CloseDialogUpload();\" /><img src=\"Images/close.png\" border=\"0\" style=\"float:right;margin-top:-15px;\" /></a></div>" + 
									"<iFrame id=\"imgUpload\" name=\"imgUpload\" src=\"controlupload.php\" frameborder=\"no\" style=\"width:350px;height:110px;\">" +
									"</iFrame>";
								//"</div>";			
	}
	
	function SaveUploadCompanyLogo(Status, FileName)
	{
		if(Status == "success")
		{
			//Hide Modal
			hideModal('modalPage2');			
			
			//Get span object for render uploaded image
			var sImgLogo = document.getElementById("sImgLogo");
			//Clear First
			sImgLogo.innerHTML = "";
			//~ //Render Uploaded Logo
			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=\"" + FileName + "\" src=\"" + FileName + "\" />" +
												"</td>" +
											"</tr>" +
										"</table>" +
									"</div>" +
							   "</div>";
			
			//Hide Link to show Upload dialog
			var sUpload = document.getElementById("sUpload");
			sUpload.style.display = "none";
		}
		else if(Status == "wrongformat")
		{
			alert("Only support jpg, jpeg, and gif.");
			CloseDialogUpload();
		}
		else
		{
			alert("Error Upload Logo");
			CloseDialogUpload();
		}
	}
	
	function SaveUploadPhotos(Status, FileName)
	{			
		if(Status == "success")
		{
			//Hide Modal
			hideModal('modalPage2');
			
			//Get span object for render uploaded image
			var sImgPhoto = document.getElementById("sImgPhoto");
			//Split File Name Photo Uploaded
			var AllFileName = FileName.split(",");
			
			var RenderedPhotos = "<table><tr>";
			//Render Uploaded Photo
			for(var i = 0; i < AllFileName.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=\"" + AllFileName[i] + "\" />" +
													"</td>" +
												"</tr>" +
											"</table>" +
										"</div>" +
									"</div>" + 
								"<td/>";
								      
			RenderedPhotos += "</tr></table>";
			
			//render photos
			sImgPhoto.innerHTML = RenderedPhotos;
			
			//Hide Link to show Upload dialog
			var sUpload = document.getElementById("sUpload");
			sUpload.style.display = "none";
		}
		else if(Status == "wrongformat")
		{
			alert("Only support jpg, jpeg, and gif.");
			CloseDialogUpload();
		}
		else
		{
			alert("Error Upload Photo");
			CloseDialogUpload();
		}
	}
	
	function SaveUploadPhotos2(Status, FileName)
	{
		if(Status == "success")
		{
			//Hide Modal
			hideModal('modalPage2');
			
			//Get span object for render uploaded image
			var sImgPhoto = document.getElementById("sImgPhoto");
			
			//Check there is a image photo
			var imgPhoto = document.getElementsByName("imgPhoto");
			
			//Get Span Link to add more photos
			var sUpload = document.getElementById("sUpload");
			
			//There is a 3 photos then hide the span link add more photos, otherwise show the span
			if(imgPhoto.length == 2)
				sUpload.style.display = "none";
			else
				sUpload.style.display = "";
			
			var RenderedPhotos = "<table><tr>";
			
			var i = 0;
			
			//There is an image photo
			if(imgPhoto.length >= 0)
			{
				//Take the current photo and Render again
				for(i = 0; i < imgPhoto.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=\"" + imgPhoto[i].title + "\" title=\"" + imgPhoto[i].title + "\"/>" +
														"</td>" +
													"</tr>" +
												"</table>" +
											"</div>" +
										"</div>" + 
									"<td/>";						
				}
				
				//The Last Photo take from the last upload
				i = imgPhoto.length + 1;
			}
			
			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=\"" + FileName + "\" title=\"" + FileName + "\"/><br/>" +
												"</td>" +
											"</tr>" +
										"</table>" +
									"</div>" +
								"</div>" + 
							"<td/>";
			
			RenderedPhotos += "</tr></table>";
			
			//render photos
			sImgPhoto.innerHTML = RenderedPhotos;
		}
		else if(Status == "wrongformat")
		{
			alert("Only support jpg, jpeg, and gif.");
			CloseDialogUpload();
		}
		else
		{
			alert("Error Upload Photo");
			CloseDialogUpload();
		}
	}
	
	function SaveEditPhoto(Status, FileName, Index)
	{			
		if(Status == "success")
		{
			//Hide Modal
			hideModal('modalPage2');
			
			//~ var imgPhoto = document.getElementsByName("imgPhoto");
			//~ imgPhoto[Index].id = FileName;
			//~ imgPhoto[Index].src = FileName;
			
			var imgId = "imgPhoto" + Index;
			var imgPhoto = document.getElementById(imgId)
			imgPhoto.title = FileName;
			imgPhoto.src = FileName;
		}
		else if(Status == "wrongformat")
		{
			alert("Only support jpg, jpeg, and gif.");
			CloseDialogUpload();
		}
		else
		{
			alert("Error Upload Photo");
			CloseDialogUpload();
		}
	}
	
	function RemovePhoto(id)
	{
		//Get Img Photo to be remove
		var RemovePhoto = document.getElementById(id);
		//Clear Photo
		RemovePhoto.innerHTML = "";
		
		//Check there is a image photo
		var imgPhoto = document.getElementsByName("imgPhoto");
		
		//Get Span Link to add more photos
		var sUpload = document.getElementById("sUpload");
	
		//There is a 3 photos then hide the span link add more photos, otherwise show the span
		if(imgPhoto.length < 3)
			sUpload.style.display = "";
	}
	
	function ViewProfile(ProfileType, AccountSetup, Company, LanguageSupport, CompanyProfile, PrimaryContact, ServiceArea, ServiceVar, Partnerships, Industry)
	{
		//Get All Object
		var hAccountSetup = document.getElementById('hAccountSetup');
		var hCompany = document.getElementById("hCompany");
		var hLanguageSupport = document.getElementById("hLanguageSupport");
		var hCompanyProfile = document.getElementById("hCompanyProfile");
		var hPrimaryContact = document.getElementById("hPrimaryContact");
		var hServiceArea = document.getElementById("hServiceArea");
		var hIndustry = document.getElementById("hIndustry");
		var hServiceVar = document.getElementById("hServiceVar");
		var hPartnerships = document.getElementById("hPartnerships");
		
		//Bind all value from database to hidden input
		hAccountSetup.value = DecodeTag(AccountSetup);
		hCompany.value = DecodeTag(Company);
		hLanguageSupport.value = LanguageSupport;
		hCompanyProfile.value= DecodeTag(CompanyProfile);
		hPrimaryContact.value = DecodeTag(PrimaryContact);
		hServiceArea.value = DecodeTag(ServiceArea);
		hIndustry.value = Industry;
		hServiceVar.value = ServiceVar;
		hPartnerships.value = Partnerships;
		
		//~ alert(hAccountSetup.value);
		//~ alert(hCompany.value);
		//~ alert(hLanguageSupport.value);
		//~ alert(hCompanyProfile.value);
		//~ alert(hPrimaryContact.value);
		//~ alert(hServiceArea.value);
		//~ alert(hIndustry.value);
		//~ alert(hServiceVar.value);
		//~ alert(hPartnerships.value);
		
		if(ProfileType == "viewprofile")
		{
			//Hide Back and Continue Button
			var divcontent2 = document.getElementById("content2");
			divcontent2.style.display = "none";
		}
		
		//Get object btnBack and btnContinue
		var btnBack = document.getElementById("btnBack");		
		var btnContinue = document.getElementById("btnContinue");
		//Set Index Page to Confirmation Page
		IndexPage = 7;
		//Show btnBack and Change btnContinue to Submit
		btnBack.style.display = "";
		btnContinue.value = "Submit";
		btnContinue.src = "Images/submit_but.gif";			
		
		//~ //Show on Confirmation Format
		ShowConfirmation(ProfileType);
	}		

	function RequestPage(url)
	{
		var sGoToConfirmation = document.getElementById("sGoToConfirmation");
		var ComponentId = "s" + url.substring(0,  url.length - 4);
		
		if(ComponentId != "shome")
			//~ //Show Modal Background
			revealModal('modalPage', ComponentId);
		
		//~ //Out function, don't request page
		//~ if(ComponentId == "sHome")
			//~ return;
			
		//~ //Check Register or Editing
		var CheckedRegOrEdit = CheckRegOrEdit();
		
		//Hide Click Here
		if(!CheckedRegOrEdit)
			sGoToConfirmation.style.display = "none";
		//Show Click Here
		else
			sGoToConfirmation.style.display = "";
		
		xmlhttpRequestPage=null;
		// code for Mozilla, etc.
		if (window.XMLHttpRequest)
		  {
			xmlhttpRequestPage=new XMLHttpRequest();					
		  }
		// code for IE
		else if (window.ActiveXObject)
		  {
			xmlhttpRequestPage=new ActiveXObject("Microsoft.XMLHTTP");					
		  }
		if (xmlhttpRequestPage!=null)
		  {
			  xmlhttpRequestPage.onreadystatechange=state_Change;
			  xmlhttpRequestPage.open("GET",url,true);
			  xmlhttpRequestPage.send(null);				
		  }
		else
		  {
			alert("Your browser does not support XMLHTTP.");
		  }
	}
	
	function state_Change()
	{				
		//readyState, 0 = uninitialized
		//		1 = loading
		//		2 = loaded
		//		3 = interactive
		//		4 = complete
		
		//Completed Request
		if (xmlhttpRequestPage.readyState==4)
		  {
			// Status value just 404 and 200, 404 = "Not Found" & 200 = "Ok"					
			if (xmlhttpRequestPage.status==200)
			{				
				//Get Response from next page
				var ResponsePage = xmlhttpRequestPage.responseText;	// response
				//~ alert(ResponsePage);
				//Get Div Content
				var Content = document.getElementById("content");				
				//Render response from Next Page
				Content.innerHTML = ResponsePage;
			}
			else
			{
				alert("Problem retrieving data");
			}
		  }
	}
	
	function CaptureEvent(evt)
	{
		evt = (evt) ? evt : event;
		var charCode = (evt.which) ? evt.which : evt.keyCode;
		//If Press Enter the begin Search
		if(charCode==13)
			Search2();
	}		

	function DecodeTag(str)
	{		
		var decodedStr = str.replace(/&lt;/g, "<");
		decodedStr = decodedStr.replace(/&gt;/g, ">");
		decodedStr = decodedStr.replace(/&amp;/g, "&");
		decodedStr = decodedStr.replace(/&apos;/g, "'");
		decodedStr = decodedStr.replace(/&quot;/g, '"');
		decodedStr = decodedStr.replace(/\n;/g, ' ');
		decodedStr = decodedStr.replace(/\r;/g, ' ');
		decodedStr = decodedStr.replace(/\t;/g, ' ');
		return decodedStr;
	}
	
	function EncodeIllegalChar(str)
	{
		var encodeStr = str.replace(/</, "&lt;");
		encodeStr = encodeStr.replace(/>/, "&gt;");
		encodeStr = encodeStr.replace(/&/, "&amp;");
		encodeStr = encodeStr.replace(/'/, "&apos;");
		encodeStr = encodeStr.replace(/"/, "&quot;");
		//Replace New Line
		encodeStr = encodeStr.replace(/\n/, " ");
		encodeStr = encodeStr.replace(/\r/, " ");
		encodeStr = encodeStr.replace(/\t/, " ");
		return encodeStr;
	}
	
	function ReplaceIllegalChar(str)
	{
		var replacestr = str.replace(/&/, "|");
		
		for(var i = 0; i < 100; i++)
			replacestr = replacestr.replace(/&/, "|");
			
		return replacestr;
	}
	
	function CheckRegOrEdit()
	{
		var CheckedRegOrEdit = false;
		var fullURL = parent.document.URL;
		var qs = fullURL.split('?');
		var cid = "";
		if(qs.length > 1)
		{
			queryStr = qs[1].split('&');
			for(var i=0; i<queryStr.length; i++)
			{
				key = queryStr[i].split('=');
				if(key[0] =="cid")
					cid = key[1];
			}			
		}
	
		if (cid != "")
			CheckedRegOrEdit = true;
			
		return CheckedRegOrEdit;
	}
	
	function IsNumeric(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;
	}
	
	//<![CDATA[
		var ASCIIGMap = null;
		var ASCIIGeocoder = null;
		var Center;
		
		function CompanyLocation(ZipCode)
		{				
			if (GBrowserIsCompatible())
			{
				ASCIIGMap = new GMap2(document.getElementById("ASCIIGMap"));
				ASCIIGeocoder = new GClientGeocoder();
				
				ASCIIGeocoder.getLatLng(ZipCode, function(point)
									{
										if (point)
										{
											if (Center)
											{	
												//Remove Marker
												Center.removeOverlay( Center );
											}
											
											//Set Center Point
											ASCIIGMap.setCenter(point, 13);
											//Give Marker on Google Map
											var ASCIIMarker = new GMarker(point);
											ASCIIGMap.addOverlay(ASCIIMarker);
										}
									});
			}
		}
		
		function CompanyLocation2(Latitude, Longitude)
		{				
			
			if (GBrowserIsCompatible())
			{
				//Get div for render google map
				ASCIIGMap = new GMap2(document.getElementById("ASCIIGMap"));					
				//Set Center Point
				ASCIIGMap.setCenter(new GLatLng(Latitude, Longitude), 13);
				//Give Marker on Google Map
				var ASCIIMarker = new GMarker( new GLatLng(Latitude, Longitude));
				ASCIIGMap.addOverlay(ASCIIMarker);
			}
		}
	//]]>
	
	
	//============================================================================================= Lost Password =======================================================================================================================
	//=================================================================================================================================================================================================================================
	var xmlhttpSendEmailLostPassword;
	
	function CaptureEventLostPassword(evt)
	{
			evt = (evt) ? evt : event;
			var charCode = (evt.which) ? evt.which : evt.keyCode;
			//If Press Enter the begin Search
			if(charCode==13)
				SendEmailLostPassword();
	}
	
	function LostPasswordPopup(CompanyId, CompanyEmail, CompanyName, toContactName)
	{	
		var txtEmailLostPassword = document.getElementById("txtEmailLostPassword");
		var sEmailProgressLP = document.getElementById("sEmailProgressLP");
		var imgProgressLP = document.getElementById("imgProgressLP");
		
		var imgStatusEmailLP = document.getElementById("imgStatusEmailLP");
		var sStatusEmailLP = document.getElementById("sStatusEmailLP");
		
		var sStarEmailLostPassword = document.getElementById("sStarEmailLostPassword");
		
		//Claer Email Value 
		txtEmailLostPassword.value = "";
		
		//Hide email progress
		sEmailProgressLP.style.display = "none";
		imgProgressLP.style.display = "none";

		//Hide Email Status
		imgStatusEmailLP.style.display = "none";
		sStatusEmailLP.style.display = "none";
		sStarEmailLostPassword.innerHTML = "";
		
		window.onscroll = function () 
					{ 
						document.getElementById("modalPageLostPassword").style.top = document.documentElement.scrollTop + "px"; 					
					};      
		document.getElementById("modalPageLostPassword").style.display = "block";    
		document.getElementById("modalPageLostPassword").style.top = document.documentElement.scrollTop + "px";  		
		
		//Check browser name
		if(navigator.appName == "Microsoft Internet Explorer")
		{
			//Get browser version
			var version = navigator.appVersion;
			var versionName = version.substring(22, 25);
			//Check if IE version 6.0
			if(versionName == "6.0")
			{					
				var dModalPageLostPassword = document.getElementById("modalPageLostPassword");
				var dModalBackgroundLostPassword = document.getElementById("modalBackgroundLostPassword");
				dModalPageLostPassword.style.height = "900px";
				dModalBackgroundLostPassword.style.height = "900px";
			}
		}				
	}

	function CloseLostPasswordPopup()
	{		
		document.getElementById("modalPageLostPassword").style.display = "none";		
	}
	
	function SendEmailLostPassword()
	{		
		var txtEmailLostPassword = document.getElementById("txtEmailLostPassword");
		var sStarEmailLostPassword = document.getElementById("sStarEmailLostPassword");
		
		if(txtEmailLostPassword.value != "")
		{
			sStarEmailLostPassword.innerHTML = "";
			
			//Get Destination Email Address, Subject Email and Email Message	
			var imgProgressLP = document.getElementById("imgProgressLP");
			var sEmailProgressLP = document.getElementById("sEmailProgressLP");
			
			var imgStatusEmailLP = document.getElementById("imgStatusEmailLP");
			var sStatusEmailLP = document.getElementById("sStatusEmailLP");
		
			//Show email progress		
			imgProgressLP.style.display = "";
			sEmailProgressLP.style.display = "";
			//Hide Email Status
			imgStatusEmailLP.style.display = "none";
			sStatusEmailLP.style.display = "none";
			
			var parameter = "emailTo=" + document.getElementById("txtEmailLostPassword").value;		
			RequestSendEmailLostPassword("lostpassword.php", parameter);
		}
		else
		{
			sStarEmailLostPassword.innerHTML = "*";
		}
	}
	
	
	function RequestSendEmailLostPassword(url, parameter)
	{
		xmlhttpSendEmailLostPassword=null;
		// code for Mozilla, etc.
		if (window.XMLHttpRequest)
		{
			xmlhttpSendEmailLostPassword=new XMLHttpRequest();
		}
		// code for IE
		else if (window.ActiveXObject)
		{
			xmlhttpSendEmailLostPassword=new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (xmlhttpSendEmailLostPassword!=null)
		{
			xmlhttpSendEmailLostPassword.open("POST",url,true);
			  
			xmlhttpSendEmailLostPassword.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlhttpSendEmailLostPassword.setRequestHeader("Content-length", parameter.length);
			xmlhttpSendEmailLostPassword.setRequestHeader("Connection", "close");
			  
			xmlhttpSendEmailLostPassword.onreadystatechange=StateChangeEmailLostPassword;
			xmlhttpSendEmailLostPassword.send(parameter);
		}
		else
		{
			alert("Your browser does not support XMLHTTP.");
		}
	}
	
	function StateChangeEmailLostPassword()
	{
		//readyState, 0 = uninitialized
		//		1 = loading
		//		2 = loaded
		//		3 = interactive
		//		4 = complete
		
		//Completed Request
		if (xmlhttpSendEmailLostPassword.readyState==4)
		  {
			// Status value just 404 and 200, 404 = "Not Found" & 200 = "Ok"
			if (xmlhttpSendEmailLostPassword.status==200)
			{				
				//Get Response from next page
				var ResponseSendEmail = xmlhttpSendEmailLostPassword.responseText;	// response				
				//~ alert(ResponseSendEmail);
				
				var sEmailProgressLP = document.getElementById("sEmailProgressLP");
				var imgProgressLP = document.getElementById("imgProgressLP");
				
				var imgStatusEmailLP = document.getElementById("imgStatusEmailLP");
				var sStatusEmailLP = document.getElementById("sStatusEmailLP");
				
				if(ResponseSendEmail == "sent")
				{
					imgStatusEmailLP.src = "Images/Ok.ico";
					sStatusEmailLP.innerHTML = "Email sent";
					ClearEmailValue();
				}
				else if(ResponseSendEmail == "failed")
				{
					imgStatusEmailLP.src = "Images/Failed.ico";
					sStatusEmailLP.innerHTML = "Email failed to sent";
				}
				else
				{
					imgStatusEmailLP.src = "Images/Failed.ico";
					sStatusEmailLP.innerHTML = "Email does not exist.";
				}
				
				//Hide email progress
				sEmailProgressLP.style.display = "none";
				imgProgressLP.style.display = "none";
				//Show Email Status
				imgStatusEmailLP.style.display = "";
				sStatusEmailLP.style.display = "";
			}
			else
			{						
				alert("Problem retrieving data");
			}
		  }
	}