// JavaScript Document
var getPageSize = function(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

var showDiv = function(memid,memberId,Product_Title,Product_Id){
	
	var arrayPS = getPageSize();
	var divAll = $("DivFAll");
	var div = $("DivFloat");
	if(divAll == null){
		divAll = document.createElement("DIV");
		divAll.id="DivFAll";
		divAll.style.top="0px";
		divAll.style.left="0px";
		divAll.style.width=arrayPS[0]+"px";
		divAll.style.height=arrayPS[1]+30+"px";
		document.body.appendChild(divAll);
	}
	if(memid==0)
	{
		if(div == null){
		div=document.createElement("DIV");
		div.id="DivFloat";
		div.style.top=arrayPS[1]/2+"px";
		div.style.left=arrayPS[0]/3+"px";
		div.style.width="320px";
		div.style.height="250px";
		div.innerHTML = "<ul><li class='right' style='cursor:pointer' onclick='hideshowcolse()'><font color=red>对不起只有登陆后才能询价，请先登陆！&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><img src='../images/com/close.gif' /></li><div id='div_login' class='main_textarea'><li class='f14 fb blue lfloat'>&nbsp;&nbsp;&nbsp;&nbsp;会员登录</li><li class='f14'><div style='background-color:#a6a6a6;height:1px;margin:5px 0px;overflow:hidden;'></div>&nbsp;&nbsp;用&nbsp;户&nbsp;名：<input type='text' name='LoginName' id='LoginName' size='30'  class='Gray' style='padding:0px 2px;background-color:#fff;'/></li><li class='f14'>用户密码：<input name='LoginPass' id='LoginPass' type='password' size='30'  class='Gray' style='padding:0px 2px;background-color:#fff;'/></li><li class='f14'>验&nbsp;证&nbsp;码:&nbsp;<input type='text' id='validatecode'  name='validatecode' size='5' maxlength='4'/>&nbsp;<img src='/System/imgchk/validatecode.asp' align='absmiddle' border='0'>	</li><li class='center'><input type='button' value='登&nbsp;&nbsp;陆' style='height:18px;padding:0px;' onclick='proudctLogin("+ memberId +","+Product_Id+")'/>&nbsp;<input type='hidden' value='"+Product_Title+"' name='Product_Title' id='"+Product_Title+"'/><input type='button' value='重&nbsp;&nbsp;填'  style='height:18px;padding:0px;' onclick='clearform()'/></li><div style='background-color:#a6a6a6;height:1px;margin-top:15px;overflow:hidden;' ></div><li><span style='float:right;padding-right:90px;'>已使用安全方式登录</span><img src='../images/com/login_s.gif' /></li></ul></div>";
	
		document.body.appendChild(div);
		}
	else
	{
		
		div.style.top=arrayPS[1]/2+"px";
		div.style.left=arrayPS[0]/3+"px";
		div.style.width="320px";
		div.style.height="275px";
		div.innerHTML = "<ul><li class='right' style='cursor:pointer' onclick='hideshowcolse()'><font color=red>对不起只有登陆后才能询价，请先登陆！&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><img src='../images/com/close.gif' /></li><div id='div_login' class='main_textarea'><li class='f14 fb blue lfloat'>&nbsp;&nbsp;&nbsp;&nbsp;会员登录</li><li class='f14'><div style='background-color:#a6a6a6;height:1px;margin:5px 0px;overflow:hidden;'></div>&nbsp;&nbsp;用&nbsp;户&nbsp;名：<input type='text' name='LoginName' id='LoginName' size='30'  class='Gray' style='padding:0px 2px;background-color:#fff;'/></li><li class='f14'>用户密码：<input name='LoginPass' id='LoginPass' type='password' size='30'  class='Gray' style='padding:0px 2px;background-color:#fff;'/></li><li class='f14'>验&nbsp;证&nbsp;码:&nbsp;<input type='text' id='validatecode'  name='validatecode' size='5' maxlength='4'/>&nbsp;<img src='/System/imgchk/validatecode.asp' align='absmiddle' border='0'>	</li><li class='center'><font color=red>用户名或密码输入错误!</font></li><li class='center'><input type='button' value='登&nbsp;&nbsp;陆' style='height:18px;padding:0px;' onclick='proudctLogin("+ memberId +","+Product_Id+")'/>&nbsp;<input type='hidden' value='"+Product_Title+"' name='Product_Title' id='"+Product_Title+"'/><input type='button' value='重&nbsp;&nbsp;填'  style='height:18px;padding:0px;' onclick='clearform()'/></li><div style='background-color:#a6a6a6;height:1px;margin-top:15px;overflow:hidden;' ></div><li><span style='float:right;padding-right:90px;'>已使用安全方式登录</span><img src='../images/com/login_s.gif' /></li></ul></div>";
	
		document.body.appendChild(div);
		
		}
				
		
	}
	else
	{
	if(div == null){
		div=document.createElement("DIV");
		div.id="DivFloat";
		div.style.top=arrayPS[1]/2+"px";
		div.style.left=arrayPS[0]/3+"px";
		div.style.width="320px";
		div.style.height="280px";
		div.innerHTML = "<ul><li class='right' style='cursor:pointer' onclick='hideShow()'><img src='../images/com/close.gif' /></li><li >询价标题：<input type='text' id='"+ memberId +"' name='title' size='40' value='我对您在中华门窗网发布的“"+Product_Title+"”很感兴趣'/></li><li></li><li>验&nbsp;证&nbsp;码：<input type='text' id='validatecode'  name='validatecode' size='5' maxlength='4'/>&nbsp;<img src='/System/imgchk/validatecode.asp' align='absmiddle' border='0'></li><li>询价内容：<textarea cols='30' rows='8' 	name='content' >订货总量:\n期望价格:</textarea></li><li class='center'><input type='image' src='../images/com/botton1.gif' style='border:0px;width:44px;height:21px;' onclick='proudctLevel("+memid+","+memberId+","+Product_Id+")' />&nbsp;<input  type='image'   src='../images/com/botton2.gif' style='border:0px;width;44px;height:21px;'  onclick='hideShow()'/></li></ul>";
		document.body.appendChild(div);
		}
		else{
	
		div.style.top=arrayPS[1]/2+"px";
		div.style.left=arrayPS[0]/3+"px";
		div.style.width="320px";
		div.style.height="280px";
		div.innerHTML = "<ul><li class='right' style='cursor:pointer' onclick='hideShow()'><img src='../images/com/close.gif' /></li><li >询价标题：<input type='text' id='"+ memberId +"' name='title' size='40' value='我对您在中华门窗网发布的“"+Product_Title+"”很感兴趣'/></li><li></li><li>验&nbsp;证&nbsp;码：<input type='text' id='validatecode'  name='validatecode' size='5' maxlength='4'/>&nbsp;<img src='/System/imgchk/validatecode.asp' align='absmiddle' border='0'></li><li>询价内容：<textarea cols='30' rows='8' 	name='content' >订货总量:\n期望价格:</textarea></li><li class='center'><input type='image' src='../images/com/botton1.gif' style='border:0px;width:44px;height:21px;' onclick='proudctLevel("+memid+","+memberId+","+Product_Id+")' />&nbsp;<input  type='image'   src='../images/com/botton2.gif' style='border:0px;width;44px;height:21px;'  onclick='hideShow()'/></li></ul>";
		document.body.appendChild(div);
			
			}
		
		
	}
	
	divAll.style.display="block";
	div.style.display="block";
}

var clearform=function(){
$("LoginName").value=""	;
$("LoginPass").value="";
$("validatecode").value=""	;
$("LoginName").focus();		
	
}
var hideShow = function(){
	$("DivFAll").style.display='none';
	$("DivFloat").style.display='none';
}
var hideshowcolse=function(){
	$("DivFAll").style.display='none';
	$("DivFloat").style.display='none';
   

}
function proudctLogin(memberId,Product_Id)
{ 
	if ($("LoginName").value.Trim()==''){
			alert("用户名不能为空!");
		return false;
	};
	if ($("LoginPass").value.Trim()==''){
			alert("密码不能为空!");
		return false;
	};
	if ($("validatecode").value.trim()==''){
		alert("验证码不能为空！");
		return false;
	}

	var obj = $("DivFloat");
	var LoginName = $("LoginName").value.trim(); 
	var LoginPass = $("LoginPass").value.trim(); 
	var validatecode=$("validatecode").value.trim();
	var Product_Title=$("Product_Title").value.trim();
	var ajax = new Ajax();
	ajax.onFinished = function (){ajax=null;}
	ajax.onObjErr = function(){objChild.innerHTML= "<font color=red>错误:浏览器不支持</font>"}
	ajax.addJob(
					function(){//设置初始值
					
				
						ajax.url="/include/member_login.asp?memberId=" + memberId + "&Product_Title="+Product_Title+"&Product_Id="+Product_Id+"&LoginName=" + LoginName + "&LoginPass="+LoginPass+"&validatecode="+validatecode+"&rnd="+Math.random()*(999999 - 100000) + 100000;
						
						obj.innerHTML = "loading……";
					}
					,
					function(){ // 完成

					if(ajax.returnData.substring(0,2)=="OK")
					{
						
						
						    var str=ajax.returnData;
							var stra=new Array(4);
                            stra=str.split(",");
						    showDiv(stra[1],stra[2],stra[3],stra[4]);
							
							
							
							
					}
					else
				   {					 
			      
						    var str2=ajax.returnData;
							var stra2=new Array(3);
                            stra2=str2.split(",");
						    showDiv(stra2[0],stra2[1],stra2[2],stra2[3]);
							
				
			       	}
					}
						
					
					,
					function(){ //状态改变
						obj.innerHTML += ".." //+ ajax.getPercent() +"%"//ajax.msg()
					}
					,
					function(){ //发生错误
						obj.innerHTML = ajax.err
					}
				);
	ajax.doNextJob();
}


function proudctLevel(memid,memberid,Product_Id)
{ 
	if ($("title").value.Trim()==''){
			alert("询价标题不能为空!");
		return false;
	};
	if ($("content").innerHTML.Trim()==''){
			alert("询价内容不能为空!");
		return false;
	};
	if ($("validatecode").value.trim()==''){
		alert("验证码不能为空！");
		return false;
	}
	
	var obj = $("DivFloat");
	var title = $("title").value.trim(); 
	var content = $("content").innerHTML.trim(); 
	var validatecode=$("validatecode").value.trim();
	
	var ajax = new Ajax();
	ajax.onFinished = function (){ajax=null;}
	ajax.onObjErr = function(){objChild.innerHTML= "<font color=red>错误:浏览器不支持</font>"}
	ajax.addJob(
					function(){//设置初始值
						ajax.url="/include/MdyProudctLevel.asp?memid="+memid+"&memberid=" + memberid + "&Product_Id="+Product_Id+"&title="+ title +"&content="+ content +"&validatecode="+validatecode+"&rnd="+Math.random()*(999999 - 100000) + 100000;
						obj.innerHTML = "loading……";
					}
					,
					function(){ // 完成
						obj.innerHTML= ajax.returnData;
					}
					,
					function(){ //状态改变
						obj.innerHTML += ".." //+ ajax.getPercent() +"%"//ajax.msg()
					}
					,
					function(){ //发生错误
						obj.innerHTML = ajax.err
					}
				);
	ajax.doNextJob();
}
String.prototype.Trim = function(){ 
	return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 