// JavaScript Document
	var http = getHTTPObject();
	var http2 = getHTTPObject();	
	
	var refreshsec = 0;
	var ads_cat = 1;
	var mainframeloc = "normal";
	var currentClientHeight;
	var stopnews = 1;	
	var init = 1;
	var resizeTimer = null;
	var mallad_timer = false;
	var changead_timer = false;

	var windowWidth, windowHeight;
	if (self.innerHeight) {    // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	
	// INIT
	var mainframe = getobject('mainframe');
	mainframe.style.height = windowHeight + 'px';
	var mainbody = getobject('mainbody');
	mainbody.style.height = windowHeight +  'px';
	var bottommenu = getobject('bottommenu');				
	bottommenu.style.width = windowWidth - 40 + 'px';
	

	function chloc(type) {
		if(type != mainframeloc) {
			mainframeloc = type;
			if(mainframeloc == "admin") {
//				hidediv("mallad");
//				showdiv("adminpanel");
//				stopnews = 0;
//				start();				
//				getaddata2();
				yahooobj.show();
				showdiv('bottomdiv');
			} else if(mainframeloc == "hide") {
				hidediv('bottomdiv');
			} else {
//				stopnews = 1;
//				hidediv("adminpanel");
//				showdiv("mallad");						
//				changead();
			}
		}
	}
	
	function getHTTPObject() {
		if (typeof XMLHttpRequest != 'undefined') {
			return new XMLHttpRequest();
		}
		try {
			return new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				return new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
		return false;
	}
	
	function getaddata(ads_cat) {
		var n = calheight();
		var myurl = "/newmallad2.php?cat="+category+"&s="+shopid+"&n="+n+"&c="+ads_cat;
		http.open("GET", myurl, true);
		http.onreadystatechange = useHttpResponse;
		http.send(null);
	} 
	
	function getaddata2() {
		var myurl = "/getsysinfo.php";
		http2.open("GET", myurl, true);
		http2.onreadystatechange = useHttpResponse2;
		http2.send(null);
	} 
	
	function useHttpResponse() {
	  if (http.readyState == 4) {
		if(http.status == 200) {
			if(mallad_opened == true) {
				mallad_timer = false;			
				var obj = getobject('adtype');
				if(ads_cat == 1) {
					obj.className = 'header';
					obj.innerHTML = '人氣貨品';
				} else if(ads_cat == 2) {
					obj.className = 'header2';		
					obj.innerHTML = "減價促銷";
				} else if(ads_cat == 3) {
					obj.className = 'header2';
					obj.innerHTML = "熱爆優惠";
				} else {
					obj.className = 'header';
					obj.innerHTML = "最新優惠";				
				}
				var obj = getobject('malladcontent');
				obj.innerHTML = http.responseText;
				changead_timer = true;
				setTimeout("changead()", 1000 * refreshsec);
			}
		}
	  }
	}

	function useHttpResponse2() {
	  if (http2.readyState == 4) {
		if(http2.status == 200) {
			var obj = getobject('adminright');
			obj.innerHTML = http2.responseText;
			setTimeout("getaddata2()", 60000 * 2.5);			
		}
	  }
	}

	function calheight() {
//		var result = Math.ceil(windowHeight / 200) - 1;	
		var result = 3;
		refreshsec = result * 2;
		return result;
	}
	
	function changead() {
		if((mallad_opened == true)&&(changead_timer == true)) {
			changead_timer = false;
			ads_cat = ads_cat + 1;
			if(ads_cat > 2){
				ads_cat	= 1;
			}
			getaddata(ads_cat);
		}
	}
	
	function hidediv(id) {
		getobject(id).style.visibility = 'hidden';
		getobject(id).visibility = 'hidden';
	}
	
	function showdiv(id) {
		getobject(id).style.visibility = 'visible';
		getobject(id).visibility = 'visible';
	}
	
	function scroll() {
		if(parseInt(getobject('roller').style.top) > -65) {
			getobject('roller').style.top = parseInt(getobject('roller').style.top) - 2 + 'px';
		} else {
			getobject('roller').style.top = parseInt(getobject('roller').style.top) + 70 + 'px';
		}
	}
	function rulla() {
		setInterval("scroll()", 50)
	}
	
	window.onresize = function(){
	   if(resizeTimer) clearTimeout(resizeTimer);
		  resizeTimer = setTimeout("doResize()",0);
	}			
	function doResize(){
		if (self.innerHeight) {    // all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}				
		var mainframe = getobject('mainframe');
		mainframe.style.height = windowHeight + 'px';
		var mainbody = getobject('mainbody');				
		mainbody.style.height = windowHeight + 'px';
		var bottommenu = getobject('bottommenu');				
		bottommenu.style.width = windowWidth - 40 + 'px';
	}			
	setInterval("doResize()", 2000)	
	
	function showmallad() {
		if((mallad_timer == true)&&(mallad_opened == false)&&(mainframeloc == "normal")) {
			changead_timer = true;
			var butt = getobject('malladbutt');
			mallad_timer = false;
			switchwin('mallad', butt);
			changead();			
		}
	}
	
	function switchwin2() {	
		var butt = getobject('malladbutt');
		switchwin("mallad", butt);
	}
	
	function switchwin(id, buttobj) {
		var obj = getobject('id');
		if(id == "mallad") {
			if(mallad_opened == false) {
				if(systemmsg_opened == true) {
					var butt = getobject('systembutt');
					switchwin('adminpanel', butt);
				}
				mallad_opened = true;
				showdiv(id);
				buttobj.style.background = '#FFFFFF';
//				alert(changead_timer);
				if(changead_timer == false) {
					changead_timer = true;
					setTimeout("changead()", 1000 * refreshsec);
				}
			} else {
				changead_timer = false;
				mallad_opened = false;
				hidediv(id);
				buttobj.style.background = '#E3E3E3';
				if(mallad_timer == false) {
					mallad_timer = true;
					setTimeout("showmallad()", 15000);
				}
			}
		}
		if(id == "adminpanel") {
			if(systemmsg_opened == false) {
				if(mallad_opened == true) {
					var butt = getobject('malladbutt');
					switchwin('mallad', butt);
				}
				systemmsg_opened = true;
				showdiv(id);
				buttobj.style.background = '#FFFFFF';
			} else {
				systemmsg_opened = false;
				hidediv(id);
				buttobj.style.background = '#E3E3E3';			
			}
		}		
	}	
