function goAjax(url,target,args) {
	var req;
	try {
		req= new XMLHttpRequest();
	} catch (e) {
		try {
			req= new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser not support!");
				return false;
			}
		}
	}

	req.onreadystatechange = function() {
		if (req.readyState == 4 && (req.status == 200 || req.status == 304)) {
			sdp = document.getElementById(target);
			sdp.innerHTML = req.responseText;
			autoCheck(nSel);
		}
	};

	req.open("post",url);
	req.setRequestHeader('Content-Type','application/x-www-form-urlencoded; UTF-8');
	req.send(args);
}

var halfX;
var halfY;
var fullX;
var fullY;


function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	} else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		} else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function initial() {
	IE = document.all ? true : false;
	fox = new RegExp("Firefox","i");
	chrome = new RegExp("Chrome","i");
	safari = new RegExp("Safari","i");
	opera = new RegExp("Opera","i");
	if (IE) {
		fullX = document.body.clientWidth;
		fullY = getWindowHeight();
	}
	else if (fox.test(navigator.userAgent) || chrome.test(navigator.userAgent) || safari.test(navigator.userAgent) || opera.test(navigator.userAgent)) {
		fullX = document.body.clientWidth;
		fullY = getWindowHeight();
	}
	else {
		fullX = pageXOffset;
		fullY = pageYOffset;
	}
	halfX = Math.floor(fullX / 2);
	halfY = fullY / 2;
}

var popz;
var strChecked = "";
var strChecked1 = "";
var strChecked2 = "";
var nSel = 0;
var arrValue = Array();
var bLock = true;

function callLogin() {
	if (bLock) return;
	nSel = 0;
	popz.style.top = "350px";
	popz.style.left = (halfX - 300) + "px";
	popz.innerHTML = "<div style='width:400px;' align='center'><img src='images/ajax-loader.gif'></div>";
	goAjax("login_box.php","pop");
}

function callCat() {
	if (strChecked == "") return;
	nSel = 1;
	popz.style.top = "350px";
	popz.style.left = (halfX - 250) + "px";
	popz.innerHTML = "<div style='width:600px;' align='center'><img src='images/ajax-loader.gif'></div>";	
	goAjax("select1.php","pop","gid=" + strChecked + "&cid=" + strChecked1);
}

function callSub() {
	if (strChecked1 == "") return;
	nSel = 2;
	popz.style.top = "350px";
	popz.style.left = (halfX - 300) + "px";
	popz.innerHTML = "<div style='width:700px;' align='center'><img src='images/ajax-loader.gif'></div>";
	goAjax("select2.php","pop","gid=" + strChecked + "&cid=" + strChecked1 + "&sid=" + strChecked2);
}

function chkAll(t) {
	inps = popz.getElementsByTagName("input");
	for (i = 0;i < inps.length;i++) {
		inps[i].checked = t;
	}
}

function chkComp() {
	strChecked = "";
	inps = popz.getElementsByTagName("input");
	for (i = 0;i < inps.length;i++) {
		if (inps[i].checked) {
			strChecked += "," + inps[i].value;
		}
	}
	if (strChecked != "") {
		strChecked = strChecked.substr(1);
		document.getElementById("nameCat").style.color = "#000000";
		document.getElementById("nameCountry").innerHTML = "Selected";
		document.getElementById("nameCat").style.color = "#000000";
		document.getElementById("nameCat").innerHTML = "- All Category -";
	}
	else {
		document.getElementById("nameCountry").innerHTML = "- All Country -";
		document.getElementById("nameCat").style.color = "#CCCCCC";
		document.getElementById("nameCat").innerHTML = "- All Category -";
	}
	document.getElementById("nameSub").style.color = "#CCCCCC";
	document.getElementById("nameSub").innerHTML = "- All Sub Category -";
	document.forms["searchForm"].cat.value = "";
	document.forms["searchForm"].sub.value = "";
	strChecked1 = "";
	strChecked2 = "";
	popz.style.top = "-10000px";
	document.forms["searchForm"].country.value = strChecked;
}

function chkComp1() {
	strChecked1 = "";
	inps = popz.getElementsByTagName("input");
	for (i = 0;i < inps.length;i++) {
		if (inps[i].checked) {
			strChecked1 += "," + inps[i].value;
		}
	}
	if (strChecked1 != "") {
		strChecked1 = strChecked1.substr(1);
		document.getElementById("nameSub").style.color = "#000000";
		document.getElementById("nameCat").innerHTML = "Selected";
		document.getElementById("nameSub").style.color = "#000000";
		document.getElementById("nameSub").innerHTML = "- All Sub Category -";
	}
	else {
		document.getElementById("nameCat").innerHTML = "- All Category -";
		document.getElementById("nameSub").style.color = "#CCCCCC";
		document.getElementById("nameSub").innerHTML = "- All Sub Category -";
	}
	document.forms["searchForm"].sub.value = "";
	strChecked2 = "";
	popz.style.top = "-10000px";
	document.forms["searchForm"].cat.value = strChecked1;
}

function chkComp2() {
	strChecked2 = "";
	inps = popz.getElementsByTagName("input");
	for (i = 0;i < inps.length;i++) {
		if (inps[i].checked) {
			strChecked2 += "," + inps[i].value;
		}
	}
	if (strChecked2 != "") {
		strChecked2 = strChecked2.substr(1);
		document.getElementById("nameSub").innerHTML = "Selected";
	}
	else {
		document.getElementById("nameSub").innerHTML = "- All Sub Category -";
	}
	popz.style.top = "-10000px";
	document.forms["searchForm"].sub.value = strChecked2;
	goSubmit();
}

function goSubmit() {
	document.forms["searchForm"].submit();
}

function autoCheck(n) {
	arrValue = new Array();
	if (n == 0 && strChecked != "") {
		arrValue = strChecked.split(",");
	}
	else if (n == 1 && strChecked1 != "") {
		arrValue = strChecked1.split(",");
	}
	else if (n == 2 && strChecked2 != "") {
		arrValue = strChecked2.split(",");
	}
	if (arrValue.length == 0) return;
	inps = popz.getElementsByTagName("input");
	for (i = 0;i < inps.length;i++) {
		if (autoCheck2(inps[i].value)) {
			inps[i].checked = true;
		}
		//inps[i].checked = true;
	}
}

function autoCheck2(v) {
	if (arrValue.length == 0) return false;
	for (o = 0;o < arrValue.length;o++) {
		if (arrValue[o] == v) return true;
	}
	return false;
}


