	
function distributorName1Clicked()
{
	
	var distributorName = document.PPWForm["DistributorName1"].value;
	if (distributorName == "Distributor Name")	{
		
		document.PPWForm["DistributorName1"].value = "";					
	}

}
function phonecardName1Clicked()
{
	var phoneCardName = document.PPWForm["PhoneCardName1"].value;
	if (phoneCardName == "Phone Card Name")	{
		
		document.PPWForm["PhoneCardName1"].value = "";					
	}
}

function distributorName1LostFocus()
{
	
	var distributorName = document.PPWForm["DistributorName1"].value;
	if (distributorName == "")	{
		
		document.PPWForm["DistributorName1"].value = "Distributor Name";					
	}  

}
function phonecardName1LostFocus()
{
	var phoneCardName = document.PPWForm["PhoneCardName1"].value;
	if (phoneCardName == "")	{
		
		document.PPWForm["PhoneCardName1"].value = "Phone Card Name";					
	}  
}

function getMiddleCards()
{
	//alert ("get cards");
	
	var countryName = document.PPWForm["CardSearchMiddleRowControl:Countryselectcontrol4:CountrySelect"].value;
	var url = "SearchPhoneCard.aspx?";
	
	if (countryName != null)	{
		
		if (countryName == "0")	{
			countryName = "";
		}
		
		url = url + "CountryName=" + escape(countryName);	
		//alert (url);	
	}
	
	
	document.location = url;
}

function phoneCardSelectChange()
{
    var phoneCardID = document.PPWForm["ProductSelectControl:ProductSelect"].value;
	var url = "ReviewForm.html?";
	
	if (phoneCardID != null)	{
		
		if (phoneCardID == "0")	{
			alert("Please select a phone card.");
			return;
		}
		
		url = url + "PhoneCard=" + escape(phoneCardID);	
		//alert (url);	
	}
	document.location = url;
}

function getCards()
{
	
	var phoneCardName = encode(document.PPWForm["PhoneCardName1"].value);
	var countryName = encode(document.PPWForm["CardSearchControl:CountrySelectControl:CountrySelect"].value);
	var distributorName = encode(document.PPWForm["DistributorName1"].value);
	var url = "http://www.prepaidworldindex.com/search";
	
	if (distributorName != null)	{
		
		if (distributorName == "Distributor Name" || distributorName == "")	{
			url = url + "/-";								
		}
		else {
			url = url + "/" + escape(distributorName);		
		}
		//alert (url);
	}
	
	if (countryName != null)	{
		
		if (countryName == "0")	{
			url = url + "/-";
		}
		else {
			url = url + "/" + escape(countryName);	
		}
		//alert (url);	
	}
	else {
		url = url + "/" + escape(countryName);	
	
	}
	
	if (phoneCardName != null)	{
		if (phoneCardName == "Phone Card Name" || phoneCardName == "")	{
			url = url + "/-";								
		}
		else {
			url = url + "/" + escape(phoneCardName);		
		}
		//alert (url);
	}
	
	document.location = url + "/.html";
}



function getDistributors()
{
//	alert ("get cards");
	
	var state = encode(document.PPWForm["DistributorSearchControl:StateControl:States"].value);
	var distributorName = encode(document.PPWForm["DistributorName2"].value);
	var phoneCardName = encode(document.PPWForm["PhoneCardName2"].value);
	var url = "http://www.prepaidworldindex.com/find";
	
	
	if (distributorName != "")	{
		
		url = url + "/" + escape(distributorName);		
		//alert (url);
	}
	else {
		url = url + "/-";
	}
	if (state != null)	{
		
		if (state == "0")	{
			url = url + "/-";
		}
		else {
			url = url +	"/" + escape(state)
		}
		
		
//		alert (url);	
	}
	
	
	if (phoneCardName != "")	{
		
		url = url + "/" + escape(phoneCardName);			
		//alert (url);
	}
	else {
		url = url + "/-";
	}
	//alert (url);
	document.location = url + "/.html";

}

window.onload=function()
{
	document.onkeypress = cancel_Enter;
};

function cancel_Enter(e)
{
	if (!e) var e = window.event;  //for IE
	
	var code;
	if(e.keyCode) code = e.keyCode; //for IE
	if(e.which) code = e.which;  //for other browsers

	if (code == 13) return false;
	//return true;
}


function phonecardSearchKeyPressed()
{
	
	var code;
	var e = window.event;
	
				
	if (e.keyCode == 13 || e.keyCode == 3)	{
		//alert("code: " + e.keyCode);
		getCards();
		cancel_Enter(e);
	}

}

function phonecardMiddleSearchKeyPressed()
{
	
	var code;
	var e = window.event;
	
				
	if (e.keyCode == 13 || e.keyCode == 3)	{
		//alert("code: " + e.keyCode);
		getMiddleCards();
	}

}

function onMiddleSearchCountryChange()
{
	getMiddleCards();
}

function distributorSearchKeyPressed()
{
	var code;
	var e = window.event;
	
				
	if (e.keyCode == 13 || e.keyCode == 3)	{
		//alert("code: " + e.keyCode);
		getDistributors();
		cancel_Enter(e)
	}
}


function messageBodyKeyPressed()
{
	var code;
	var e = window.event;
	
				
	if (e.keyCode == 13 || e.keyCode == 3)	{
		//alert("code: " + e.keyCode);
	//	getDistributors();
	}
}


function validateContactForm()
{
		
	var email = document.PPWForm["ContactFormControl:EmailTextbox"].value;
	var fax = document.PPWForm["ContactFormControl:FaxTextbox"].value;
	var phone = document.PPWForm["ContactFormControl:PhoneTextbox"].value;
	var companyName = document.PPWForm["ContactFormControl:CompanyNameTextbox"].value;
	var comtactName = document.PPWForm["ContactFormControl:ContactNameTextbox"].value;
	var subject = document.PPWForm["ContactFormControl:SubjectTextbox"].value;
	var body = document.PPWForm["ContactFormControl:BodyTextbox"].value;
	if (companyName == "")	{
		alert("Please enter Company Name information.");
		document.PPWForm["ContactFormControl:CompanyNameTextbox"].focus();
		return false;
	}
	if (comtactName == "")	{
		alert("Please enter Contact Name information.");
		document.PPWForm["ContactFormControl:ContactNameTextbox"].focus();
		return false;
	}
	if (phone == "")	{
		alert("Please enter Phone information.");
		document.PPWForm["ContactFormControl:PhoneTextbox"].focus();
		return false;
	}
	
	if (email == "")	{
		alert("Please enter Email information.");
		document.PPWForm["ContactFormControl:EmailTextbox"].focus();
		return false;
	}
	
	if (subject == "")	{
		alert("Please enter Subject information.");
		document.PPWForm["ContactFormControl:SubjectTextbox"].focus();
		return false;
	}
	if (body == "")	{
		alert("Please enter Message Body information.");
		document.PPWForm["ContactFormControl:BodyTextbox"].focus();
		return false;
	}
	return true;

}



function getSearchResults()
{
	//alert ("get cards");
	
	var search = document.PPWForm["search"].value;
	var url = "http://www.prepaidworldindex.com/site-search";

	if (search == "")	{
		search = "-";
	}	
	if (search != null)	{
		url = url + "/" + escape(encode(search));	
	}
	//alert(url);
	
	document.location = url + "/.html";


}

function siteSearchKeyPressed()
{
	var code;
	var e = window.event;
	
				
	if (e.keyCode == 13 || e.keyCode == 3)	{
		//alert("code: " + e.keyCode);
		getSearchResults();
		cancel_Enter(e)
	}
}


function encode(str)
{
    var myStr = replaceIt(str, " ", "_");
    myStr = replaceIt(myStr, "&", "-and-");
    myStr = replaceIt(myStr, ".", "-dot-");
    myStr = replaceIt(myStr, "%", "-percent-");
    myStr = replaceIt(myStr, "?", "-question-");
    myStr = replaceIt(myStr, "/", "-slash-");
    
	return myStr;
	
}	




function replaceIt(sString, sReplaceThis, sWithThis) { 
	if (sReplaceThis != "" && sReplaceThis != sWithThis) { 
		var counter = 0; 
		var start = 0; 
		var before = ""; 
		var after = ""; 
		while (counter<sString.length) { 
			start = sString.indexOf(sReplaceThis, counter); 
			if (start == -1) { 
				break; 
			} 
			else { 
				before = sString.substr(0, start); 
				after = sString.substr(start + sReplaceThis.length, sString.length); 
				sString = before + sWithThis + after; 
				counter = before.length + sWithThis.length; 
			} 
		} 
	} 
	return sString; 
} 



function add()
{
	var availableServices = document.PPWForm["RegistrationFormControl:ServiceListbox"];
	var selectedServices = document.PPWForm["RegistrationFormControl:SelectedServiceListbox"];
	var selectedValue = document.PPWForm["RegistrationFormControl:ServiceListbox"].value;
	var found = false;
	//alert("add");
	if (selectedValue != 0)	{
		for (i = 0; i <	 selectedServices.length; i++)	{
			if (selectedValue == selectedServices.options[i].value)	{
				found = true;
				break;
			}
		}
		if (!found)	{
			//alert("not found");
			selectedServices.options[selectedServices.options.length] = new Option(availableServices.options[availableServices.selectedIndex].text, availableServices.options[availableServices.selectedIndex].value);
			availableServices.options[availableServices.selectedIndex] = null;
		}
	}
	// populate hidden text box
	var values = "";
	for (i = 0; i < selectedServices.length; i++)	{
		
		values = values + selectedServices.options[i].value;
		if (i < selectedServices.length - 1)	{
			values = values + ",";
		}
		
	}
	document.PPWForm["RegistrationFormControl:HiddenServices"].value = values;
}	


			
function remove()
{
	var availableServices = document.PPWForm["RegistrationFormControl:ServiceListbox"];
	var selectedServices = document.PPWForm["RegistrationFormControl:SelectedServiceListbox"];
	var selectedValue = document.PPWForm["RegistrationFormControl:SelectedServiceListbox"].value;
	var found = false;
	//alert("add");
	if (selectedValue != 0)	{
		
		availableServices.options[availableServices.options.length] = new Option(selectedServices.options[selectedServices.selectedIndex].text, selectedServices.options[selectedServices.selectedIndex].value);
		selectedServices.options[selectedServices.selectedIndex] = null;
		
	}
	// populate hidden text box
	var values = "";
	for (i = 0; i < selectedServices.length; i++)	{
		
		values = values + selectedServices.options[i].value;
		if (i < selectedServices.length - 1)	{
			values = values + ",";
		}
		
	}
	document.PPWForm["RegistrationFormControl:HiddenServices"].value = values;
}
