// JavaScript Document

// getCitys 
var global_sf='college_sf'; //默认省份控件名称
var global_dq='college_qd'; //默认地区控件名称
var global_qx='college_qx'; //默认区县控件名称
function getCitys(obj_name_sf,obj_name_dq,obj_name_qx)
{
	    global_sf = obj_name_sf ;
	    global_dq = obj_name_dq ;
					global_qx = obj_name_qx ;
					var provinceId=$(global_sf).value;
					var pars	= 'action=city&sfcode='+provinceId;
					var url=siteurl+"index/ajax/city";
					var myAjax	= new Ajax.Request(
						url, 
						{
							parameters: pars, 
							onSuccess: updateGetCitys,
							onComplete:updateGetCitys
						});
}
function updateGetCitys(originalRequest)
{
				var responseText				= originalRequest.responseText;
				eval(responseText);
				$(global_dq).options.length = 0;
				$(global_dq).options[0]=new Option("所属地区",0);
				var i=1;
				for (var key in theCitys)
				{
						$(global_dq).options[i] = new Option(theCitys[key], key);
						i = i + 1;
				}
				$(global_qx).options.length = 0;
				$(global_qx).options[0]=new Option("所属区县",0);
}
function getCountys(obj_name_sf,obj_name_dq,obj_name_qx){
	    global_sf = obj_name_sf ;
	    global_dq = obj_name_dq ;
					global_qx = obj_name_qx ;
					var cityId=$(global_dq).value;
					var pars	= 'action=county&dqcode='+cityId;
					var url=siteurl+"index/ajax/city";
					var myAjax	= new Ajax.Request(
						url, 
						{
							parameters: pars, 
							onSuccess: updateGetCountys
						});
}
function updateGetCountys(originalRequest)
{
				var responseText				= originalRequest.responseText;
				eval(responseText);
				$(global_qx).options.length = 0;
				$(global_qx).options[0]=new Option("所属区县",0);
				var i=1;
				for (var key in theCountys)
				{
						$(global_qx).options[i] = new Option(theCountys[key], key);
						i = i + 1;
				}
}


function buy(shopID){
	if(shopID==0){
		alert("请先登录！");
		if(document.getElementById("loginDiv")==null){
			showLogin();
		}else{
		
		}
	}else{
		this.disabled=false;
		location.href=siteurl+"index/payment/index/"+shopID;
	}
}

function delBuy(shopID){
	location.href=siteurl+"index/payment/delbuy/"+shopID;
}

function loadRar(shopID){
	if(shopID==0){
		alert("请先登录！");
		if(document.getElementById("loginDiv")==null){
			showLogin();
		}else{
		
		}
	}else{
		var newWindow = window.open(siteurl+"index/download/index/"+shopID,'_blank','height=200,width=400,status=yes,toolbar=no,menubar=no,location=no,top=10000');    
    	newWindow.document.execCommand('saveas'); 
    	newWindow.close(); 
	}
}
function payment(){
	if($("to_name").value==''){alert("请填写收货人");return false;}
	if($("to_phone").value==''){alert("请填写收货人电话或手机");return false;}
	if($("to_zip").value==''){alert("请填写收货人邮编");return false;}
	if($("to_address").value==''){alert("请填写收货人地址");return false;}
	if($("to_remark").value.length>100){alert("备注不能多于100字符!");return false;};
	$("paymentForm").submit();
}
function ucReg(){
	location.href=siteurl+"/home/do.php?ac=23a4ae83f162e482545c7d10b0cf0d80";	
}
function showLogin(){
	var bodyWidth=document.body.scrollWidth;
	var bodyHeight=document.body.clientHeight>document.body.scrollHeight?document.body.clientHeight:document.body.scrollHeight;
	var loginDiv=document.createElement("div");
	var loginTop=Math.ceil((document.body.clientHeight-80)/2)+document.body.scrollTop;
	with(loginDiv){
		id="loginDIV";
		align="center";
		style.width=bodyWidth;
		style.height=bodyHeight;
		style.backgroundColor="#ccc";
		style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=70)";
		style.position="absolute";	
		style.top=0;
		style.left=0;
	}
	document.body.appendChild(loginDiv);	
	var loginTable=document.createElement("div");
	with(loginTable){
		id="loginTable";
		align="center";
		style.position="absolute";	
		style.width=bodyWidth;
		style.height=bodyHeight;
		style.top=0;
		style.left=0;
		innerHTML="<table border=0 style=\"font-size:13px;margin-top:"+loginTop+"px;background-color:#ff9;\" ><tr><td colspan=2 style=\"height:10px;font-size:10px;\" align=right><span id=\"exitLogin\" style=\"cursor:pointer;\">取消</span></td></tr><tr><td colspan=2 align=center>请登录</td></tr><tr><td>帐号:</td><td><input type=\"text\" id=loginUser maxlenght=16></td></tr><tr><td>密码:</td><td><input type=\"password\" id=loginPwd maxlenght=16 ></td></tr><tr><td colspan=2 align=center><input type=\"button\" value=\"登录\" onClick=\"ucLogin()\" >  <input type=\"button\" value=\"注册\" onClick=\"ucReg()\" ></td></tr><tr><td colspan=2 style=\"height:10px;font-size:9px;\" align=right>&nbsp;</td></table>";
		}
	document.body.appendChild(loginTable);
	$("exitLogin").onmouseover=function(){$("exitLogin").style.color="#FF0000";}
	$("exitLogin").onmouseout=function(){$("exitLogin").style.color="#666";}
	$("exitLogin").onclick=function(){delObj("loginTable");delObj("loginDiv");}
}

function delObj(oid){
		document.body.removeChild($(oid));
}

function ucLogin(){
		var ucName=$("loginUser").value;
		var ucPwd=$("loginPwd").value;
		if(ucName=='' || ucPwd==''){alert("请填写账户密码!");return false}
		var pars	= 'action=shopLogin&ucname='+ucName+'&ucpwd='+ucPwd;
		var url=siteurl+"index/ajax/index";
		var myAjax	= new Ajax.Request(
			url, 
			{
				parameters: pars, 
				onSuccess: updateLogin
			});
		
}

function updateLogin(originalRequest)
{
	var responseText				= originalRequest.responseText;
	if(responseText=="OK"){
		location.reload();
	}else{
		alert("账户或密码错误!");
		$("loginUser").value="";
		$("loginPwd").value="";
		$("loginUser").focus();
	}
}