//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//   This document is design by ken-mok workshop,                               //
//   including any programming, scripting, and css.                             //
//   If anything inside is used outside this document,                          //
//   we appreciate an email. (Just so we could add you in our list)             //
//                                                                              //
//   For more enquries, please contact:                                         //
//   Ken Mok                                                                    //
//   ken@ken-mok.com                                                            //
//   msn:ken_mok@hotmail.com                                                    //
//   http://www.ken-mok.com                                                     //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////



// JavaScript Document
var mainselected = "null";

var message="Function Disabled!";

function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("alert(message);return false")


function mainmenuchange(x)
{
	for ( var i = 1; i < 7; i++)
	{
		document.getElementById("MMenu"+(i*2)).src = "images/MMenu"+(i*2)+"_n.jpg";
	}
	if ( parent.mainselected != "null")
	{
		document.getElementById(parent.mainselected).src = "images/"+parent.mainselected+"_s.jpg";
	}
	if ( x != "null" && x != "parent")
	{
		document.getElementById(x).src = "images/"+x+"_o.jpg";
	}	
}

function submenuclick(catName, selectedIndex, catTotal, url)
{
	//Change Menu Images
	
		for (var i = 1; i < (catTotal+1); i++)
		{
			document.getElementById("SMenu"+catName+i).src = "images/SMenu"+catName+i+"_n.jpg";
		}
		document.getElementById("SMenu"+catName+selectedIndex).src = "images/SMenu"+catName+selectedIndex+"_o.jpg";
	
	
	//Change MainContent Page
	parent.MainContent.location= url + ".html";
	
	if (catName == "Product")
	{
		if (selectedIndex == 2)
		{
			for (var j = 1; j < 5; j++)
			{
				document.getElementById("SMenuProduct2_"+j).src = "images/SMenuProduct2_"+j+"_n.jpg";
				document.getElementById("CellSMenuProduct2_"+j).style.display = "block";
			}
			//document.getElementById("SMenuProduct2_1").src = "images/SMenuProduct2_1_o.jpg";
		}else{
			for (var j = 1; j < 5; j++)
			{
				document.getElementById("SMenuProduct2_"+j).src = "images/SMenuProduct2_"+j+"_n.jpg";
				document.getElementById("CellSMenuProduct2_"+j).style.display = "none";
			}
			//document.getElementById("SMenuProduct2_1").src = "images/SMenuProduct2_1_o.jpg";
		}
	}
}

function kcehcnoitacol()
{
	var noitacol = parent.location.protocol;
	var kcehcstr = new Array(102, 105, 108, 101, 58);
	var neknoitacol = new Array(105, 108, 108, 101, 103, 97, 108, 117, 115, 101, 97, 103, 101, 46, 104, 116, 109, 108);
	//var kcehcstr = new Array(104, 116, 116, 112, 58);
	//var neknoitacol = new Array(104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 107, 101, 110, 45, 109, 111, 107, 46, 99, 111, 109);
	
	gnirts = gnirtsnoitamorf(kcehcstr);	
	if (noitacol == gnirts)
	{
		gnirts = gnirtsnoitamorf(neknoitacol);
		parent.location = gnirts;
	}
}

function gnirtsnoitamorf(arr)
{
	var temp = "";
	for (var i = 0; i < arr.length; i++)
	{
		temp = temp + String.fromCharCode(arr[i]);
	}
	return temp;
}

function getArgs()
{
	var args = new Object();
	//window.alert(parent.location);
	var query = parent.location.search.substring(1);
	//window.alert(query);
	var pairs = query.split("&");
	var args = new Array;
	for(var i = 0; i < pairs.length; i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos == -1) continue;
		var argname = pairs[i].substring(0,pos); 
		var value = pairs[i].substring(pos+1);
		args[argname] = unescape(value);
	}
	return args;
}

function pageChange(pageName, catName, totalNumber, selfNumber)
{
	var args = getArgs();
	if (args["pid"])
	{
		var currentURL = parent.MainContent.location.pathname;
		//window.alert(currentURL);
		var paths = currentURL.split("/");
		//window.alert(paths[(paths.length - 1)]);
		if (paths[(paths.length - 1)] != ("test" + args["pid"] + ".html"))
		{
			//window.alert("HELLO");
			if (args["pid"] != selfNumber)
			{
				parent.MainContent.location=pageName + args["pid"] + ".html";
				for (var i = 1; i < (totalNumber+1); i++)
				{
					parent.Menu.document.getElementById("SMenu"+catName+i).src = "images/SMenu"+catName+i+"_n.jpg";
				}
				parent.Menu.document.getElementById("SMenu"+catName+parseInt(args["pid"])).src = "images/SMenu"+catName+parseInt(args["pid"])+"_o.jpg";
			}
		}
	}
}

function clearForm()
{
	document.getElementById("company").value = "";
	document.getElementById("contactperson").value = "";
	document.getElementById("position").value = "";
	document.getElementById("tel").value = "";
	document.getElementById("address").value = "";
	document.getElementById("email").value = "";
	document.getElementById("website").value = "";
	document.getElementById("enquiry").value = "";
}

//kcehcnoitacol();

function formCheck()
{
	var noError = true;
	document.getElementById("error_company").style.display = "none";
	document.getElementById("error_contactperson").style.display = "none";
	document.getElementById("error_tel").style.display = "none";
	document.getElementById("error_email").style.display = "none";
	if (document.getElementById("company").value == "")
	{
		document.getElementById("error_company").style.display = "block";
		noError = false;
	}
	if (document.getElementById("email").value == "")
	{
		document.getElementById("error_email").style.display = "block";
		noError = false;
	}
	if (document.getElementById("tel").value == "")
	{
		document.getElementById("error_tel").style.display = "block";
		noError = false;
	}
	if (document.getElementById("contactperson").value == "")
	{
		document.getElementById("error_contactperson").style.display = "block";
		noError = false;
	}
	if (noError)
		document.getElementById("enuiryForm").submit();
}