function loginSubmit(login, uc)
{
	var username = login.elements['username'];
	var password = login.elements['password'];
    if(!loginCheck(login)) return false;
	if(uc == 1) return true;
	$.post(login.action, 'action=ajax&username='+username.value+'&password='+password.value, function(data){
		if(data == 1)
		{
			$('#logined_username').html(username.value);
			$('#div_login').hide();
			$('#div_logined').show();
		}
		else
		{
			alert('登录失败');
			redirect(login.action);
		}
		username.value = password.value = '';
	});
	return false;
}

function logout(url)
{
	$.getJSON('http://www.800shang.com/member/logout.php?action=ajax&id='+(Math.random()*5)+"&jsoncallback=?", function(data){
		if(data.logout != 1) alert(data);
	});
	$('#div_logined').hide();
	$('#div_login').show();
}
window._userid=0;
function loginshow()
{
	$.getJSON("http://www.800shang.com/member/login.php?action=get_username&contentid="+contentid+"&t="+Math.random()+"&jsoncallback=?",
	function(data){
		var auth=data.username;
		_userid=data.userid;
		if($("#sitecss").attr("href")!="templates/default/skins/"+data.sitecss+"/site.css" && data.sitecss!=""){
            $("#sitecss").attr("href","templates/default/skins/"+data.sitecss+"/site.css");
        }
		if(auth != null && auth!="")
		{
			$('#logined_username').html(auth);
			$('#div_login').hide();
			$('#div_logined').show();
		}
		else
		{
			$('#div_logined').hide();
			$('#div_login').show();
		}		
	}); 	
}

function sendmail(siteuid){
	if(_userid<1){
		alert("登陆后才能为商家留言！");
		return;
	}
	if(_userid==siteuid){
		alert("您不能为自己留言！");	
		return;
	}
	sendmailtpl(siteuid);
}
window.linktpl;
function sendmailtpl(siteuid){
	linktpl=$("#commenttext").html();
	$("#commenttext").html("<IFRAME id=\"ajaxsend\" width=\"210\" height=\"270\" scrolling=\"no\" frameBorder=\"0\" ></IFRAME>");
	$("#ajaxsend").attr("src","http://www.800shang.com/message/send.php?action=ajaxsend&userid="+siteuid);
}
$(function(){
   	if(siteurl.indexOf("http://")!=-1 && location.href.indexOf("www.800shang.com")!=-1 && location.href.indexOf("admin.php")==-1){
        location.href=location.href.replace(/^http.*\.com\/800\/[^\/]+/,siteurl);
    }
	var url=location.href.match(/^http:\/\/[^\/]+/);
	if(url=="http://www.3qep.com" || url=="http://www.800shang.com"){
		var lasturl=$("#menu").find("a:last").attr("href");
                if(lasturl){  
		    url=url+lasturl.match(/^\/800\/[^\/]+/);
                }
		$("a.siteindex").attr("href",url);
	}else{
		$("a.siteindex").attr("href",url);
		$("#menu").find("a").each(function(i){
			this.href=this.href.replace(/^http.*\.com\/800\/[^\/]+/,url);
		});
		if($("#position").find("a").length>3){
			$("#position").find("a:first").remove();
			$("#position").find("a:first").remove();
		}
	}
   loginshow();
   footer_over_top();
   $(".jqmClose").click(function(){
		if($("#footer_over").css("height")=="30px"){
			$("#commenttext").show();
			$("#footer_over").css({height:"300px"});
			$(this).children("img").attr("src","images/close.gif");
		}else{
			$("#commenttext").hide();
			$("#footer_over").css({height:"30px"});
			$(this).children("img").attr("src","images/open.gif");
		}
		footer_over_top();
		return false;
   });
   //调整banner
   if($("#logo").find("img").height()>200){
		$("#logo").find("img").height(200);   
   }
   
});
window.onscroll=footer_over_top; 
window.onresize=footer_over_top;  
function footer_over_top(){
	var t=(document.documentElement.scrollTop+document.documentElement.clientHeight-document.getElementById("footer_over").offsetHeight)+"px";
	$("#footer_over").css({top:t});
}
function gotools(type,url){
	var _url="http://www.800shang.com/tools/";
	if(type=="code"){
		_url+="code.php?file="+url;
	}else{
		_url+=url;
	}
	if(!$("#showx").attr("id")){$("#endtext").append("<div id='showx'></div>")}
	$.get(_url,function(msg){
		$("#showx").html(msg).css({color:"#0099FF",'background-color':"#FFCC99",border:"#FF9900 2px solid",'text-indent':"0px",padding:"8px"});
	});
}
