﻿/**
* @param string   url      
* @param string   callback  回调函数
* @param string  data      post数据
* @return void
*/
function downloadUrl(url, callback, data) {
    // init
    url += url.indexOf("?") >= 0 ? "&" : "?";
    url += "random_download_url=" + Math.random();

    if (typeof data == 'undefined') {
        var data = null;
    }

    method = data ? 'POST' : 'GET';
    // create XMLHttpRequest object
    if (window.XMLHttpRequest) {
        var objXMLHttpRequest = new XMLHttpRequest();
    }
    else {
        var MSXML = ['MSXML2.XMLHTTP.6.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];
        for (var n = 0; n < MSXML.length; n++) {
            try {
                var objXMLHttpRequest = new ActiveXObject(MSXML[n]);
                break;
            }
            catch (e) {
                alert(e);
            }
        }
    }

    // send request
    with (objXMLHttpRequest) {
        //setTimeouts(30*1000,30*1000,30*1000,30*60*1000);
        try {
            open(method, url, true);

            if (method == 'POST') {
                setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
            }
            //setRequestHeader("If-Modified-Since", "0");
            send(data);
        }
        catch (e) {
            alert(url+","+e);
        }
        // on ready
        onreadystatechange = function() {
            if (objXMLHttpRequest.readyState == 4) {
                callback(objXMLHttpRequest.responseText, objXMLHttpRequest.status);
                delete (objXMLHttpRequest);
            }
        }
    }
}

//回调函数
function callBack(data, responseCode) {
	if(responseCode!=200)
	{
		alert('提交未完成');
	}
	else
	{
		if(data.indexOf("logout:") >= 0 || data.indexOf("login:") >= 0)
		{
			if(document.getElementById("loginArea")!=null){
				document.getElementById("loginArea").innerHTML = data.replace("logout:","").replace("login:","");
			}
			//location.reload();
		}
		else if(data.indexOf("admin_login_error:")>=0){
			alert (data.replace("admin_login_error:",""));
		}
		else if(data.indexOf("login_error:")>=0){
			alert ('登录失败：'+data.replace("login_error:",""));
		}
		else if(data=="Register_OK"){
			alert ('恭喜你，已经注册成功！');
			location.href="index.aspx";
		}
		else if(data.indexOf("Register_error:")>=0)
		{
			alert ('对不起，注册失败：'+data.replace("Register_error:",""));
		}
		else if(data=="RegisterCheck_ok"){
			alert ('恭喜你，该用户名尚未被注册。');
		}
		else if(data=="RegisterCheck_relation"){
			alert ('该用户名已经在关联站点中被使用了，如果您是该用户名的持有者，无须再注册，直接登陆即可。否则请重新选择用户名，谢谢。');
		}
		else if(data=="RegisterCheck_exist"){
			alert ('对不起，该用户名已经被注册了。请重新选择。');
			document.getElementById("reg_username").focus();
		}
		else if(data=="EditProfile_OK"){
			alert ('恭喜你，资料已经成功更改。');
		}
		else if(data.indexOf("EditProfile_error:")>=0){
			alert ('对不起，资料更新失败：'+data.replace("EditProfile_error:",""));
		}
		else if(data=="ShopCarSubmit_ok"){
			alert('订单操作已经成功提交！'); 
			location.href="/OrderList.aspx";
		}
		else if(data.indexOf("ShopCar_error:")>=0){
			alert (data.replace("ShopCar_error:",""));
		}
		else if(data.indexOf("ShopCar_ok:")>=0){
			data=data.replace("ShopCar_ok:","");
			if(data.indexOf(",")>=0){
				var datas=data.split(',');
				updateNavCar(datas[0],datas[1]);
			}
		}
		else if(data.indexOf("message_error:")>=0){
			alert (data.replace("message_error:",""));
			if(document.getElementById("message_submit")!=null){
				document.getElementById("message_submit").disabled=false;
			}
		}
		else if(data=="message_ok"){
			alert ('恭喜你，留言你已经成功提交，请等待站点管理员的审核。');
			document.getElementById("message_title").value="";
			document.getElementById("message_body").value="";
			if(document.getElementById("message_submit")!=null){
				document.getElementById("message_submit").disabled=false;
			}
		}
		else if(data.indexOf("message_audit_ok:")>=0){
			alert ('OK，操作成功提交。');
			data=data.replace("message_audit_ok:","")
			if(data.indexOf(",")>=0){
				var datas=data.split(',');
				if(document.getElementById("message_status_"+datas[0])!=null){
					document.getElementById("message_status_"+datas[0]).innerHTML=datas[1];
				}
			}
		}
		else if(data.indexOf("message_audit_error:")>=0){
			alert (data.replace("message_audit_error:",""));
		}
		else if(data.indexOf("message_reply_ok:")>=0){
			data=data.replace("message_reply_ok:","");
			if(data.indexOf(",")>=0){
				var datas=data.split(',');
				alert (datas[1]);
				if(document.getElementById("message_"+datas[0])!=null && document.getElementById("replyArea_"+datas[0])!=null){
					document.getElementById("message_"+datas[0]).style.display="";
					document.getElementById("replyArea_"+datas[0]).innerHTML=datas[2];
					document.getElementById("replyArea_"+datas[0]).style.display="";
				}
			}
		}
		else if(data.indexOf("message_getreply_ok:")>=0){
			document.getElementById("message_body").value=data.replace("message_getreply_ok:","");
		}
		else if(data.indexOf("message_getreply_error:")>=0){
		}
		else if(data.indexOf("message_reply_error:")>=0){
			alert (data.replace("message_reply_error:",""));
		}
		else if(data.indexOf("products_del_ok:")>=0){
			alert ('该产品已经成功被删除！');
			var pid=data.replace("products_del_ok:","");
			var id_array=pid.split(',');
			for(i=0;i<id_array.length;i++){
				if(document.getElementById("ptr_"+id_array[i])!=null){
					document.getElementById("ptr_"+id_array[i]).style.display="none";
				}
				else{
					this.location.reload();
				}
			}
		}
		else if(data.indexOf("products_del_error:")>=0){
			alert (data.replace("products_del_error:",""));
		}
		else if(data=="productModify_ok"){
			alert ('产品修改已经成功执行。');
		}
		else if(data.indexOf("productModify_error:")>=0){
			alert (data.replace("productModify_error:",""));
		}
		else if(data=="productcreate_ok"){
			alert ('成功添加新产品！');
			var currentUrl=document.location.href;
			currentUrl=currentUrl.toLowerCase();
			if(currentUrl.indexOf("iswap=true")>=0){
				location.href='Admin_ProductsManage.aspx?iswap=true';
			}
			else{
				location.href='Admin_ProductsManage.aspx';
			}
		}
		else if(data.indexOf("productcreate_error:")>=0){
			alert (data.replace("productcreate_error:",""));
		}
		else if(data.indexOf("news_del_ok:")>=0){
			alert ('该新闻已经成功被删除！');
			var nid=data.replace("news_del_ok:","");
			var id_array=nid.split(',');
			for(i=0;i<id_array.length;i++){
				if(document.getElementById("ntr_"+id_array[i])!=null){
					document.getElementById("ntr_"+id_array[i]).style.display="none";
				}
				else{
					this.location.reload();
				}
			}
		}
		else if(data.indexOf("news_del_error:")>=0){
			alert (data.replace("news_del_error:",""));
		}
		else if(data=="newsModify_ok"){
			alert ('新闻修改已经成功执行。');
		}
		else if(data.indexOf("newsModify_error:")>=0){
			alert (data.replace("newsModify_error:",""));
		}
		else if(data=="newscreate_ok"){
			alert ('成功添加新闻！');
			var currentUrl=document.location.href;
			currentUrl=currentUrl.toLowerCase();
			if(currentUrl.indexOf("iswap=true")>=0){
				location.href='Admin_NewsManage.aspx?iswap=true';
			}
			else{
				location.href='Admin_NewsManage.aspx';
			}
		}
		else if(data.indexOf("newscreate_error:")>=0){
			alert (data.replace("newscreate_error:",""));
		}
		else if(data.indexOf("gettenpay:")>=0){
			var tenpayurl=data.replace("gettenpay:","");
			if(tenpayurl.indexOf("http")>=0){
					window.location.href=tenpayurl;
			}
			else{
				alert (tenpayurl);
			}
		}
		else if(data.indexOf("getalipay:")>=0){
			var alipayurl=data.replace("getalipay:","");
			if(alipayurl.indexOf("http")>=0){
					window.location.href=alipayurl;
			}
			else{
				alert (alipayurl);
			}
		}
		else if(data.indexOf("member_del_ok:")>=0){
			alert ('成功删除该会员');
			var itemobj=document.getElementById("mem_"+data.replace("member_del_ok:",""));
			if(itemobj!=null){
				itemobj.style.display="none";
			}
		}
		else if(data.indexOf("member_del_error:")>=0){
			alert (data.replace("member_del_error:",""));
		}
		else if(data.indexOf("fileManage_delOK:")>=0){
			alert ('对象删除成功！');
			var row=document.getElementById("tr_/"+data.replace("fileManage_delOK:",""));
			if(row!=null){
				row.style.display="none";
			}
			else{
				alert (data.replace("fileManage_delOK:",""));
			}
		}
		else if(data.indexOf("fileManage_delError:")>=0){
			alert (data.replace("fileManage_delError:",""));
		}
		else if(data=="fileManage_clearOK"){
			alert ('清空成功！');
			var listobj=document.getElementById("rightObjList");
			if(listobj!=null){
				if(listobj.rows.length>2){
					for(i=1;i<listobj.rows.length-1;i++){
						listobj.rows[i].style.display="none";
					}
				}
			}
		}
		else if(data.indexOf("fileManage_clearError:")>=0){
			alert (data.replace("fileManage_clearError:",""));
		}
		else if(data.indexOf("fileManage_delSomeObjOK:")>=0){
			alert ('删除成功！');
			HiddenDeletedObjs(data.replace("fileManage_delSomeObjOK:",""));
		}
		else if(data.indexOf("fileManage_delSomeObjError:")>=0){
			alert (data.replace("fileManage_delSomeObjError:",""));
		}
		else if(data=="channelmanage_delok"){
			alert ('频道已经成功删除。');
		}
		else if(data=="channelmanage_midifyok"){
			alert ('频道更新成功。');
		}
		else if(data.indexOf("channelmanage_ok:")>=0){
			alert ('频道创建成功');
			var str=data.replace("channelmanage_ok:","");
			if(str!=null && str.indexOf(",")>=0){
				var nodes=str.split(',');
				var types=document.getElementsByName("type_"+nodes[1]);
				var urls=document.getElementsByName("url_"+nodes[1]);
				if(types!=null && types.length>nodes[0]){
					types[nodes[0]].disabled="disabled";
					urls[nodes[0]].disabled="disabled";
				}
			}
		}
		
		else if(data.indexOf("channelmanage_error:")>=0){
			alert ('频道创建失败：'+data.replace("channelmanage_error:",""));
		}
		else if(data.indexOf("binddomain_ok:")>=0){
			alert ('成功绑定域名。');
			document.getElementById("addDomainButton").disabled="";
			document.getElementById("addDomain").value="";
			var selectcontrol=document.getElementById("bindedDomain");
			if(selectcontrol!=null){
				var domain=data.replace("binddomain_ok:","").split(',');
				selectcontrol.options.add(new Option(domain[0],domain[0]));
				if(domain[1]!=null && domain[1]!=""){
					var mailDomainlist=document.getElementById("mailDomain");
					if(mailDomainlist!=null){
						mailDomainlist.options.add(new Option(domain[1],domain[1]));
						if(document.getElementById("mail_tips")!=null){
							document.getElementById("mail_tips").style.display="none";
						}
					}
				}
			}
		}
		else if(data.indexOf("createmail_ok:")>=0){
			alert ('邮局创建成功！');
			location.reload();
			/*
			document.getElementById("mailStatus").innerHTML="<font color=green>"+data.replace("createmail_ok:","")+"</font> 运行中...";
			var cmb=document.getElementById("createMailButton");
			cmb.value="创建邮局";
			cmb.disabled="";
			document.getElementById("create_area").style.display="none";
			*/
		}
		else if(data.indexOf("createEmailAccout_ok:")>=0){
			alert ('邮箱创建成功！');
			var row=data.replace("createEmailAccout_ok:","");
			if(row!=null && row!=""){
				document.getElementById("email_"+row).disabled="disabled";
				document.getElementById("password_"+row).disabled="disabled";
				document.getElementById("buttonid_"+row).disabled="disabled";
			}
		}
		else if(data.indexOf("mailcenter_error:")>=0){
			document.getElementById("addDomainButton").disabled="";
			//document.getElementById("createMailButton").disabled="";
			alert (data.replace("mailcenter_error:",""));
		}
		else if(data.indexOf("admin_channeleditor_ok")>=0){
			alert ('保存已经成功提交！');
		}
		else if(data.indexOf("admin_channeleditor_error:")>=0){
			alert (data.replace("admin_channeleditor_ok:",""));
		}
		else if(data=="admin_login_ok"){
			location.href="admin_main.aspx";
		}
		else if(data=="admin_logout_ok"){
			location.href="admin.aspx";
		}
		else if(data=="acceptOrder_ok"){
			alert ('订单已受理。');
		}
		else if(data.indexOf("acceptOrder_error:")>=0){
			alert (data.replace("acceptOrder_error:",""));
			if(document.getElementById("acceptOrderButton")!=null){
				document.getElementById("acceptOrderButton").disabled=false;
			}
		}
		else if(data!="ok")
		{
			//alert (responseCode);
			location.reload();
			//alert(responseCode+","+data); // 这里处理返回的数据
		}
		else{
			//alert ('没人管'+data);
		}
	}
    //document.getElementById('result').innerText = '处理结果：'+responseCode;
}

//Cookie写入
function SetCookie(name,value){
	var argv=SetCookie.arguments;
	var argc=SetCookie.arguments.length;
	var expires=(2<argc)?argv[2]:null;
	var path=(3<argc)?argv[3]:null;
	var domain=(4<argc)?argv[4]:null;
	var secure=(5<argc)?argv[5]:false;
	document.cookie=name+"="+escape(value)+((expires==null)?"":("; expires="+expires.toGMTString()))+((path==null)?"":("; path="+path))+((domain==null)?"":("; domain="+domain))+((secure==true)?"; secure":"");
} 

//Cookie读取
function GetCookie(Name) {
	var search = Name + "=";
	var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);
		if (offset != -1) { 
			offset += search.length;
			end = document.cookie.indexOf(";", offset); 
			if (end == -1)
				end = document.cookie.length;
			returnvalue=unescape(document.cookie.substring(offset,end));
		}
	}
	return returnvalue;
}

//
function GoToFriendLink(url) {
    if (url != "") {
        window.open(url);
    }
}

var theOpenMenu;

function FlashOnClick(proName) {
    if (theOpenMenu == null) {
        ShowMenu(proName);
    }
    else if (theOpenMenu == proName) {
        HiteMenu(proName);
    }
    else {
        HiteMenu(theOpenMenu);
        ShowMenu(proName);
    }
}

function ShowMenu(proName) {
    var cols = document.getElementById(proName);
    if (cols != null)
        eval("" + proName + ".style.display = \"inline\";")
    else {
        for (i = 0; i < 50; i++) {
            var colss = document.getElementById(proName + "_" + i);
            if (colss != null)
                eval("" + proName + "_" + i + ".style.display = \"inline\";");
            else
                break;
        }
    }
    theOpenMenu = proName;
}

function HiteMenu(proName) {
    var cols = document.getElementById(proName);
    if (cols != null)
        eval("" + proName + ".style.display = \"none\";")
    else {
        for (i = 0; i < 50; i++) {
            var colss = document.getElementById(proName + "_" + i);
            if (colss != null)
                eval("" + proName + "_" + i + ".style.display = \"none\";");
            else
                break;
        }
    }
    theOpenMenu = null;
}

function Navigator_DoFScommand(command, args) {
    FlashOnClick("pro" + args);
    //alert(command+","+args);
}

function AddToShoppingCar() {
    var url;
	url = document.location.href;
    if (url != null) {
        url = url.toLowerCase();
		if(url.indexOf('.aspx')!=-1)
		{
			url=url.substr(0,url.indexOf('.aspx'));
			url = url.substr(url.lastIndexOf('/')+1,url.length-url.lastIndexOf('/')-1);
			var postData = "type=1&id="+url+"&name=晚秋枫叶";
			//document.getElementById('result').innerText = '数据提交中....';
    		//downloadUrl('/shoppingcar.aspx?type=1&id='+url, callBack,null);
			downloadUrl('/shoppingcar.aspx', callBack,postData);
		}
    }
    alert('已成功添加到购物车');
}

function AddThisAndCheckNow() {
	var url;
	url = document.location.href;
    if (url != null) {
        url = url.toLowerCase();
		if(url.indexOf('.aspx')!=-1)
		{
			url=url.substr(0,url.indexOf('.aspx'));
			url = url.substr(url.lastIndexOf('/')+1,url.length-url.lastIndexOf('/')-1);
			var postData = "type=1&id="+url+"&name=晚秋枫叶";
			//document.getElementById('result').innerText = '数据提交中....';
    		//downloadUrl('/shoppingcar.aspx?type=1&id='+url, callBack,null);
			downloadUrl('/shoppingcar.aspx', callBack,postData);
			location.href="/shoppingcar.aspx";
		}
    }
}

function AddToShoppingCarByID(id) {
	id = id.toLowerCase();
	if(id.indexOf('.aspx')!=-1){
		id=id.substr(0,id.indexOf('.aspx'));
		id = id.substr(id.lastIndexOf('/')+1,id.length-id.lastIndexOf('/')-1);
	}
	//alert (id);
	var postData = "type=1&id="+id;
	downloadUrl('/shoppingcar.aspx', callBack,postData);
}

function AddThisAndCheckNowByID(id) {
	id = id.toLowerCase();
	if(id.indexOf('.aspx')!=-1){
		id=id.substr(0,id.indexOf('.aspx'));
		id = id.substr(id.lastIndexOf('/')+1,id.length-id.lastIndexOf('/')-1);
	}
	AddToShoppingCarByID(id);
	location.href="/shoppingcar.aspx";
}

function CheckNow() {
	location.href="/shoppingcar.aspx";
}

//价格结算
function SettlementPrice(){
	if(confirm("确定下订单？")){
		var postData = "type=10";
		if(document.getElementById("order_memo")!=null){
			var memo=document.getElementById("order_memo").value;
			postData+="&memo="+memo;
		}
		downloadUrl('/shoppingcar.aspx', callBack,postData);
		//alert('订单操作已经成功提交！'); 
	}
}

//清空购物车
function ClearCar(){
	if(confirm("确定要清空购物车吗？")){
		var postData = "type=5";
		downloadUrl('/shoppingcar.aspx', callBack,postData);
		location.reload();
		//location.href="/shoppingcar.aspx?temp="+(Math.round(Math.random()*10000));
	}
}

//更新导航上的购物车信息(直接对当前的html中的相关值进行计算，得出新的值)
function resetNavCar(total_price,single_price,tmp_value){
	if(document.getElementById("nav_total_num")!=null){
		var tmp_total_price=parseFloat(total_price);
		var tmp_total_price2=parseFloat(single_price*tmp_value);
		var Spread=0;
		if(tmp_total_price<tmp_total_price2){
			Spread=(tmp_total_price2-tmp_total_price)/parseFloat(single_price);
			document.getElementById("nav_total_num").innerText=parseFloat(document.getElementById("nav_total_num").innerText)+Spread;
		}
		else
		{
			Spread=(tmp_total_price-tmp_total_price2)/parseFloat(single_price);
			document.getElementById("nav_total_num").innerText=parseFloat(document.getElementById("nav_total_num").innerText)+Spread;
		}
	}
				
	if(document.getElementById("nav_total_cost")!=null){
		document.getElementById("nav_total_cost").innerText=parseFloat(total_cost)+parseFloat(single_price*tmp_value)-parseFloat(total_price);
	}
}

//更新导航上的购物车信息(直接用ajax返回的值替换掉html中的值)
function updateNavCar(new_num,new_cost){
	if(document.getElementById("nav_total_num")!=null && document.getElementById("nav_total_cost")!=null){
		document.getElementById("nav_total_num").innerText=new_num;
		document.getElementById("nav_total_cost").innerText=new_cost;
	}
}

//重设价格
function resetPrice(num) {
	var tmp_value = document.getElementById("num_"+num).value;
	if (tmp_value!=null){
		if(IsInt(tmp_value)==false){
			alert ('对不起,数量必须是整数的！');
		}
		else
		{
			var single_price = document.getElementById("singlePrice_"+num).innerText;
			var total_price = document.getElementById("total_"+num).innerText;
			var total_cost = document.getElementById("total_cost").innerText;
			if(single_price!=null && total_price!=null && total_cost!=null){
				var postData = "type=4&id="+num+"&num="+tmp_value;
				downloadUrl('/shoppingcar.aspx', callBack,postData);
				document.getElementById("total_"+num).innerText=single_price*tmp_value;
				document.getElementById("total_cost").innerText=parseFloat(total_cost)+parseFloat(single_price*tmp_value)-parseFloat(total_price);
				//alert (single_price+","+total_price+","+total_cost+","+single_price*tmp_value+","+(parseFloat(total_cost)+parseFloat(single_price*tmp_value)));
				//resetNavCar(total_price,single_price,tmp_value);
			}
			//alert (tmp_value);
		}
	}
}

//移除某种商品
function RemoveProduct(num){
	var postData = "type=3&id="+num;
	downloadUrl('/shoppingcar.aspx', callBack,postData);
	location.reload();
}

//登陆
function Login(){
	if(document.getElementById("login_user")!=null && document.getElementById("login_pass")!=null)
	{
		var tmp_user = document.getElementById("login_user").value;
		var tmp_pass = document.getElementById("login_pass").value;
		if(tmp_user==""){
			alert ('用户名是必须填的！');
			document.getElementById("login_user").focus(); 
			return;
		}
		if(tmp_pass==""){
			alert ('密码是必须填的！');
			document.getElementById("login_pass").focus(); 
			return;
		}
		var postData = "op=login&username="+tmp_user+"&password="+tmp_pass;
		var postUrl=document.location.href;
		if(postUrl.substring(postUrl.length-1,postUrl.length)=="/"){
			postUrl=postUrl+"index.aspx";
		}
		downloadUrl(postUrl, callBack,postData);
		//downloadUrl('/login.aspx', callBack,postData);
		//alert (tmp_user+','+tmp_pass);
		//location.reload();
	}
	else{
		alert ('参数错误。');	
	}
}

//退出
function Logout(){
	var postData = "op=logout";
	var postUrl=document.location.href;
		if(postUrl.substring(postUrl.length-1,postUrl.length)=="/"){
			postUrl=postUrl+"index.aspx";
		}
	downloadUrl(postUrl, callBack,postData);
	//downloadUrl('/logout.aspx', callBack,postData);
}

//注册
function Register(){
	location.href="/register.aspx";
}

//检查用户是否存在
function checkUserIsExist(){
	if(document.getElementById("reg_username")==null)
	{
		alert ('reg_username为null');
		return;
	}
	var tmp_username=document.getElementById("reg_username").value;
	if(tmp_username!=""){
		var postData="op=check&username="+tmp_username;
		downloadUrl('/Register.aspx',callBack,postData);
	}
}

//注册提交
function RegisterSubmit(){
	if(document.getElementById("reg_username")==null)
	{
		alert ('reg_username为null');
		return;
	}
	if(document.getElementById("reg_userpass")==null)
	{
		alert ('reg_userpass为null');
		return;
	}
	var tmp_name=document.getElementById("reg_username").value;
	var tmp_pass=document.getElementById("reg_userpass").value;
	if(tmp_name==""){
		alert ('用户名不能为空！');
		document.getElementById("reg_username").focus();
		return;
	}
	if(tmp_name.length<4 || tmp_name.length>20)
	{
		alert ('用户名的长度必须是4--20位。');
		document.getElementById("reg_username").focus();
		return;
	}
	if(tmp_pass==""){
		alert ('密码不能为空！');
		document.getElementById("reg_userpass").focus();
		return;
	}
	if(tmp_pass.length<6 || tmp_pass.length>20){
		alert ('密码长度必须是6--20位。');
		document.getElementById("reg_userpass").focus();
		return;
	}
	
	var tmp_repass=document.getElementById("reg_repass").value;
	if(tmp_repass==""){
		alert ('确认密码不能为空！');
		document.getElementById("reg_repass").focus();
		return;
	}
	if(tmp_repass!=tmp_pass){
		alert ('输入的两次密码不一致！请重新确认。');
		document.getElementById("reg_repass").focus();
		return;
	}
	var tmp_realname=document.getElementById("reg_realname").value;
	if(tmp_realname==""){
		alert ('请填写真实姓名。');
		document.getElementById("reg_realname").focus();
		return;
	}
	var tmp_tel=document.getElementById("reg_tel").value;
	var tmp_mobile=document.getElementById("reg_mobile").value;
	if(tmp_tel=="" && tmp_mobile==""){
		alert ('固定电话和移动电话，最少要填写一个！');
		document.getElementById("reg_tel").focus();
		return;
	}
	var tmp_agreement=document.getElementById("reg_agreement").checked;
	if(!tmp_agreement){
		alert ('必须接受网站会员协议才可以注册。');
		return;
	}
	var tmp_email=document.getElementById("reg_email").value;
	var tmp_fax=document.getElementById("reg_fax").value;
	var tmp_addr=document.getElementById("reg_addr").value;
	var tmp_zip=document.getElementById("reg_zip").value;
	var tmp_sex="1";

	if(document.getElementById("sex_female").checked){
		tmp_sex="0";
	}
	var tmp_qq=document.getElementById("reg_qq").value;
	var tmp_msn=document.getElementById("reg_msn").value;

	if(tmp_name!=null && tmp_pass!=null){
		var postData="op=new&username="+tmp_name+"&userpass="+tmp_pass+"&repass="+tmp_repass+"&realname="+tmp_realname+"&tel="+tmp_tel+"&mobile="+tmp_mobile+"&email="+tmp_email+"&fax="+tmp_fax+"&addr="+tmp_addr+"&zip="+tmp_zip+"&sex="+tmp_sex+"&qq="+tmp_qq+"&msn="+tmp_msn;
		//alert (postData);
		downloadUrl('/Register.aspx',callBack,postData);
	}
	else{
		alert ('用户名和密码必须填！');
	}
}

//个人资料修改
function editProfile(){
	location.href="/editProfile.aspx";
}

function profileEditSubmit(){
	var tmp_name=document.getElementById("reg_username").value;
	var tmp_pass=document.getElementById("reg_userpass").value;
	var tmp_repass=document.getElementById("reg_repass").value;

	if(tmp_pass!="" || tmp_repass!=""){
		if(tmp_pass!=tmp_repass){
			alert ('输入的两次密码不一致！请重新确认。');
			document.getElementById("reg_repass").focus();
			return;
		}
	}
	
	var tmp_realname=document.getElementById("reg_realname").value;
	if(tmp_realname==""){
		alert ('请填写真实姓名。');
		document.getElementById("reg_realname").focus();
		return;
	}
	var tmp_tel=document.getElementById("reg_tel").value;
	var tmp_mobile=document.getElementById("reg_mobile").value;
	if(tmp_tel=="" && tmp_mobile==""){
		alert ('固定电话和移动电话，最少要填写一个！');
		document.getElementById("reg_tel").focus();
		return;
	}
	var tmp_email=document.getElementById("reg_email").value;
	var tmp_fax=document.getElementById("reg_fax").value;
	var tmp_addr=document.getElementById("reg_addr").value;
	var tmp_zip=document.getElementById("reg_zip").value;
	var tmp_sex="1";

	if(document.getElementById("sex_female").checked){
		tmp_sex="0";
	}
	var tmp_qq=document.getElementById("reg_qq").value;
	var tmp_msn=document.getElementById("reg_msn").value;

	var postData="op=modify&userpass="+tmp_pass+"&repass="+tmp_repass+"&realname="+tmp_realname+"&tel="+tmp_tel+"&mobile="+tmp_mobile+"&email="+tmp_email+"&fax="+tmp_fax+"&addr="+tmp_addr+"&zip="+tmp_zip+"&sex="+tmp_sex+"&qq="+tmp_qq+"&msn="+tmp_msn;
	downloadUrl('/EditProfile.aspx',callBack,postData);
}

//我的订单列表
function myOrderList(){
	location.href="/OrderList.aspx";
}

//判断是否为整数
function IsInt(input) {
	var re = /^\d+$/;
	if (!re.test(input)) {
  		return false;
 	}
}

//检查是否为浮点型
function checkRate(input) {
	var re = /^[0-9]+.?[0-9]*$/;
	if (!re.test(input)) {
  		return false;
 	}
} 
///管理员退出
function adminLogout(){
	var postData="logout=true";
	//downloadUrl('/Admin/admin_main.aspx',callBack,postData);
	downloadUrl('admin_main.aspx',callBack,postData);
}

//-----------------------------------------------------------
//站点管理员登陆
function adminLogin(){
	if(document.getElementById("userID")==null){
		alert ('缺乏必要的参数userID！');
		return;
	}
	if(document.getElementById("userPass")==null){
		alert ('缺乏必要的参数userPass');
		return;
	}
	if(document.getElementById("ValidCode")==null){
		alert ('缺乏必要的参数ValidCode');
		return;
	}
	var userID=document.getElementById("userID").value;
	var userPass=document.getElementById("userPass").value;
	var vcode=document.getElementById("ValidCode").value;
	if(userID=="" || userPass==""){
		alert ('用户名和密码不能为空！');
		return;
	}
	if(vcode=="" || vcode.length!=5){
		alert ('错误的验证码！');
		return;
	}
	var postData="login=true&userid="+userID+"&userpass="+userPass+"&validcode="+vcode;
	downloadUrl('admin_main.aspx',callBack,postData);
}

//受理订单
function acceptOrder(orderID){
	if(document.getElementById("acceptOrderButton")!=null){
		document.getElementById("acceptOrderButton").disabled=true;
	}
	var postData="acceptorder="+orderID;
	downloadUrl('admin_main.aspx',callBack,postData);
}
//搜索功能
function CADSearch(){
	if(document.getElementById("search_keywords")==null){
		alert ('页面缺少相关的关键字输入框');
		return;
	}
	var keyword=document.getElementById("search_keywords").value;
	if(keyword==null || keyword==""){
		alert ('关键字不可以为空！');
		return;
	}
	location.href='search.aspx?q='+escape(keyword);
}

//留言提交
function message_post(){
	if(document.getElementById("message_title")==null){
		alert ('页面缺少标题输入框!');
		return;
	}
	if(document.getElementById("message_body")==null){
		alert ('页面缺少内容输入框!');
		return;
	}
	var tmp_title=document.getElementById("message_title").value;
	var tmp_body=document.getElementById("message_body").value;
	if(tmp_title==null || tmp_title==""){
		alert ('标题不能为空！');
		document.getElementById("message_title").focus();
		return;
	}
	if(tmp_body==null || tmp_body==""){
		alert ('内容不能为空！');
		document.getElementById("message_body").focus();
		return;
	}
	if(document.getElementById("message_submit")!=null){
		document.getElementById("message_submit").disabled=true;
	}
	var postData="messageop=post&title="+tmp_title+"&body="+tmp_body;
	downloadUrl('/guestbook.aspx',callBack,postData);
}

//查看留言
function message_view(messageID){   
	var tr_name="message_"+messageID;
	view_control(tr_name);
}

//查看留言(用于后台查看回复)
function message_view2(messageID,title,bodystr){   
	var tr_name="message_"+messageID;
	view_control(tr_name);
	gotoReply_internal(messageID,title);
	if(document.getElementById("message_body")!=null){
		if(bodystr==""){
			var postData="messageop=getreply&messageid="+messageID;
			var url=document.location.href;
			downloadUrl(url,callBack,postData);
		}
		else{
			document.getElementById("message_body").value="";
		}
	}
}

//回复留言
function gotoReply(messageID,title,bodystr){
	gotoReply_internal(messageID,title);
	if(document.getElementById("message_body")!=null){
		document.getElementById("message_body").focus();
		if(bodystr==""){
			var postData="messageop=getreply&messageid="+messageID;
			var url=document.location.href;
			downloadUrl(url,callBack,postData);
		}
		else{
			document.getElementById("message_body").value="";
		}
		
	}
}
//gotoReply内部调用 
function gotoReply_internal(messageID,title){
	if(document.getElementById("message_id")!=null){
		document.getElementById("message_id").value=messageID;
	}
	if(document.getElementById("message_title")!=null){
		document.getElementById("message_title").value="reply:"+title;
		document.getElementById("message_title").readOnly=true;
	}
}

//展开或关闭留言Item
function view_control(param){
	if(document.getElementById(param).style.display=="none"){
		document.getElementById(param).style.display="";
		if(document.getElementById("message_allid")!=null){
			var allid=document.getElementById("message_allid").value;
			if(allid!=null && allid.indexOf(",")>=0){
				var ids=allid.split(',');
				for (i = 0; i < ids.length-1; i++) {
					if(param!="message_"+ids[i]){
						var messageItem=document.getElementById("message_"+ids[i]);
						if(messageItem!=null){
							messageItem.style.display="none";
						}
					}
				}
			}
		}
    }
    else{
       document.getElementById(param).style.display="none";
    }
}

//留言审核
function Audit(id){
	if(id==null || id==""){
		alert ('id参数为空！');
		return;
	}
	var postData="messageop=audit&messageid="+id;
	var url=document.location.href;
	downloadUrl(url,callBack,postData);
}

//回复留言
function message_reply(){
	if(document.getElementById("message_id")==null || document.getElementById("message_body")==null){
		alert ('缺乏必要的页面参数');
		return;
	}
	var messageid=document.getElementById("message_id").value;
	if(messageid==null || messageid==""){
		alert ('在点击回复之前，请先选择要回复哪一条留言！');
		return;
	}
	var content=document.getElementById("message_body").value;
	if(content==null || content==""){
		alert ('内容不能为空！');
		return;
	}
	var postData="messageop=reply&messageid="+messageid+"&replybody="+content;
	var url=document.location.href;
	downloadUrl(url,callBack,postData);
}

//欢迎管理员信息
function WelcomeAdmin(name,lastLogin){
	if(document.getElementById("nick_name")!=null){
		document.getElementById("nick_name").innerText=name;
	}
	if(document.getElementById("lastLoginTime")!=null){
		document.getElementById("lastLoginTime").innerText=lastLogin;
	}
}

//删除产品
function ProductsDel(pid){
	if(confirm("确定删除此产品？")){
		var postData="paction=del&id="+pid;
		var url=document.location.href;
		downloadUrl(url,callBack,postData);
	}
}

//删除某行产品参数
function DelThisRow(){
	if(confirm("确定删除本行参数？")){
		var product_paramTable=document.getElementById("product_TitleAndParam");
		if(product_paramTable!=null){
			/*
			if(window.event.srcElement.tagName == "IMG"){
				alert ("a");
			}
			*/
			var row=-1;
			row=window.event.srcElement.parentElement.parentElement.rowIndex;
			if(row!=-1){
				product_paramTable.deleteRow(row);
				if(product_paramTable.rows.length==2){
					var newTr = product_paramTable.insertRow();
　　					var newTd = newTr.insertCell();
					newTd.style.paddingTop="10px";
					newTd.style.paddingBottom="10px";
　　					//newTd.innerHTML = '<img border="0" style="cursor:hand;" onclick="CreateNewRow2()" src="memberimages/add.png" alt="插入一行新参数" /><input type="button" onclick="CreateNewRow2()" value="插入一行参数输入框" />'; 
					newTd.innerHTML = '<img border="0" style="cursor:hand;" onclick="CreateNewRow2()" src="memberimages/add.png" alt="插入一行新参数" />插入一行参数输入框'; 
				}
			}
		}
	}
}

//新建一行产品参数
function CreateNewRow(){
	var product_paramTable=document.getElementById("product_TitleAndParam");
	if(product_paramTable!=null){
		var row=window.event.srcElement.parentElement.parentElement.rowIndex;
		var newTr = product_paramTable.insertRow(row+1);
		//var tmp_index=product_paramTable.rows.length+1;
　　		var newTd = newTr.insertCell();
		newTd.style.paddingTop="10px";
		newTd.style.paddingBottom="10px";
　　		newTd.innerHTML = '<input type="text" size="8" id="pro_paramTitle" name="pro_paramTitle" value="" />：<input type="text" id="pro_paramValue" name="pro_paramValue" value="" /><img border="0" style="cursor:hand;" onclick="CreateNewRow()" src="memberimages/add.png" alt="插入一行新参数" /><img border="0" style="cursor:hand;" onclick="DelThisRow()" src="memberimages/sub.png" alt="删除本行参数" />'; 
	}
}

//新建一行产品参数
function CreateNewRow2(){
	var product_paramTable=document.getElementById("product_TitleAndParam");
	if(product_paramTable!=null){
		var row=window.event.srcElement.parentElement.parentElement.rowIndex;
		product_paramTable.deleteRow(row);
		var newTr = product_paramTable.insertRow(row);
　　		var newTd = newTr.insertCell();
		newTd.style.paddingTop="10px";
		newTd.style.paddingBottom="10px";
　　		newTd.innerHTML = '<input type="text" size="8" id="pro_paramTitle" name="pro_paramTitle" value="" />：<input type="text" id="pro_paramValue" name="pro_paramValue" value="" /><img border="0" style="cursor:hand;" onclick="CreateNewRow()" src="memberimages/add.png" alt="插入一行新参数" /><img border="0" style="cursor:hand;" onclick="DelThisRow()" src="memberimages/sub.png" alt="删除本行参数" />'; 
	}
}

//初始化数据
function InitOriginalData(title,content){
	var product_intro=document.getElementById("pro_description");
	var currentUrl=document.location.href.toLowerCase();
	if(product_intro!=null){
		var newTr = product_intro.insertRow();
　　		var newTd = newTr.insertCell();
		newTd.style.width="575px";
		newTd.style.height="30px";
		newTd.style.className="pro2_bk";
		newTd.style.verticalAlign="top";
　　		newTd.innerHTML = '<strong>小标题：</strong><input type="text" id="pro_textTitle" name="pro_textTitle" value="'+title+'" /><span style="padding-left:300px;"><img border="0" style="cursor:hand;" onclick="CreateNewBlock()" src="memberimages/add.png" alt="插入内容块" /><img border="0" style="cursor:hand;" onclick="DelThisBlock()" src="memberimages/sub.png" alt="删除本块" /></span>';
		var newTr2 = product_intro.insertRow();
　　		var newTd2 = newTr2.insertCell();
		newTd2.style.paddingBottom="13px";
		var randomNum=Math.random();
		randomNum="pro_textContent_"+randomNum;
		if(currentUrl.indexOf("iswap=true")==-1){
			newTd2.innerHTML='<textarea id="'+randomNum+'" name="pro_textContent" style="width:580px;height:200px;">'+content+'</textarea>'; 
			KE.show({
        		id : ''+randomNum+'',
        		skinType: 'tinymce',
        		cssPath : './index.css',
        		items : [
            		'source', 'preview', 'fullscreen', 'print', 'undo', 'redo', 'cut', 'copy', 'paste',
            		'plainpaste', 'wordpaste', 'justifyleft', 'justifycenter', 'justifyright',
            		'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
            		'superscript', 'date', 'time', 'specialchar', 'link', 'unlink', '-',
            		'title', 'fontname', 'fontsize', 'textcolor', 'bgcolor', 'bold',
            		'italic', 'underline', 'strikethrough', 'removeformat', 'selectall', 'image',
            		'layer', 'table', 'hr'
        		]
    		});
		}
		else{
			newTd2.innerHTML='<textarea id="'+randomNum+'" name="pro_textContent" style="width:580px;height:200px;">'+content.replace(/<br \/>/g,"\r").replace(/<br>/g,"\r").replace(/<br \/>/g,"\r")+'</textarea>'; 
		}
	}
}

//创建一个新的内容块
function CreateNewBlock(){
	var product_intro=document.getElementById("pro_description");
	if(product_intro!=null){
		var row=window.event.srcElement.parentElement.parentElement.parentElement.rowIndex;
		var newTr = product_intro.insertRow(row+2);
		//var tmp_index=product_paramTable.rows.length+1;
　　		var newTd = newTr.insertCell();
		newTd.style.width="575px";
		newTd.style.height="30px";
		newTd.style.className="pro2_bk";
		newTd.style.verticalAlign="top";
　　		newTd.innerHTML = '<strong>小标题：</strong><input type="text" id="pro_textTitle" name="pro_textTitle" value="" /><span style="padding-left:300px;"><img border="0" style="cursor:hand;" onclick="CreateNewBlock()" src="memberimages/add.png" alt="插入内容块" /><img border="0" style="cursor:hand;" onclick="DelThisBlock()" src="memberimages/sub.png" alt="删除本块" /></span>';
		var newTr2 = product_intro.insertRow(row+3);
　　		var newTd2 = newTr2.insertCell();
		newTd2.style.paddingBottom="13px";
		var randomNum=Math.random();
		randomNum="pro_textContent_"+randomNum;
　　		newTd2.innerHTML='<textarea id="'+randomNum+'" name="pro_textContent" style="width:580px;height:200px;"></textarea>'; 
		var currentUrl=document.location.href.toLowerCase();
		if(currentUrl.indexOf("iswap=true")==-1){
			createHtmlEditor(randomNum);
		}
	}
}

//删除某内容块
function DelThisBlock(){
	if(confirm("确定删除本内容块？")){
		var product_intro=document.getElementById("pro_description");
		if(product_intro!=null){
			var row=-1;
			row=window.event.srcElement.parentElement.parentElement.parentElement.rowIndex;
			if(row!=-1){
				product_intro.deleteRow(row+1);
				product_intro.deleteRow(row);
				if(product_intro.rows.length==0){
					var newTr = product_intro.insertRow();
　　					var newTd = newTr.insertCell();
					newTd.style.width="575px";
					newTd.style.height="30px";
					newTd.style.className="pro2_bk";
					newTd.style.verticalAlign="top";
　　					newTd.innerHTML = '<strong>小标题：</strong><input type="text" id="pro_textTitle" name="pro_textTitle" value="" /><span style="padding-left:300px;"><img border="0" style="cursor:hand;" onclick="CreateNewBlock()" src="memberimages/add.png" alt="插入内容块" /><img border="0" style="cursor:hand;" onclick="DelThisBlock()" src="memberimages/sub.png" alt="删除本块" /></span>';
					var newTr2 = product_intro.insertRow();
　　					var newTd2 = newTr2.insertCell();
					newTd2.style.paddingBottom="13px";
					var randomNum=Math.random();
　　					newTd2.innerHTML='<textarea id="pro_textContent_'+randomNum+'" name="pro_textContent" style="width:580px;height:200px;"></textarea>'; 
					var currentUrl=document.location.href.toLowerCase();
					if(currentUrl.indexOf("iswap=true")==-1){
						createHtmlEditor("pro_textContent_"+randomNum);
					}
				}
			}
		}
	}
}

//创建html编辑器
function createHtmlEditor(idstr){
	KE.init({
        id : ''+idstr+'',
        skinType: 'tinymce',
        cssPath : './index.css',
        items : [
            'source', 'preview', 'fullscreen', 'print', 'undo', 'redo', 'cut', 'copy', 'paste',
            'plainpaste', 'wordpaste', 'justifyleft', 'justifycenter', 'justifyright',
            'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
            'superscript', 'date', 'time', 'specialchar', 'link', 'unlink', '-',
            'title', 'fontname', 'fontsize', 'textcolor', 'bgcolor', 'bold',
            'italic', 'underline', 'strikethrough', 'removeformat', 'selectall', 'image',
            'layer', 'table', 'hr'
        ]
    });
	KE.create(''+idstr+'');
}

//引用本地文件夹中的图片
function importFromLocalFolder(){
	//alert ('打开站点文件夹');
	//lhgdialog.opendlg( '打开站点文件夹', 'admin_filemanage.aspx', 800, 600 );
	OpenSiteFileCenterInternal('请选择文件',document.documentElement.clientWidth, document.documentElement.clientHeight);
}

//引用互联网上的图片地址
function importFromInternet(){
	lhgdialog.opendlg( '请输入图片的地址', 'pup.html', 400, 200 );
}

//产品修改
function product_modify(pid){
	product_op(false);
}

//产品创建提交
function product_createSubmit(){
	product_op(true);
}

function product_op(isCreate){
	var p_title,p_price,p_ptitle,p_pvalue,p_texts,p_contents;
	p_ptitle="";
	p_pvalue="";
	p_texts="";
	p_contents="";
	if(document.getElementById("pro_title")!=null){
		p_title=document.getElementById("pro_title").value;
	}
	if(document.getElementById("pro_price")!=null){
		p_price=document.getElementById("pro_price").value;
	}
	if(p_title==null){
		alert ('产品标题不能为空__！');
		document.getElementById("pro_title").focus();
		return;
	}
	if(checkRate(p_price)==false){
		alert ('价格的格式不对！');
		document.getElementById("pro_price").focus();
		return;
	}
	var p_typeObj=document.getElementById("pro_type");
	var p_type;
	if(p_typeObj!=null){
		p_type=p_typeObj.value;
		if(p_type==""){
			alert ('请选择产品归属分类！');
			document.getElementById("pro_type").focus();
			return;
		}
	}
	if(p_type==null || p_type==""){
		p_type=0;
	}
	var paramTitles=document.getElementsByName("pro_paramTitle");
	var paramValues=document.getElementsByName("pro_paramValue");
	if(paramTitles!=null && paramValues!=null){
		for(i=0;i<paramTitles.length;i++){
			var t=paramTitles[i].value;
			var v=paramValues[i].value;
			if(t!=null && t!="" && v!=null && v!=""){
				if(p_ptitle==""){
					p_ptitle=t.replace("@","");
				}
				else{
					p_ptitle+="@"+t.replace("@","");
				}
				if(p_pvalue==""){
					p_pvalue=v.replace("@","");
				}
				else{
					p_pvalue+="@"+v.replace("@","");
				}
			}
		}
	}
	var p_pictureUrl;
	p_pictureUrl="";
	if(document.getElementById("pro_pictureUrl")!=null){
		p_pictureUrl=document.getElementById("pro_pictureUrl").value;
	}
	var textTitles=document.getElementsByName("pro_textTitle");
	var textValues=document.getElementsByName("pro_textContent");
	var currentUrl=document.location.href.toLowerCase();
	if(textTitles!=null && textValues!=null){
		for(i=0;i<textTitles.length;i++){
			var t=textTitles[i].value;
			//var v=textValues[i].value;
			var v;
			if(currentUrl.indexOf("iswap=true")==-1){
				v=KE.util.getData(textValues[i].id);
			}
			else{
				v=textValues[i].value;
			}
			if(t!=null && v!=null && v!=""){
				if(p_texts==""){
					p_texts=t.replace("@","");
					if(p_texts==""){
						p_texts=" ";
					}
				}
				else{
					p_texts+="@"+t.replace("@","");
				}
				
				if(p_contents==""){
					p_contents=v.replace("@","");
					if(p_contents==""){
						p_contents=" ";
					}
				}
				else{
					p_contents+="@"+v.replace("@","");
				}
			}
		}
	}
	if(currentUrl.indexOf("iswap=true")==-1){
		p_contents=p_contents.replace(/&nbsp;/g,"*nbsp;")
	}
	var postData="productaction=modify&title="+p_title+"&price="+p_price+"&paramtitle="+p_ptitle+"&paramvalue="+p_pvalue+"&pictureUrl="+p_pictureUrl+"&p_texts="+p_texts+"&p_contents="+p_contents;
	if(isCreate==true){
		postData="productaction=create&title="+p_title+"&price="+p_price+"&ptype="+p_type+"&paramtitle="+p_ptitle+"&paramvalue="+p_pvalue+"&pictureUrl="+p_pictureUrl+"&p_texts="+p_texts+"&p_contents="+p_contents;
	}
	var url=document.location.href;
	downloadUrl(url,callBack,postData);
}

//创建产品
function CreateNewProduct(){
	var currentUrl=document.location.href;
	currentUrl=currentUrl.toLowerCase();
	if(currentUrl.indexOf("iswap=true")>=0){
		document.location.href='Admin_ProductsEditor.aspx?iswap=true';
	}
	else{
		document.location.href='Admin_ProductsEditor.aspx';
	}
}

//创建新闻
function CreateNewNews(){
	var currentUrl=document.location.href;
	currentUrl=currentUrl.toLowerCase();
	if(currentUrl.indexOf("iswap=true")>=0){
		document.location.href='Admin_NewsEditor.aspx?iswap=true';
	}
	else{
		document.location.href='Admin_NewsEditor.aspx';
	}
}

//删除产品
function NewsDel(nid){
	if(confirm("确定删除此新闻？")){
		var postData="paction=del&id="+nid;
		var url=document.location.href;
		downloadUrl(url,callBack,postData);
	}
}

//新闻修改
function news_modify(nid){
	news_op(false);
}

//添加一条新闻
function news_createSubmit(){
	news_op(true);
}

//新闻的添加编辑操作
function news_op(isCreate){
	if(document.getElementById("news_title")==null){
		alert ('缺少标题参数！');
		return;
	}
	var title=document.getElementById("news_title").value;
	var n_typeObj=document.getElementById("news_type");
	var n_type;
	if(n_typeObj!=null){
		n_type=n_typeObj.value;
		if(n_type==""){
			alert ('请选择新闻分类！');
			document.getElementById("news_type").focus();
			return;
		}
	}
	if(n_type==null || n_type==""){
		n_type=0;
	}
	var titles=document.getElementsByName("content_title");
	var bodys=document.getElementsByName("content_body");
	var n_title,n_body;
	var currentUrl=document.location.href.toLowerCase();
	if(titles!=null && bodys!=null){
		for(i=0;i<titles.length;i++){
			var t=titles[i].value;
			//var v=bodys[i].value;
			var v;
			if(currentUrl.indexOf("iswap=true")==-1){
				v=KE.util.getData(bodys[i].id);
			}
			else{
				v=bodys[i].value;
			}
			if(n_title==null){
					if(t==null || typeof(t)==undefined){
						t=" ";
					}
					n_title=t.replace("@","");
			}
			else{
				if(t==null || typeof(t)==undefined){
					t=" ";
				}
				n_title+="@"+t.replace("@","");
			}
			if(n_body==null || n_body==""){
				n_body=v.replace("@","");
			}
			else{
				n_body+="@"+v.replace("@","");
			}
		}
	}
	if(currentUrl.indexOf("iswap=true")==-1){
		n_body=n_body.replace(/&nbsp;/g,"*nbsp;")
	}
	if(title!=null && title!="" && n_title!=null && n_body!=null && n_body!=""){
		var postData="newsaction=modify&n_title="+title+"&c_title="+n_title+"&c_body="+n_body;
		if(isCreate==true){
			postData="newsaction=create&n_title="+title+"&n_type="+n_type+"&c_title="+n_title+"&c_body="+n_body;
		}
		var url=document.location.href;
		downloadUrl(url,callBack,postData);
	}
}

//改变目录
function ChangeFolder(path){
	if(path!=null && path!=""){
		document.location.href="admin_filemanage.aspx?action=changefolder&path="+escape(path);
	}
}
//删除文件
function DelFile(path){
	if(path!=null && path!=""){
		var postData="action=delfile&path="+path;
		var url="admin_filemanage.aspx";
		downloadUrl(url,callBack,postData);
		//document.location.href="admin_filemanage.aspx?action=delfile&path="+escape(path);
	}
}

//文件替换
function ReplaceFile(path){
	if(path!=null && path!=""){
		D.lhgdialog.opendlg( '文件替换', '../admin_fileupload.aspx?action=replace&path='+path, 560, 200, true ); 
		//lhgdialog.opendlg( title, '../admin_fileupload.aspx?action=replace&path='+path, 700, 200,true);
	}
}

//上传文件
function UploadFile(path){
	if(path!=null && path!=""){
		D.lhgdialog.opendlg( '上传文件', '../admin_fileupload.aspx?path='+path, 560, 200, true ); 
	}
}

//创建文件夹
function CreateFolder(path){
	if(path!=null && path!=""){
		D.lhgdialog.opendlg( '创建文件夹', '../admin_fileupload.aspx?action=create&path='+path, 560, 200, true );
	}
}

//删除目录
function DelFolder(path){
	if(path!=null && path!=""){
		var postData="action=delfolder&path="+path;
		var url="admin_filemanage.aspx";
		downloadUrl(url,callBack,postData);
		//document.location.href="admin_filemanage.aspx?action=delfolder&path="+escape(path);
	}
}

//清空文件夹
function clearFolder(path){
	if(path!=null && path!=""){
		var postData="action=clearfolder&path="+path;
		var url="admin_filemanage.aspx";
		downloadUrl(url,callBack,postData);
	}
}

//全选
function SelectAll(path){
	if(path!=null && path!=""){
		var inputs=document.getElementsByName("item_"+path);
		if(inputs!=null && inputs.length>0){
			for(i=0;i<inputs.length;i++){
				inputs[i].checked="checked";
			}
		}
	}
}

//删除被选中的某些文件
function DelSomeObj(path){
	if(path!=null && path!=""){
		var inputs=document.getElementsByName("item_"+path);
		if(inputs!=null && inputs.length>0){
			var paths;
			for(i=0;i<inputs.length;i++){
				if(inputs[i].checked==true){
					if(paths==null){
						paths=inputs[i].value;
					}
					else{
						paths+="|"+inputs[i].value;
					}
				}
			}
			if(paths!=null){
				var postData="action=delsomeobj&path="+path+"&objs="+paths;
				var url="admin_filemanage.aspx";
				downloadUrl(url,callBack,postData);
			}
		}
	}
}

//隐藏被删除的文件
function HiddenDeletedObjs(path){
	if(path!=null && path!=""){
		var inputs=document.getElementsByName("item_"+path);
		if(inputs!=null && inputs.length>0){
			var paths;
			for(i=0;i<inputs.length;i++){
				if(inputs[i].checked==true){
					if(document.getElementById("tr_"+inputs[i].value)!=null){
						document.getElementById("tr_"+inputs[i].value).style.display="none";
					}
				}
			}
		}
	}
}

//选中当前文件
function selectThisFile(path){
	if(document.getElementById("selectFileInput")!=null){
		document.getElementById("selectFileInput").value=path;
	}
}

//打开文件中心
function OpenSiteFileCenter(){
	OpenSiteFileCenterInternal('文件中心',document.documentElement.clientWidth, document.documentElement.clientHeight);
}

//打开文件中心的内部操作
function OpenSiteFileCenterInternal(title,width,height){
	//lhgdialog.opendlg( title, '../admin_filemanage.aspx', width, height,true,false, '', true, { top:0, left:0 });
	lhgdialog.opendlg( title, '../admin_filemanage.aspx', width, height,true);
}

//初始化新闻内容数据
function InitOriginalData_News(title,content){
	var news_area=document.getElementById("newscontent_area");
	if(news_area!=null){
		var newTr = news_area.insertRow();
　　		var newTd = newTr.insertCell();
　　		newTd.innerHTML = '小标题：<input type="text" id="content_title" name="content_title" style="width:400px;" value="'+title+'"><span style="padding-left:20px;"><img border="0" style="cursor:hand;" onclick="CreateNewBlock_News()" src="memberimages/add.png" alt="插入内容块" /><img border="0" style="cursor:hand;" onclick="DelThisBlock_News()" src="memberimages/sub.png" alt="删除本块" /></span>';
		var newTr2 = news_area.insertRow();
　　		var newTd2 = newTr2.insertCell();
		var randomNum=Math.random();
		randomNum="content_body_"+randomNum;
　		var currentUrl=document.location.href.toLowerCase();
		if(currentUrl.indexOf("iswap=true")==-1){
			newTd2.innerHTML='<textarea id="'+randomNum+'" name="content_body" cols="80" rows="12">'+content+'</textarea>'; 
			KE.show({
        		id : ''+randomNum+'',
        		skinType: 'tinymce',
        		cssPath : './index.css',
        		items : [
            		'source', 'preview', 'fullscreen', 'print', 'undo', 'redo', 'cut', 'copy', 'paste',
            		'plainpaste', 'wordpaste', 'justifyleft', 'justifycenter', 'justifyright',
            		'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
            		'superscript', 'date', 'time', 'specialchar', 'link', 'unlink', '-',
            		'title', 'fontname', 'fontsize', 'textcolor', 'bgcolor', 'bold',
            		'italic', 'underline', 'strikethrough', 'removeformat', 'selectall', 'image',
            		'layer', 'table', 'hr'
        		]
    		});
		}
		else{
			newTd2.innerHTML='<textarea id="'+randomNum+'" name="content_body" cols="80" rows="12">'+content.replace(/<br \/>/g,"\r").replace(/<br>/g,"\r").replace(/<br \/>/g,"\r")+'</textarea>'; 
		}
	}
}

//创建一个新的新闻内容块
function CreateNewBlock_News(){
	var news_area=document.getElementById("newscontent_area");
	if(news_area!=null){
		var row=window.event.srcElement.parentElement.parentElement.parentElement.rowIndex;
		var newTr = news_area.insertRow(row+2);
　　		var newTd = newTr.insertCell();
　　		newTd.innerHTML = '小标题：<input type="text" id="content_title" name="content_body" style="width:400px;" value=""><span style="padding-left:20px;"><img border="0" style="cursor:hand;" onclick="CreateNewBlock_News()" src="memberimages/add.png" alt="插入内容块" /><img border="0" style="cursor:hand;" onclick="DelThisBlock_News()" src="memberimages/sub.png" alt="删除本块" /></span>';
		var newTr2 = news_area.insertRow(row+3);
　　		var newTd2 = newTr2.insertCell();
		var randomNum=Math.random();
		randomNum="content_body_"+randomNum;
　　		newTd2.innerHTML='<textarea id="'+randomNum+'" name="content_body" cols="80" rows="12"></textarea>'; 
		var currentUrl=document.location.href.toLowerCase();
		if(currentUrl.indexOf("iswap=true")==-1){
			createHtmlEditor(randomNum);
		}
	}
}

//删除某内容块
function DelThisBlock_News(){
	if(confirm("确定删除本新闻内容块？")){
		var news_area=document.getElementById("newscontent_area");
		if(news_area!=null){
			var row=-1;
			row=window.event.srcElement.parentElement.parentElement.parentElement.rowIndex;
			if(row!=-1){
				news_area.deleteRow(row+1);
				news_area.deleteRow(row);
				if(news_area.rows.length==0){
					var newTr = news_area.insertRow();
　　					var newTd = newTr.insertCell();
　　					newTd.innerHTML = '小标题：<input type="text" id="content_title" name="content_body" style="width:400px;" value=""><span style="padding-left:20px;"><img border="0" style="cursor:hand;" onclick="CreateNewBlock_News()" src="memberimages/add.png" alt="插入内容块" /><img border="0" style="cursor:hand;" onclick="DelThisBlock_News()" src="memberimages/sub.png" alt="删除本块" /></span>';
					var newTr2 = news_area.insertRow();
　　					var newTd2 = newTr2.insertCell();
					var randomNum=Math.random();
					randomNum="content_body_"+randomNum;
　　					newTd2.innerHTML='<textarea id="'+randomNum+'" name="content_body" cols="80" rows="12"></textarea>'; 
					var currentUrl=document.location.href.toLowerCase();
					if(currentUrl.indexOf("iswap=true")==-1){
						createHtmlEditor(randomNum);
					}
				}
			}
		}
	}
}

//删除某个会员
function DelMember(uid){
	if(uid!=null && uid!=""){
		var postData="action=delmember&id="+uid;
		var url=document.location.href;
		downloadUrl(url,callBack,postData);
	}
}

//初始化管理员登陆ID
function InitAdminLoginID(){
	var url=document.location.href;
	var uid=document.getElementById("userID");
	if (url != null && uid!=null) {
        url = url.toLowerCase();
		url = url.replace("http://","");
		var nodes=url.split('/');
		if(nodes!=null && nodes.length>=2){
			uid.value=nodes[1];
			uid.readOnly=true;
		}
    }
	if(document.getElementById("userPass")!=null){
		document.getElementById("userPass").focus();
	}
}

//插入新的频道
function InsertNewChannel(tableName){
	var table=document.getElementById(tableName);
	if(table!=null){
		var row=window.event.srcElement.parentElement.parentElement.rowIndex;
		var newTr = table.insertRow(row+1);
　　		var newTd = newTr.insertCell();
		newTd.style.paddingLeft="6px";
		newTd.style.height="30px";
　　		newTd.innerHTML = '<input name="name_'+tableName+'" type="text" value="" />';
		var newTd2 = newTr.insertCell();
		newTd2.style.paddingLeft="6px";
　　		newTd2.innerHTML = '<input name="url_'+tableName+'" type="text" value="" />';
		var newTd3 = newTr.insertCell();
		newTd3.style.paddingLeft="6px";
　　		newTd3.innerHTML = '<select name="type_'+tableName+'"><option value="Channel">频道页</option><option value="Content">简单文本</option><option value="NewsList">新闻列表</option><option value="ProductList">产品列表</option><option value="Salenet">销售网络</option><option value="GuestBook">客户留言</option><option value="System">系统管理</option></select>';
		var newTd4 = newTr.insertCell();
		newTd4.style.paddingLeft="6px";
　　		newTd4.innerHTML = '<span onclick="InsertNewChannel(\''+tableName+'\')" style="cursor:hand">插入新频道</span> <span onclick="DelThisChannel(\''+tableName+'\')" style="cursor:hand">删除本频道</span> <span onclick=\"EditThisChannel(\''+tableName+'\')\" style=\"cursor:hand;\">编辑</span> <span onclick="ModifyThisChannel(\''+tableName+'\')" style="cursor:hand">提交</span>';
	}
}

//删除本频道
function DelThisChannel(tableName){
	if(confirm("执行删除将不可回复，确定删除本频道？")){
		var table=document.getElementById(tableName);
		if(table!=null){
			var row=-1;
			row=window.event.srcElement.parentElement.parentElement.rowIndex;
			if(row!=-1){
				var rowindex=row-1;
				var urls=document.getElementsByName("url_"+tableName);
				var types=document.getElementsByName("type_"+tableName);
				if(urls!=null && urls.length>=rowindex){
					url=urls[rowindex].value;
					if(types[rowindex].disabled==true){
						if(url!=null && url!=""){
							var postData="action=delchannel&url="+url+"&table="+tableName+"&rowindex="+row;
							var url2=document.location.href;
							downloadUrl(url2,callBack,postData);
						}
					}
					table.deleteRow(row);
				}
			}
		}
	}
}

//修改提交本频道
function ModifyThisChannel(tableName){
	if(confirm("确定提交？")){
		var table=document.getElementById(tableName);
		if(table!=null){
			var row=-1;
			row=window.event.srcElement.parentElement.parentElement.rowIndex;
			if(row!=-1){
				row=row-1;
				var names=document.getElementsByName("name_"+tableName);
				var urls=document.getElementsByName("url_"+tableName);
				var types=document.getElementsByName("type_"+tableName);
				if(names!=null && names.length>=row && urls!=null && urls.length>=row){
					var currentName=names[row].value;
					var currentUrl=urls[row].value;
					var currentType=types[row].value;
					if(currentName==null || currentName==""){
						alert ('频道标题不能为空！');
						return;
					}
					if(currentUrl==null || currentUrl=="" || currentUrl.length<6 || currentUrl.indexOf(".aspx")==-1){
						alert ('频道地址不能为空，且必须是以.aspx为后缀的!');
						return;
					}
					if (currentUrl.substr(currentUrl.lastIndexOf("."),currentUrl.length).toLowerCase()!=".aspx"){
						alert ('频道url必须是.aspx为后缀的。');
						return;
					}
					var postData="action=newchannel&title="+currentName+"&url="+currentUrl+"&channeltype="+currentType+"&table="+tableName+"&rowindex="+row;
					if(types[row].disabled==true){
						postData="action=modifychannel&title="+currentName+"&url="+currentUrl+"&channeltype="+currentType+"&table="+tableName+"&rowindex="+row;
					}
					var url=document.location.href;
					downloadUrl(url,callBack,postData);
				}
			}
		}
	}
}

//添加域名提交
function addDomainPost(){
	var domainControl=document.getElementById("addDomain");
	if(domainControl!=null){
		var domain=domainControl.value;
		if(domain!=null && domain!=""){
			document.getElementById("addDomainButton").disabled="disabled";
			var postData="action=addDomain&domain="+domain;
			var url=document.location.href;
			downloadUrl(url,callBack,postData);
		}
		else{
			alert ("域名不能为空！");
			domainControl.focus();
		}
	}
}

//创建站点邮局
function createSiteMail(){
	var mailDomainControl=document.getElementById("mailDomain");
	if(mailDomainControl!=null){
		var domain=mailDomainControl.value;
		if(domain!=null && domain!=""){
			var cmb=document.getElementById("createMailButton");
			cmb.value="邮局正在创建中，请稍等...";
			cmb.disabled="disabled";
			var postData="action=createMail&domain="+domain;
			var url=document.location.href;
			downloadUrl(url,callBack,postData);
		}
		else{
			alert ('邮局的域名为空，无法创建。');
		}
	}
}

//创建email帐号
function createEmailAccout(num){
	var userControl=document.getElementById("email_"+num);
	var passControl=document.getElementById("password_"+num);
	if(userControl!=null && passControl!=null){
		var email=userControl.value;
		var pass=passControl.value;
		if(email==null || email=="" || pass==null || pass==""){
			alert ('邮箱帐号名和密码不能为空！');
			userControl.focus();
		}
		else{
			if(confirm("确定创建？")){
				var postData="action=createEmailAccout&email="+email+"&password="+pass+"&rowindex="+num;
				var url=document.location.href;
				downloadUrl(url,callBack,postData);
			}
		}
	}
}

//删除被选中的新闻
function DelSelectedNews(){
	DeleteSelectedObj("inputItem","ntr_");
}

//删除被选中的产品
function DelSelectedProducts(){
	DeleteSelectedObj("inputItem","ptr_");
}

//删除选中的项
function DeleteSelectedObj(name_Param,tr_Param){
	var items=document.getElementsByName(name_Param);
	if(items!=null && items.length>0){
		var nid=null;
		for(i=0;i<items.length;i++){
			if(items[i].checked==true && items[i].value!="" && document.getElementById(tr_Param+items[i].value).style.display!="none"){
				if(nid==null){
					nid=items[i].value;
				}
				else{
					nid+=","+items[i].value;
				}
			}
		}
		if(nid!=null){
			var postData="paction=delsomeobj&ids="+nid;
			downloadUrl(document.location.href,callBack,postData);
		}
		else{
			alert ('对不起，你没有选择要删除的项。！');
		}
	}
}

//频道内容编辑
function EditThisChannel(tableName){
	var table=document.getElementById(tableName);
	if(table!=null){
		var row=-1;
		row=window.event.srcElement.parentElement.parentElement.rowIndex;
		if(row!=-1){
			row=row-1;
			var urls=document.getElementsByName("url_"+tableName);
			if(urls!=null && urls.length>=row){
				var currentUrl=urls[row].value;
				if(currentUrl.substr(0,1)!="/"){
					currentUrl="/"+currentUrl;
				}
				lhgdialog.opendlg('频道编辑', '../admin_channeleditor.aspx?url='+currentUrl, 700, 500,true);
			}
		}
	}
}

//编辑CDATA类型的频道
function EditCDATAChannel(){
	var content=document.getElementById("editor_content");
	if(content!=null){
		var str=content.value;
		if(str!=null && str!=""){
			var postData="edit=true&editor_content="+str;
			downloadUrl(document.location.href,callBack,postData);
		}
		else{
			alert ('内容不能为空！');
			content.focus();
		}
	}
	else{
		alert ('缺乏相关控件，无法提交！');
	}
}

//编辑产品列表频道
function EditProductsChannel(){
	var postData="edit=true";
	var c_pagesize=document.getElementById("editor_pagesize");
	var c_column=document.getElementById("editor_column");
	var c_hot=document.getElementById("editor_hot");
	var c_new=document.getElementById("editor_new");
	var c_commend=document.getElementById("editor_commend");
	var c_ispager=document.getElementById("editor_ispager");
	var c_shopcar=document.getElementById("editor_shopcar");
	if(c_pagesize==null || c_column==null || c_hot==null || c_new==null || c_commend==null || c_ispager==null || c_shopcar==null){
		alert ('缺少必要的控件元素，无法提交！');
		return;
	}
	var pagesize=c_pagesize.value;
	if(IsInt(pagesize)==false){
		alert ('对不起,显示条数必须为整数！');
		c_pagesize.focus();
		return;
	}
	postData+="&editor_pagesize="+pagesize;
	var column=c_column.value;
	if(IsInt(column)==false){
		alert ('对不起，列数必须是整数！');
		c_column.focus();
		return;
	}
	postData+="&editor_column="+column;
	postData+="&editor_hot="+c_hot.checked+"&editor_new="+c_new.checked+"&editro_commend="+c_commend.checked+"&editor_pager="+c_ispager.checked+"&editor_shopcar="+c_shopcar.checked;
	downloadUrl(document.location.href,callBack,postData);
}

//编辑新闻列表频道
function EditNewsChannel(url){
	var postData="edit=true";
	var c_pagesize=document.getElementById("editor_pagesize");
	var c_hot=document.getElementById("editor_hot");
	var c_new=document.getElementById("editor_new");
	var c_commend=document.getElementById("editor_commend");
	var c_ispager=document.getElementById("editor_ispager");
	if(c_pagesize==null || c_hot==null || c_new==null || c_commend==null || c_ispager==null){
		alert ('缺少必要的控件元素，无法提交！');
		return;
	}
	var pagesize=c_pagesize.value;
	if(IsInt(pagesize)==false){
		alert ('对不起,显示条数必须为整数！');
		c_pagesize.focus();
		return;
	}
	postData+="&editor_pagesize="+pagesize;
	postData+="&editor_hot="+c_hot.checked+"&editor_new="+c_new.checked+"&editro_commend="+c_commend.checked+"&editor_pager="+c_ispager.checked;
	downloadUrl(document.location.href,callBack,postData);
}

//编辑销售网络频道
function EditSaleNetChannel(url){
	alert ('SaleNet');
}

//财付通
function tenpay(){
	var orderid=document.getElementById("orderid").value;
	downloadUrl("/Tenpay.aspx?orderid="+orderid,callBack,"action=post");
}

//支付宝
function alipay(){
	var orderid=document.getElementById("orderid").value;
	document.location.href="/Alipay.aspx?action=post&orderid="+orderid;
	//downloadUrl("/Alipay.aspx?orderid="+orderid,callBack,"action=post");
}