var eid;
var inch=0;
var olist;
var totalheight;

function switcherinit() {
	var switcher = $("switcher");
	var switchers = switcher.getElementsByTagName("a");
	switchers[0].onclick=function(){
		$("gamelist").style.display = "block";
		$("plist").style.display = "none";
		if (inch>0){toggle();}
		$("locfix").innerHTML = " - Game Currencies:";
		return false;
	}
	switchers[1].onclick=function(){
		$("gamelist").style.display = "none";
		$("plist").style.display = "block";
		if (inch>0){toggle();}
		$("locfix").innerHTML = " - Power Leveling:";
		return false;
	}
	switchers[0].onkeypress = switchers[0].onclick;
}

function toggle() {
	var eimg = $("triggerimg");
	if (inch==0){
		eimg.src="/img/arrdown.gif";
		eid = setInterval("hidelist()",10);
	}
	if(inch==totalheight) {
		eimg.src="/img/arrup.gif";
		eid = setInterval("showlist()",10);
	}
}

function hidelist() {
	var visibleHeight = totalheight-inch;
	olist.scrollTop = inch;
	visibleHeight = (visibleHeight>0)?visibleHeight:0;
	olist.style.height = visibleHeight+"px";
	inch = inch +38;
	if (visibleHeight==0){
		inch = totalheight;
		SetCookie("pheight",inch);
		clearInterval(eid)
	}
}

function showlist() {
	inch = inch -38;
	var visibleHeight = totalheight-inch;
	olist.scrollTop = inch;
	visibleHeight = (visibleHeight>totalheight)?totalheight:visibleHeight;
	olist.style.height = visibleHeight+"px";
	if (visibleHeight>=totalheight){
		inch = 0;
		SetCookie("pheight",inch);
		clearInterval(eid)
	}
}

function pannelinit() {
	olist = $("listcontainer");
	var list = $("gamelist");
	totalheight = list.scrollHeight;
	inch = parseInt(getCookie("pheight"));
	if (inch>0){
		olist.scrollTop = inch;
		olist.style.height = "0px";
		$("triggerimg").src="/img/arrdown.gif";
	}

	var ocart = $("cart");
	var ocartanchor = ocart.getElementsByTagName("a")[0];
	ocartanchor.onclick = function() {
		showcart();
		return false;
	}
}

addLoadEvent(pannelinit);
addLoadEvent(switcherinit);




// cart event functions :
if(typeof(HTMLElement)!="undefined"){   
	HTMLElement.prototype.contains   =   function(obj) {
		while(obj!=null && typeof(obj.tagName)!="undefind"){
			if(obj==this) return true; obj=obj.parentNode;}
			return false;   
	};   
}
var proy;
var proyc;
function showcart(){
	clearInterval(proy);
	clearInterval(proyc);
	var o = $("cartdetail");
	if (parseInt(o.style.height)==60){
		closecart();
		return false;
	}
	o.style.display = "block";
	o.style.height = "1px"; 
	proy = setInterval(function(){openy(o,60)},10);
}	
	
function openy(o,y){
	var cy = parseInt(o.style.height);
	if(cy < y) {
		o.style.height = (cy + Math.ceil((y-cy)/5)) +"px";
	}
	else{
		clearInterval(proy);
		o.onmouseout=function(){if(!this.contains(event.toElement)) closecart()};
	}
}	
function closecart(){
	clearInterval(proy);
	clearInterval(proyc);		
	var o = $("cartdetail");
	if(o.style.display == "block"){
		proyc = setInterval(function(){closey(o)},10);			
	}		
}	
function closey(o){
	var cy = parseInt(o.style.height);
	if(cy > 0){
		o.style.height = (cy - Math.ceil(cy/5)) +"px";
	}
	else{
		o.style.display ="none";
		clearInterval(proyc);				
	}
}


function chksearch(){with (document.all.searchform){if (keyword.value == ''){
alert('Please input a keyword !');keyword.focus();return false;}}}
function chkLogin(){with (document.getElementById('loginform')){
if (email.value == '' || !email.value.match(/^[\w\.\-]+@([\w\-]+\.)+[a-z]{2,4}$/ig)){
alert('Please input your email !');email.focus();return false;}
if (password.value == ''){alert('Please input your password !');password.focus();return false;}}}
function checkorder(){with (document.PostForm){
if (firstname.value.length < 2 || !firstname.value.match(/^[a-zA-Z]+$/g)){
alert('Please input your first name ! \n Name can contain only letters');firstname.focus();return false;}
if (lastname.value.length < 2 || !lastname.value.match(/^[a-zA-Z]+$/g)){alert('Please input your last name ! \n Name can contain only letters');
lastname.focus();return false;}
if (email.value == '' || !email.value.match(/^[\w\.\-]+@([\w\-]+\.)+[a-z]{2,4}$/ig)){
alert('Please input your email address !');email.focus();return false;}
if (usaphone1.value != ''){if (usaphone1.value.length != 3 || isNaN(usaphone1.value)){
alert('Phone can contain only numbers! \n This field must contain three numbers !');
usaphone1.focus();return false;}
if (usaphone2.value.length != 3 || isNaN(usaphone2.value)){
alert('Phone can contain only numbers! \n This field must contain three numbers !');
usaphone2.focus();return false;}
if (usaphone3.value.length != 4 || isNaN(usaphone3.value)){
alert('Phone can contain only numbers! \n This field must contain four numbers !');
usaphone3.focus();return false;}}
if (etcphone.value != ''){if (etcphone.value.length <5 || etcphone.value.length >20 || isNaN(etcphone.value) ){
alert('Please input your phone number !');etcphone.focus();return false;}}
if (usaphone1.value=='' && etcphone.value==''){alert('Please input your phone number !');usaphone1.focus();return false;}
if (charname.value == '' || charname.value.length>20){alert('Please input your character name !');charname.focus();return false;}}}