var materialid;

if (window.ActiveXObject && !window.XMLHttpRequest) {
  	window.XMLHttpRequest=function() {
  	return new ActiveXObject((navigator.userAgent.toLowerCase().indexOf('msie 5') != -1) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP');
   };
}

function sendGoodFriend(){
	eval("window.open('/goodfriendEmailAdd.htm?materialId=" +materialid + "')");
}

//打印制作方法	
function printMethod(){
	eval("window.open('/printMaterial.htm?material.id=" +materialid + "')");
}

function finish1(){
		var operId = document.getElementById("operId").value;
		var error = document.getElementById("error").value;
		var url = "/view/error/errorSave.htm?error.rightContent=" + error + "&operId=" + operId + "&operType=2";  //保存报错信息
		var msgbox;
		var req=new XMLHttpRequest();
		if (req) {
			req.onreadystatechange=function() {
			   if (req.readyState==4 && req.status==200) {
				   var value = req.responseText;
				   if(value!=''&&value=='success'){
					 document.getElementById("errorhtml").innerHTML="&nbsp;&nbsp;<font color='green'>欢迎参加可口找“茬”有“礼”活动，您已成功提交纠错信息，我们将在审核后判断是否给予您积分，积分达到一定程度会有礼品赠送，感谢您的参与。</font><br/><br/>";
				   }
			   }
			 }
			req.open('POST', url);
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			req.send("");
		}
}

function addError(aaaa){
	if(aaaa==''||aaaa==0){ //如果原料ID不存在，或者原料ID为0， 条件为没有原料
		document.getElementById("errorhtml").style.display="none";
	}else{
		if(document.getElementById("errorhtml")==null||document.getElementById("errorhtml")==''){
			document.getElementById("pageNav").innerHTML=" <div id=\"errorhtml\"><table width=150>"
			+"<tr><td><font color='green'>纠错</font></td></tr>"
			+"<tr><td>"
			+"<input type='hidden' name='operId' value='"+materialid+"'>"
			+"<input type='hidden' name='operType' value='2' >"
			+"<textarea name='error.rightContent' rows='15' id='error' dataType='LimitB'  style='overflow:auto;width:100%;' min='1' max='2000' msg='纠错内容在600个汉字之内！'></textarea>"
			+"</td></tr><tr><td>"	
			+"<input type='button' name='finish' value='提交' onclick='finish1()' />&nbsp;&nbsp;"
			+"<input type='button' name='finish' value='关闭' onclick='addError(0)' />"
			+"</td><tr>"
			+"</table></div>"
			+ document.getElementById("pageNav").innerHTML ;	
			document.getElementById("error").focus();
		}else{
			document.getElementById("errorhtml").style.display="block";
		}
	}
}

function showTopInfo(materialid2){
	materialid=materialid2;
	var req=new XMLHttpRequest();
	if (req) {
		req.onreadystatechange=function() {
	       if (req.readyState==4 && req.status==200) {
	           var value = req.responseText;
			   if(value!=''){
			   	 document.getElementById("quicklink").innerHTML=value;
			   	 if(materialid==''){
			   	 	 hide('login');
			   	 }
			   }
	       }
	     }
	    req.open('POST', '/getTopInfo.htm?operType=material&operId=' + materialid);
	    req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    req.send("");
	}
	//document.getElementById("materialname").innerHTML=document.getElementById("materialname").innerHTML+"<div>google ads!</div>"
	//document.getElementById("materialname").innerHTML=document.getElementById("materialname").innerHTML+"<div><scr"+"ipt type='text/javascript'><!--google_ad_client = 'pub-6515529160275067';/* 468x15, 长条的文字广告 */google_ad_slot = '0956842761';google_ad_width = 468;google_ad_height = 15;//--></scr"+"ipt><scr"+"ipt type='text/javascript' src='http://pagead2.googlesyndication.com/pagead/show_ads.js'></scr"+"ipt></div>";
}

function gongn(strg,materialId){
	var req=new XMLHttpRequest();
	if (req) {
		req.onreadystatechange=function() {
	       if (req.readyState==4 && req.status==200) {
	           var value = req.responseText;
			   if(value!=''){
			   	 document.getElementById(strg).innerHTML=value;
			   	 show(strg);
			   }else{
			   	 showLogin();
			   }
	       }
	     }
	    req.open('POST', '/ylGongneng.htm?gongneng='+strg+"&&material.id="+materialId);
	    req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    req.send("");
	}
}

function show(id){
	
	//隐藏
	messh = document.getElementById('jiucuo');
	messh.close = true;
	messh.style.visibility = 'hidden'
	
	messh = document.getElementById('login');
	messh.close = true;
	messh.style.visibility = 'hidden'

	//显示ID
  	var me = this;
  	var mess = document.getElementById(id);
  	mess.style.left = (document.documentElement.scrollLeft+document.documentElement.clientWidth- mess.offsetWidth)/2;
  	mess.style.top = (document.documentElement.scrollTop+document.documentElement.clientHeight - mess.offsetHeight)/2;	
  	mess.style.visibility = 'visible';
}

function hide(id){
		var mess = document.getElementById('jiucuo');
		mess.close= true;
		mess.style.visibility = 'hidden';
		
		var mess1 = document.getElementById('login');
		mess1.close= true;
		mess1.style.visibility = 'hidden';
}

function loginClose(){
	var req=new XMLHttpRequest();
	if (req) {
		req.onreadystatechange=function() {
	       if (req.readyState==4 && req.status==200) {
	           var value = req.responseText;
			   if(value!=''){
			   	 document.getElementById('quicklink').innerHTML=value;
			   	 hide('login');
			   }
	       }
	     }
	    req.open('POST', '/loginClose.htm');
	    req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    req.send("");
	}
}

function login(){
	 var nick = document.getElementById("nick").value;
	 var password = document.getElementById("password").value;
	 if(nick==''){
	 	alert('用户不能为空！');
	 	return false;
	 }
	 if(password==''){
	 	alert('密码不能为空！');
	 	return false;
	 }
	 if(nick!=''&&password!=''){
	 var condition = "?accounts.nick=" + nick + "&accounts.password=" + password;
	 var req=new XMLHttpRequest();
	if (req) {
		req.onreadystatechange=function() {
		if (req.readyState==4 && req.status==200) {//判断状态，4是已发送，200已完成
           var value = req.responseText;
			//document.getElementById("login1").innerHTML=value;
			document.getElementById('login').innerHTML=value;
			show('login');
		}
     }
    document.getElementById('login').innerHTML="正在登录，请稍等...";
	show('login');
    req.open('POST','/uLogin.htm'+condition);//改变原料ID和原料量
    req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    req.send("");//发送参数如果有参数req.send("username="+user_name);用request取得
  }
  }
}

function KeyDown()
{
	if (event.keyCode == 13)
	  {
	     login();
	  }
}
	
function showLogin(){
	str = "<div id=a1><div id=a11>登录</div><div id=a12><span title=\"关闭\" onclick=\"hide('login');\" ><img src=\"/images/close.jpg\"></span></div></div>"
					  +"<div id=a2>"
					  +"<div id=class>用户名："
					  +"<input name=\"accounts.nick\" type=\"text\"  id=\"nick\"  style=\"width:100px\" onkeydown=\"KeyDown()\"/>"
					  +"</div>"
					  +"<div id=class>&nbsp;&nbsp;密码："
					  +"<input name=\"accounts.password\" type=\"password\" id=\"password\" style=\"width:100px\" onkeydown=\"KeyDown()\" maxlength=\"20\"/>"
					  +"</div>"
					  +"<div id=class><input type=\"button\" value=\"登录\" onclick=\"login();\"></div>"
					  +"</div>";
	document.getElementById('login').innerHTML=str;
	show('login');
}

function cerror(){
		var operId = document.getElementById("operId").value;
		var error = document.getElementById("error").value;
		
		if(error==''){
			alert('纠错内容不能为空！');
			return false;
		}
		
		var url = "/saveError.htm?error.rightContent=" + error + "&operId=" + operId + "&operType=2";  //保存报错信息
		var req=new XMLHttpRequest();
		if (req) {
			req.onreadystatechange=function() {
			   if (req.readyState==4 && req.status==200) {
				   var value = req.responseText;
				   if(value!=''&&value=='success'){
				   	 hide('jiucuo');
					 alert("欢迎参加可口找“茬”有“礼”活动，您已成功提交纠错信息，我们将在审核后判断是否给予您积分，积分达到一定程度会有礼品赠送，感谢您的参与!");
				   }
			   }
			}
			req.open('POST', url);
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			req.send("");
		}
}

function closeLogin(str){
	var req=new XMLHttpRequest();
	if (req) {
		req.onreadystatechange=function() {
	       if (req.readyState==4 && req.status==200) {
	           var value = req.responseText;
			   if(value!=''){
			   	 document.getElementById("quicklink").innerHTML=value;
		   	 	 hide(str);
			   }
	       }
	     }
	    req.open('POST', '/closeLogin.htm');
	    req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    req.send("");
	}
}