// JavaScript Document

var adtimeout;
function flashadbox(w,h,th,arrp,arrl,arrt,adplace){
	var stop_time=5000; //图片停顿时间，单位为秒，为0则停止自动切换
	var focus_width=w;
	var focus_height=h;
	var text_height=0;
	var text_align="center" //标题文字对齐方式(left、center、right)
	var txtcolor="000000"; //文字色
	var bgcolor="DDDDDD"; //背景色
	var button_pos=4; //按扭位置 1左 2右 3上 4下
	var swf_height=focus_height+text_height; //相加之和最好是偶数,否则数字会出现模糊失真的问题
	var pics=arrp.join('|');
	var links=arrl.join('|');
	var texts=arrt.join('|');
	var flash='<object id="swf'+adplace+'" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ focus_width +'" height="'+ swf_height +'">';
	flash+='<param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="/pic/index/focus.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#F0F0F0">';
	flash+='<param name="menu" value="false"><param name=wmode value="opaque">';
	flash+='<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&pic_width='+focus_width+'&pic_height='+focus_height+'&show_text='+text_height+'&txtcolor='+txtcolor+'&bgcolor='+bgcolor+'&button_pos='+button_pos+'&stop_time='+stop_time+'">';
	flash+='<embed src="/pic/index/focus.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&pic_width='+focus_width+'&pic_height='+focus_height+'&show_text='+text_height+'&txtcolor='+txtcolor+'&bgcolor='+bgcolor+'&button_pos='+button_pos+'&stop_time='+stop_time+'" menu="false" bgcolor="#F0F0F0" quality="high" width="'+ focus_width +'" height="'+ focus_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	flash+='</object>';
	return flash;
}
function printAd(adPlace,adUrl,adLink,adTitle,adtype,adWidth,adHeight,mmax,mmin){
	//adtype 0 img 1 flash
	if(!$(adPlace)){return false;}
	if(adtype==2 && typeof adUrl!='string'){
		AdChange(adPlace,adUrl,adLink,mmax,mmin);
		return true;
	}
	aadWidth=adWidth;
	aadHeight=adHeight
	adWidth = adWidth?" width='"+adWidth+"'":'';
	adHeight = adHeight?" height='"+adHeight+"'":'';
	aadLink = adLink?" href='"+adLink+"'":'';
	if(adtype==1 || adtype==0){//随机一条 ||  固定一条
		if(adUrl.substr(adUrl.length-4,adUrl.length-1).toUpperCase=='SWF'){
			
			printAd(adPlace,adUrl,adLink,adTitle,3,adWidth,adHeight,mmax,mmin);
			return true;
		}
		adHtml = "<a"+aadLink+" target='_blank'><img border=0 "+adWidth+adHeight+" src='"+adUrl+"' /></a>";
	}
	if(adtype==5){
		adHtml = "<a"+aadLink+" target='_blank'>"+adUrl+"</a>";
		}
	if(adtype==3){
		/*if(adUrl.substr(adUrl.length-3,3).toUpperCase!='SWF'){
			printAd(adPlace,adUrl,adLink,adTitle,1,adWidth,adHeight,mmax,mmin);
			return true;
		}*/
		adHtml = "<a"+aadLink+" target='_blank'><object id='swf"+adPlace+"'  classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' "+adWidth+adHeight+"><param name='movie' value='"+adUrl+"' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><embed src='"+adUrl+"' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash'"+adWidth+adHeight+"></embed></object></a>";
	}
	if(adtype==4){
		adHtml = flashadbox(aadWidth,aadHeight,24,adUrl,adLink,adTitle,adPlace);
	}
	if($(adPlace)){
	
		$(adPlace).innerHTML = adHtml;
		if($(adPlace).innerHTML=='')
			adtimeout = setTimeout(function(){printAd(adPlace,adUrl,adLink,adtype,mmax,mmin,adWidth,adHeight)},5000);
		//clearTimeout(adtimeout);
	}
}
function AdChange(adPlace,adUrl,adLink,mmax,mmin,oldkey){
		m = Math.random()*100+1;
		
		for(key in mmax){
			if(m<mmax[key] && m>mmin[key])
				break;
		}
		if(m<mmax[key] && m>mmin[key])
		if($(adPlace)){
			if(key!=oldkey)
				$(adPlace).innerHTML =  "<a href='"+adLink[key]+"'><img src='"+adUrl[key]+"' /></a>";
			setTimeout(function(){AdChange(adPlace,adUrl,adLink,mmax,mmin,key)},3000);
		}
	}
function $(){
	var elements=new Array();
	for(var i=0;i<arguments.length;i++){
		var element=arguments[i];
		if(typeof element=='string')element=document.getElementById(element);
		if(arguments.length==1)return element;elements.push(element);
	}
	return elements;
}
function getCodeImage(id){
	$(id+'show').innerHTML = "<img src=\"index.php?controller=BoLogin&action=imgcode\" onclick=\"this.src='index.php?controller=BoLogin&action=imgcode'\" alt=\"验证码看不清楚?请点击刷新验证码\">";
	setTimeout(function(){},60000)
}
function jump(url,name){
		 document.location.href = url+'&page='+(document.getElementById(name).value-1);
	}
function alertWin(title, msg, w, h, buttonText){
	var dbody = document.body;
	if(!dbody){setTimeout(function(){alertWin(title, msg, w, h, buttonText)},10);return false;} 
	
	var s=document.getElementsByTagName("select"); //--------------把所有select标签捉住
	for(var j=0;j<s.length;j++){s[j].style.display="none";} //--------------设为不显示，再进行下面操作
	var titleh = 22;
	var titleheight =  titleh+"px"; // 提示窗口标题高度 
	var bordercolor = "#666699"; // 提示窗口的边框颜色 
	var titlecolor = "#FFFFFF"; // 提示窗口的标题颜色 
	var titlebgcolor = "#666699"; // 提示窗口的标题背景色
	var bgcolor = "#FFFFFF"; // 提示内容的背景色
	document.documentElement.style.overflow = "hidden";
	document.documentElement.scrollTop = 0;
	var iWidth = document.documentElement.clientWidth+document.documentElement.scrollLeft; 
	var iHeight = document.documentElement.clientHeight+document.documentElement.scrollTop; 
	var bgObj = document.createElement("div"); 
	bgObj.style.cssText = "position:absolute;left:0px;top:0px;width:"+iWidth+"px;height:"+Math.max(document.body.clientHeight, iHeight)+"px;filter:Alpha(Opacity=30);opacity:0.3;background-color:#000000;z-index:101;";
	document.body.appendChild(bgObj); 
	
	var msgObj=document.createElement("div");
	msgObj.style.cssText = "position:absolute;font:11px '宋体';top:"+(iHeight-h)/2+"px;left:"+(iWidth-w)/2+"px;width:"+w+"px;height:"+h+"px;text-align:center;border:1px solid "+bordercolor+";background-color:"+bgcolor+";padding:1px;line-height:22px;z-index:102;";
	document.body.appendChild(msgObj);
	
	var table = document.createElement("table");
	msgObj.appendChild(table);
	table.style.cssText = "margin:0px;border:0px;padding:0px;";
	table.cellSpacing = 0;
	var tr = table.insertRow(-1);
	var titleBar = tr.insertCell(-1);
	titleBar.style.cssText = "width:100%;height:"+titleheight+"px;text-align:left;padding:3px;margin:0px;font:bold 13px '宋体';color:"+titlecolor+";border:1px solid " + bordercolor + ";cursor:move;background-color:" + titlebgcolor;
	titleBar.style.paddingLeft = "10px";
	titleBar.innerHTML = title;
	var moveX = 0;
	var moveY = 0;
	var moveTop = 0;
	var moveLeft = 0;
	var moveable = false;
	var docMouseMoveEvent = document.onmousemove;
	var docMouseUpEvent = document.onmouseup;
	titleBar.onmousedown = function() {
		var evt = getEvent();
		moveable = true; 
		moveX = evt.clientX;
		moveY = evt.clientY;
		moveTop = parseInt(msgObj.style.top);
		moveLeft = parseInt(msgObj.style.left);
		
		document.onmousemove = function() {
			if (moveable) {
				var evt = getEvent();
				var x = moveLeft + evt.clientX - moveX;
				var y = moveTop + evt.clientY - moveY;
				if ( x > document.documentElement.scrollLeft &&( x + w < iWidth+document.documentElement.scrollLeft) && y > document.documentElement.scrollTop && (y + h < iHeight+document.documentElement.scrollTop) ) {
					msgObj.style.left = x + "px";
					msgObj.style.top = y + "px";
				}
			}	
		};
		document.onmouseup = function () { 
			if (moveable) { 
				document.onmousemove = docMouseMoveEvent;
				document.onmouseup = docMouseUpEvent;
				moveable = false; 
				moveX = 0;
				moveY = 0;
				moveTop = 0;
				moveLeft = 0;
			} 
		};
	}
	
	var closeBtn = tr.insertCell(-1);
	closeBtn.style.cssText = "cursor:pointer; padding:2px;background-color:" + titlebgcolor;
	closeBtn.innerHTML = "<span style='font-size:15pt; color:"+titlecolor+";'>×</span>";
	closeBtn.onclick = function(){ 
		for(var j=0;j<s.length;j++){s[j].style.display="";} //--------------再给select显出来
		document.body.removeChild(bgObj); 
		document.body.removeChild(msgObj); 
		document.documentElement.style.overflow = "auto";
		if(msg.innerHTML){msg.innerHTML=msgBox.innerHTML;}
		if(msg.value){msg.value = msgBox.innerHTML;}
	} 
		var msgBox = table.insertRow(-1).insertCell(-1);
		msgBox.style.cssText = "font:10pt '宋体';padding-top:"+(h/2-16-titleh)+"px";
		msgBox.colSpan  = 2;
	if(msg)msgBox.innerHTML = msg;
	if(msg.innerHTML){
		msgBox.innerHTML = msg.innerHTML;
		msg.innerHTML = '1';
	}
	if(msg.value){
		msgBox.innerHTML = msg.value;
		msg.value = '1';
	}
	
	var buttonTB = document.createElement('TABLE');
	buttonTB.style.cssText = "color:"+titlecolor+";margin:0px;border:1px;padding:0px; position:absolute;font:9pt '宋体';top:"+(h-16)+"px;left:1px;width:"+w+"px;text-align:left;background-color:" + titlebgcolor;
	buttonTB.cellSpacing = 0;
	var td = buttonTB.insertRow(-1).insertCell(-1);
	td.innerHTML = buttonText;
	msgObj.appendChild(buttonTB);
	
    // 获得事件Event对象，用于兼容IE和FireFox
    function getEvent() {
	    return window.event || arguments.callee.caller.arguments[0];
    }
}
function scrollImg(x,y,obj){
	var w = obj.width;
	var h = obj.height;
	
	var maxP = Math.min(x/obj.width,y/obj.height);
	if(maxP>1){return true;}
	
	obj.width = w*maxP;
	obj.height = h*maxP;
	return true;

}