function nTabs(thisObj,Num){
	if(thisObj.className == "active")return;
	var tabObj = thisObj.parentNode.id;
	var tabList = document.getElementById(tabObj).getElementsByTagName("li");
	for(i=0; i <tabList.length; i++){
		if (i == Num){
			thisObj.className = "active";
			document.getElementById(tabObj+"_Content"+i).style.display = "block";
		}else{
			tabList[i].className = "normal";
			document.getElementById(tabObj+"_Content"+i).style.display = "none";
		}
	}
}

function checkNumeric(string) {
	var Letters = "1234567890.";
	var i;
	var c;
	for(i = 0; i < string.length; i ++){
		c = string.charAt(i);
		if (Letters.indexOf(c) ==-1) {
			return true;
		}
	}
	return false;
}

function round(num,n) {
	var dd=1;
	var tempnum;
	for(i=0;i<n;i++) {
		dd*=10;
	}
	tempnum = num*dd;
	tempnum = Math.round(tempnum);
	return tempnum/dd;
}

function checkBoxPrice(URL, V) {
	var p = document.getElementById('price');
	var l_price = document.getElementById('l_price');
	var r_price = document.getElementById('r_price');
	if(l_price.value == '' || r_price.value == '' || checkNumeric(l_price.value) || checkNumeric(r_price.value)) {
		alert("Plese type numeric!");
		return false;
	}
	l = round(l_price.value / V, 2);
	r = round(r_price.value / V, 2);
	if(l >= r) {
		alert("The second price must bigger than the first one!");
		return false;
	}
	window.location.href = URL + '&price=' + l + "_" + r;
}

function sAlert(ImageSrc) {
	var str = '<img src="'+ImageSrc+'" style="cursor:pointer" />';
	var msgw,msgh,bordercolor;
	msgw = 640;
	msgh = 640;
	titleheight = 25;
	bordercolor = "#666666";
	titlecolor = "#333333";
	var sWidth,sHeight;
	sWidth = document.body.scrollWidth;
	sHeight = document.body.scrollHeight;
	setSelect(0);
	
	var bgObj = document.createElement("div");
	bgObj.setAttribute('id', 'bgDiv');
	bgObj.style.position = "absolute";
	bgObj.style.top = "0";
	bgObj.style.background = "#cccccc";
	bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75);";
	bgObj.style.opacity = "0.6";
	bgObj.style.left = "0";
	bgObj.style.width = sWidth + "px";
	bgObj.style.height = sHeight + "px";
	bgObj.style.zIndex = "10001";
	document.body.appendChild(bgObj);

	var msgObj = document.createElement("div");
	var ll = (window.screen.width - msgw) / 2;
	var hh = (window.screen.height - msgh) / 2;
	ll = ll < 0 ? 0 : ll;
	hh = hh < 0 ? 0 : hh;
	msgObj.setAttribute("id", "msgDiv");
	msgObj.setAttribute("align", "center");
	msgObj.style.background = "white";
	msgObj.style.border = "1px solid " + bordercolor;
	msgObj.style.position = "absolute";
	msgObj.style.left = ll+"px";
	msgObj.style.top = hh+"px";
	msgObj.style.font = "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
	//msgObj.style.marginLeft = "-275px";
	//msgObj.style.marginTop = -800+document.documentElement.scrollTop+"px";
	msgObj.style.width = msgw + "px";
	msgObj.style.height = msgh + "px";
	msgObj.style.textAlign = "center";
	msgObj.style.lineHeight = "25px";
	msgObj.style.zIndex = "10002";

	var title = document.createElement("h4");
	title.setAttribute("id", "msgTitle");
	title.setAttribute("align", "right");
	title.style.margin = "0";
	title.style.padding = "3px";
	title.style.background = bordercolor;
	title.style.filter = "progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20,finishX=100,finishY=100,style=1,opacity=75,finishOpacity=100);";
	title.style.opacity = "0.75";
	title.style.border = "1px solid " + bordercolor;
	title.style.height = "18px";
	title.style.font = "12px Verdana, Geneva, Arial, Helvetica, sans-serif";
	title.style.color = "white";
	title.style.cursor = "pointer";
	title.innerHTML = "Close";
	title.onclick = function() {
		setSelect(1);
		document.body.removeChild(bgObj);
		document.getElementById("msgDiv").removeChild(title);
		document.body.removeChild(msgObj);
	}
	msgObj.onclick = function() {
		setSelect(1);
		document.body.removeChild(bgObj);
		document.getElementById("msgDiv").removeChild(title);
		document.body.removeChild(msgObj);
	}
	document.body.appendChild(msgObj);
	document.getElementById("msgDiv").appendChild(title);
	var txt = document.createElement("p");
	txt.style.margin = "1em 0"
	txt.setAttribute("id", "msgTxt");
	txt.innerHTML = str;
	document.getElementById("msgDiv").appendChild(txt);
}

function setSelect(V) {
	var all_select = document.getElementsByTagName('select');
	var status = V == 0 ? 'hidden' : 'visible';
	for(var i = 0; i < all_select.length; i++) {
		all_select.item(i).style.visibility = status;
	}
}

function switchMenu(id){
	var LeftMenu = document.getElementById('bgSwitch');
	var allLeftUL = LeftMenu.getElementsByTagName('UL');
	var thisMenu = document.getElementById(id);
	for(var i = 0; i < allLeftUL.length; i ++) {
		if(allLeftUL.item(i).id != id && allLeftUL.item(i).id.match("news") != 0) {
			allLeftUL.item(i).style.display = 'none';
		}
	}
	if(thisMenu.style.display == "none") {
		thisMenu.style.display = "block";
	} else {
		thisMenu.style.display = "none";
	}
}

function changeCurrency(Key) {
	var CFH = document.getElementById('currencies_form_header');
	CFH.currency.value = Key;
	CFH.submit();
}

function turn(URL) {
	window.location.href = URL;
}