// array of div ids
var ids=new Array('EmailRequired', 'PhoneRequired', 'NameRequired');

// form object


function OpenSalesWatch()
{

	// base url for support request
	// ---------------------------------------------------------------------------------------------------------------------------
	// enter the LWID, Category ID and Topic ID below
	// replace ### with appropriate values below
	// ex: "http://chat.linqware.com/lqwwebchat/linqwaredialog.aspx?LWID=123&CT=115,117&URL=http://www.company.domain.com"
	var strLink = "http://chat.linqware.com/lqwwebchat/linqwaredialog.aspx?LWID=460&CT=469,755&URL=http://www.namalefiji.com";
	// ----------------------------------------------------------------------------------------------------------------------------

	/*if (MyForm.optSupportType[0].checked)
		{
		strLink = strLink + "&RT=Chat";
		if (MyForm.txtFirstName.value.length == 0)
			{
			alert("Please enter your first name if you wish to chat with a member of our customer care team.");
			MyForm.txtFirstName.focus();
			return;
			}
		}
	if (MyForm.optSupportType[1].checked)
		{
		strLink = strLink + "&RT=Phone";
		// since this is a phone call, make sure phone is not empty
		if (MyForm.txtPhone.value.length == 0)
			{
			alert("Please enter a phone number if you wish to have a customer care team member call you.");
			MyForm.txtPhone.focus();
			return;
			}
		}
	if (MyForm.optSupportType[2].checked)
		{
		strLink = strLink + "&RT=Tour";
		if (MyForm.txtEmail.value.length == 0)
			{
			alert("Please enter your email address if you wish to have a customer care team member take you on a guided tour.");
			MyForm.txtEmail.focus();
			return;
			}
		}
		*/
	var MyForm = document.form1;	

		if (MyForm.txtEmail.value == 'email (required)')
			{
			alert("To chat with a member of our customer care team, please enter your email address.");
			MyForm.txtEmail.focus();
			return;
			}

	if (MyForm.txtFirstName.value != 'first name')
		{
		strLink = strLink + "&FN=" + MyForm.txtFirstName.value;
		}
	if (MyForm.txtLastName.value.length != 'last name')
		{
		strLink = strLink + "&LN=" + MyForm.txtLastName.value;
		}
	if (MyForm.txtEmail.value.length != 'email (required)')
		{
		if (echeck(MyForm.txtEmail.value)==false)
			{
				MyForm.txtEmail.focus();
				return;
			}
		strLink = strLink + "&EA=" + MyForm.txtEmail.value;
		}
	if (MyForm.txtPhone.value.length != 'phone number')
		{
		strLink = strLink + "&PN=" + MyForm.txtPhone.value;
		}
	
	//window.open(strLink,"_blank","directories=no,fullscreen=no,left=50,height=50,width=50,location=no,menubar=no,resizable=yes,status=no,toolbar=no,top=50,resizable=0");
	openRequest(strLink);
	
	//alert(strLink);
}

function echeck(str) 
	{
		// email validation
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		var strMessage = "Please enter a valid email address.";

		if (str.indexOf(at)==-1){
			alert(strMessage);
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert(strMessage);
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert(strMessage);
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert(strMessage);
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert(strMessage);
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert(strMessage);
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert(strMessage);
		    return false;
		 }

 		 return true;
	}

function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}
function switchid(id){	
	hideallids();
	showdiv(id);
}

function hideallids(){
	//loop through the array and hide each element by id
	for (var i=0;i<ids.length;i++){
		hidediv(ids[i]);
	}		  
}
