function ajax()
{
    if (window.XMLHttpRequest) {
        try {
            doc = new XMLHttpRequest();
        } catch(e)  {}
    } else if (window.ActiveXObject) {
        try {
            doc = new ActiveXObject('Msxml2.XMLHTTP');
        } catch(e)  {
          try {
              doc = new ActiveXObject('Microsoft.XMLHTTP');
          } catch(e)  {}
        }
    }
}//Ajax engine

function TopMenu(getid)
{
	document.getElementById("tmu_"+getid).style.color="#FFFFFF";
}

var DefaultI = 1;
function ChangeGa(getid)
{
	var newimg = "upload/full/"+getid+".jpg";
	document.getElementById("mainimg").src= newimg;
	document.getElementById("Cm_"+DefaultI).style.backgroundImage="url(image/gbg2.png)";
	document.getElementById("Cm_"+getid).style.backgroundImage="url(image/gbg1.png)";
	DefaultI = getid;
}

function SubMenu(getid)
{
	document.getElementById("smu_"+getid).style.color="#FFFFFF";
}

function Changeto(obj,sor)
{
	obj.src = 'upload/'+sor+'_over.png';
}

function Changeback(obj,sor)
{
	obj.src = 'upload/'+sor+'.png';
}

function Regbtn(obj,types)
{
	if (types == 1)
	{
		obj.style.backgroundColor = '#383635';
		obj.style.color = '#DCDDDD';
	}else{
		obj.style.backgroundColor = '#000000';
		obj.style.color = '#FFFFFF';
	}
}

function CheckInput(getid)
{
	switch(getid)
	{
			case "firstname":batxt = "FIRST NAME*";break;
			case "lastname":batxt = "LAST NAME*";break;
			case "address":batxt = "ADDRESS*";break;
			case "city":batxt = "CITY*";break;
			case "zip":batxt = "ZIP CODE*";break;
			case "email":batxt = "EMAIL*";break;
			case "purdate":batxt = "PURCHASE DATE (dd/mm/yy)*";break;
			case "product":batxt = "PRODUCT Select from list*";break;
			case "colour":batxt = "COLOUR*";break;
			case "price":batxt = "PRICE PER UNIT*";break;
			case "unit":batxt = "UNIT Select from list*";break;
			case "noup":batxt = "NUMBER OF UNITS PURCHASED*";break;
			case "dealername":batxt = "DEALER NAME*";break;
			case "dealeraddr":batxt = "DEALER ADDRESS*";break;
			case "dealercity":batxt = "DEALERS CITY*";break;
			case "dealerscountry":batxt = "DEALERS COUNTRY*";break;
			case "dealerstate":batxt = "DEALERS STATE/PROVINCE*";break;
			case "installationdate":batxt = "INSTALLATION DATE (dd/mm/yy)*";break;
			case "subemail":batxt = "EMAIL";break;
	}
	if (document.getElementById(getid).value == batxt)
	{
		document.getElementById(getid).value = "";
	}

	if (getid == 'product')
	{
		document.getElementById("productselects").style.display = "block";
	}
	if (getid == 'unit')
	{
		document.getElementById("unitselects").style.display = "block";
	}
}

function EndCheck(getid)
{
	if (document.getElementById(getid).value == "")
	{
		var batxt = "";
		switch(getid)
		{
			case "firstname":batxt = "FIRST NAME*";break;
			case "lastname":batxt = "LAST NAME*";break;
			case "address":batxt = "ADDRESS*";break;
			case "city":batxt = "CITY*";break;
			case "zip":batxt = "ZIP CODE*";break;
			case "email":batxt = "EMAIL*";break;
			case "purdate":batxt = "PURCHASE DATE (dd/mm/yy)*";break;
			case "product":batxt = "PRODUCT Select from list*";break;
			case "colour":batxt = "COLOUR*";break;
			case "price":batxt = "PRICE PER UNIT*";break;
			case "unit":batxt = "UNIT Select from list*";break;
			case "noup":batxt = "NUMBER OF UNITS PURCHASED*";break;
			case "dealername":batxt = "DEALER NAME*";break;
			case "dealeraddr":batxt = "DEALER ADDRESS*";break;
			case "dealercity":batxt = "DEALERS CITY*";break;
			case "dealerscountry":batxt = "DEALERS COUNTRY*";break;
			case "dealerstate":batxt = "DEALERS STATE/PROVINCE*";break;
			case "installationdate":batxt = "INSTALLATION DATE (dd/mm/yy)*";break;
			case "subemail":batxt = "EMAIL";break;
		}
		document.getElementById(getid).value = batxt;
	}
}

function Srcheck(getdo,getid)
{
	if (getdo==0)
	{
		var edi="";
	}else{
		var edi="_"+getdo;
	}

	switch(getid)
	{
			case "sname"    : batxt = "STORE NAME*";break;
			case "address"  : batxt = "ADDRESS*";break;
			case "city"     : batxt = "CITY*";break;
			case "province" : batxt = "PROVINCE/STATE*";break;
			case "postcode" : batxt = "POST CODE*";break;
			case "faxno"    : batxt = "FAX NUMBER*";break;
			case "telno"    : batxt = "TELEPHONE NUMBER*";break;
			case "website"  : batxt = "WEBSITE*";break;
			case "email"    : batxt = "EMAIL*";break;
	}
	if (document.getElementById(getid+edi).value == batxt)
	{
		document.getElementById(getid+edi).value = "";
	}
}

function Srecheck(getdo,getid)
{
	if (getdo==0)
	{
		var edi="";
	}else{
		var edi="_"+getdo;
	}
	if (document.getElementById(getid+edi).value == "")
	{
		var batxt = "";
		switch(getid)
		{
			case "sname"    : batxt = "STORE NAME*";break;
			case "address"  : batxt = "ADDRESS*";break;
			case "city"     : batxt = "CITY*";break;
			case "province" : batxt = "PROVINCE/STATE*";break;
			case "postcode" : batxt = "POST CODE*";break;
			case "faxno"    : batxt = "FAX NUMBER*";break;
			case "telno"    : batxt = "TELEPHONE NUMBER*";break;
			case "website"  : batxt = "WEBSITE*";break;
			case "email"    : batxt = "EMAIL*";break;
		}
		document.getElementById(getid+edi).value = batxt;
	}
}

function prosel(obj)
{
	obj.style.backgroundColor = '#666666';
	obj.style.color='#FFFFFF';
}

function proseo(obj)
{
	obj.style.backgroundColor = '#383635';
	obj.style.color='#666666';
}

function proselt(getid,getname)
{
	document.getElementById(getid).value = getname;
	if (getid == "product")
	{
		document.getElementById("productselects").style.display = "none";
	}else{
		document.getElementById("unitselects").style.display = "none";
	}
}

function BtnOver(obj)
{
	obj.style.backgroundColor = '#333333';
	obj.style.color='#FFFFFF';
}

function BtnOut(obj)
{
	obj.style.backgroundColor = '#999999';
	obj.style.color='#000000';
}

function StartLogin()
{
	if (document.getElementById("emails").value == "")
	{
		document.getElementById("loginfa").style.display = "block";
		document.getElementById("loginfb").innerHTML = "Sorry, Please enter your email address";
		document.getElementById("loginfb").style.display = "block";
		setTimeout('AutoHide()',5000);
		return false;
	}

	if (document.getElementById("passwords").value == "")
	{
		document.getElementById("loginfa").style.display = "block";
		document.getElementById("loginfb").innerHTML = "Sorry, Please enter your password";
		document.getElementById("loginfb").style.display = "block";
		setTimeout('AutoHide()',5000);
		return false;
	}

	var username = document.getElementById("emails").value;
	var password = document.getElementById("passwords").value

	ajax();
	if (doc)
	{
		doc.open("GET", "len.function.php?action=ulogin&user="+username+"&pass="+password+"&t="+Math.random(),false);
		doc.send(null);
		if (doc.readyState==4 && doc.status==200)
		{
	       	var azan = doc.responseText.split("**");
			if (azan[0]==0)
			{
				document.getElementById("loginfa").style.display = "block";
				document.getElementById("loginfb").innerHTML = azan[1];
				document.getElementById("loginfb").style.display = "block";
				setTimeout('AutoHide()',5000);
			}else{
				if (azan[1] == 0)
				{
					document.getElementById("firlogin").style.display = "block";
				}else{
					window.location.href = 'user_marketing_materials.php';
				}
			}
		}
	}
}

function AutoHide()
{
	document.getElementById("loginfa").style.display = "none";
	document.getElementById("loginfb").style.display = "none";
}

function ClearSp(gettext)
{
	gettext = gettext.replace("&","_and_");
	gettext = gettext.replace("'","^");
	gettext = gettext.replace('"','^^');
	return gettext;
}

function RegisterFunction()
{
	if (document.getElementById("regname").value == ""){alert("Please enter your name");return false;}
	if (document.getElementById("regemail").value == ""){alert("Please enter your email address");return false;}
	if (document.getElementById("regreemail").value == ""){alert("Please confirm your email address");return false;}
	if (document.getElementById("regemail").value != document.getElementById("regreemail").value){alert("Sorry, confirm email address is different");return false;}
	if (document.getElementById("regcompany").value == ""){alert("Please enter your company's name");return false;}
	if (document.getElementById("regaddr").value == ""){alert("Please enter your company's address");return false;}
	if (document.getElementById("regtel").value == ""){alert("Please enter your telephone number");return false;}
	if (document.getElementById("regpass").value == ""){alert("Please enter your password");return false;}
	if (document.getElementById("regrepass").value != document.getElementById("regrepass").value){alert("Sorry, confirm password is different");return false;}

	var Name    = document.getElementById("regname").value;
	var Email   = document.getElementById("regemail").value;
	var Company = document.getElementById("regcompany").value;
	var Address = document.getElementById("regaddr").value;
	var Tele    = document.getElementById("regtel").value;
	var Pass    = document.getElementById("regpass").value;

	var Tee = ClearSp(Name+"____"+Email+"____"+Company+"____"+Address+"____"+Tele+"____"+Pass);

	ajax();
	if (doc)
	{
		doc.open("GET", "len.function.php?action=ureg&infos="+Tee+"&t="+Math.random(),false);
		doc.send(null);
		if (doc.readyState==4 && doc.status==200)
		{
	       	var azan = doc.responseText.split("**");
			if (azan[0]==0)
			{
				alert(azan[1])
			}else{
				alert(azan[2]);
				window.location.href = window.location.href;
			}
		}
	}
}

function ConfirmSp()
{
	if (document.getElementById("spcode").value == ""){alert("Please enter your code");return false;}
	var Pass = document.getElementById("spcode").value;
	ajax();
	if (doc)
	{
		doc.open("GET", "len.function.php?action=rconfirm&infos="+Pass+"&t="+Math.random(),false);
		doc.send(null);
		if (doc.readyState==4 && doc.status==200)
		{
	       	var azan = doc.responseText.split("**");
			if (azan[0]==0)
			{
				alert(azan[1])
			}else{
				window.location.href = window.location.href;
			}
		}
	}
}

function AddMoreLocation()
{
	if(window.confirm("Are you sure ?"))
	{
		return StartAddMore();
	}
	return false;
}

function StartAddMore()
{
	ajax();
	if (doc)
	{
		doc.open("GET", "len.function.php?action=addmoreloca&t="+Math.random(),false);
		doc.send(null);
		if (doc.readyState==4 && doc.status==200)
		{
	       	var azan = doc.responseText.split("**");
			if (azan[0]==0)
			{
				alert('Sorry, Failed')
			}else{
				window.location.href = "searchregister.php#newform";
			}
		}
	}
}

function Subemail()
{
	var ems = document.getElementById("subemail").value;
	if (ems == "")
	{
		alert("Please enter your email address");
		return false;
	}else{
		ajax();
		if (doc)
		{
			doc.open("GET", "len.function.php?action=subemails&email="+ems+"&t="+Math.random(),false);
			doc.send(null);
			if (doc.readyState==4 && doc.status==200)
			{
				var azan = doc.responseText.split("**");
				if (azan[0]==0)
				{
					alert(azan[2]);
				}else{
					alert(azan[1]);
					document.getElementById("subemail").value = '';
				}
			}
		}
	}
}

function GetCountry()
{
	var Zid = document.getElementById("continent").value;
	if (Zid > 0)
	{
		ajax();
		if (doc)
		{
			doc.open("GET", "len.function.php?action=getcountry&zid="+Zid+"&t="+Math.random(),false);
			doc.send(null);
			if (doc.readyState==4 && doc.status==200)
			{
				document.getElementById("countrylist").innerHTML = doc.responseText;
			}
		}
	}
}

function SaveShopInfo(getdo)
{
	if (getdo==0)
	{
		var doo="";
	}else{
		var doo="_"+getdo;
	}
	if (document.getElementById("sname"+doo).value == "STORE NAME*"){alert("Please enter your shop name");return false;}
	if (document.getElementById("address"+doo).value == "ADDRESS*"){alert("Please enter your address");return false;}
	if (document.getElementById("city"+doo).value == "CITY*"){alert("Please enter your city");return false;}
	if (document.getElementById("province"+doo).value == "PROVINCE/STATE"){alert("Please enter your province/state name");return false;}
	if (document.getElementById("postcode"+doo).value == "POST CODE*"){alert("Please enter your postcode");return false;}
	if (document.getElementById("country"+doo).value == "0"){alert("Please select your country");return false;}
	if (document.getElementById("faxno"+doo).value == "FAX NUMBER*"){alert("Please enter your fax number");return false;}
	if (document.getElementById("telno"+doo).value == "TELEPHONE NUMBER*"){alert("Please enter your telephone number");return false;}
	if (document.getElementById("website"+doo).value == "WEBSITE*"){alert("Please enter your website url");return false;}
	if (document.getElementById("email"+doo).value == "EMAIL*"){alert("Please enter your email address");return false;}
	

	document.getElementById("orgform"+doo).submit();
}

function StartSearch()
{
	var oa = document.getElementById("continent").value;
	var ob = document.getElementById("country").value;
	var oc = document.getElementById("postcode").value;
	window.location.href = "searchshop.php?action="+oa+"&cid="+ob+"&postcode="+oc;
}

function ChangeLang(getid,getlang)
{
	document.getElementById("sososo_"+Dfdo).style.backgroundImage = "url(/image/nobg.png)";
	document.getElementById("sososo_"+Dfdo).style.color = "#FFFFFF";
	document.getElementById("sososo_"+getid).style.backgroundImage = "url(/image/yesbg.png)";
	document.getElementById("sososo_"+getid).style.color = "#000000";
	Dfdo = getid;
	Dfla = getlang;
}

function LoadDfdo()
{
	document.getElementById("sososo_"+Dfdo).style.backgroundImage = "url(/image/yesbg.png)";
	document.getElementById("sososo_"+Dfdo).style.color = "#000000";
}

function StartDownload(getid)
{
	var key = "di"+Dfla+getid;
	window.location.href = "style.download.php?getfile="+key;
}
