function FTagName(TagName){return document.getElementsByTagName(TagName);}
function Fid(id){return document.getElementById(id);}
function addLoadEvent(func){
var oldonload=window.onload;
if(typeof oldonload == "function"){
	window.onload=function(){
	if (oldonload){oldonload();}
	func();
	}
	}else{
	window.onload=func;
	}
}

//管理系统运行模块
//instr_pro(产品名称,购买价格,积分价,产品ID号,用户积分数,cookie购物数量,供货商ID,供货商名称)
function instr_pro(name,price,Integral,alt,u_int,cookie_num,MerID,Mer){	
if (price==0){
	if (parseInt(u_int)<parseInt(Integral)){
		alert("您的积分不够支付，请选项其它订购方式．");
		return false;
	}
	if (Integral==""){
		alert("此款产品不允许积分购买．");
		return false;
	}
}

if(Fid("Procurement")) Fid("Procurement").style.visibility='visible';	
var number;
if(number*0 !=0)number = 1;
for(var i = 0;i < pro_list.rows.length;i ++){
	if(pro_list.rows(i).cells(0).all(0).title == alt){
	var overint=parseInt((parseInt(number) + parseInt(pro_list.rows(i).cells(3).all("number").value))*parseInt(Integral))	
		if (parseInt(u_int)<overint){
			alert("您的积分不够支付．");
			return false;
			}
		if (parseInt(pro_list.rows(i).cells(2).innerText)!==0){
			if (Integral == 0){
				alert("您不能再选择其它方式购买此款产品\n\n建议您另下订单．");
				return false;
				}
			}
	pro_list.rows(i).cells(3).all("number").value = parseInt(number) + parseInt(pro_list.rows(i).cells(3).all("number").value);
	sum_total();
	return;
	}
}
var row=pro_list.insertRow(0);
var cell=row.insertCell();
cell.innerHTML='<a title=' + alt + '>[' + Mer + ']' + name +'</a>';
cell.innerHTML+='<input name="pro_id" type=hidden value='+ alt +'>';
cell.innerHTML+='<input name="price" type=hidden value='+ price +'>';
cell.innerHTML+='<input name="Inte" type=hidden value='+ Integral +'>';
cell.innerHTML+='<input name="pro_name" type=hidden value='+ name +'>';
cell.innerHTML+='<input name="pro_MerID" type=hidden value='+ MerID +'>';
cell.width='43%';
cell.height='18px';
cell=row.insertCell();
cell.innerText= price;
cell.width='20%';
cell=row.insertCell();
cell.innerText=Integral;
cell.width='19%';
cell=row.insertCell();
cell.innerHTML='<input name=number value='+ parseInt(cookie_num) +' maxlength=2 class=input_bit onblur=sum_total()>';
cell.width='12%';
cell=row.insertCell();
cell.innerHTML='<a onclick=del_pro(this) style=cursor:hand>删</a>';
sum_total();
}

function del_pro(obj){
for(var i = 0;i < pro_list.rows.length;i ++){
	if(pro_list.rows(i).cells(4).all(0) == obj){
	pro_list.deleteRow(i);
	sum_total();
	return;
	}
	}
}

function format_pro(){
	while(pro_list.rows.length > 0){
	pro_list.deleteRow(0);
	}
	sum_total();
}

function sum_total(){	
var te = 0;
for(var i = 0;i < pro_list.rows.length;i ++){
	te = eval(te+'+'+(parseFloat(pro_list.rows(i).cells(1).innerText) * parseFloat(pro_list.rows(i).cells(3).all("number").value)));
}
total.innerText = te;
var it = 0;
for(var i = 0;i < pro_list.rows.length;i ++){	
	it = eval(it+'+'+(parseFloat(pro_list.rows(i).cells(2).innerText) * parseFloat(pro_list.rows(i).cells(3).all("number").value)));
}
totit.innerText = it;
}

function writeOrders(){
	var str = "main=";
	for(var i = 0;i < pro_list.rows.length;i ++){
	str += "|"+pro_list.rows(i).cells(0).all("pro_id").value;
	str += ","+pro_list.rows(i).cells(0).all("price").value;
	str += ","+pro_list.rows(i).cells(0).all("Inte").value;
	str += ","+pro_list.rows(i).cells(3).all("number").value;
	str += ","+pro_list.rows(i).cells(0).all("pro_MerID").value;
	
	if (pro_list.rows(i).cells(0).all("pro_MerID").value!=0){
	window.open('index.asp?action=Orders&'+str+'');
	}else{
	window.open('../../../user/index.asp?action=Orders&'+str+'');
	}
	
	}
	UPobject('hidden','Procurement');
	
	//alert(str);
	//document.cookie = str;
}

function  get_cookie(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 loadCookie(){
if (Fid("pro_list")){
	if(document.cookie){
	var str = get_cookie("main")
	var str = document.cookie.split("|");
	for(var i=1;i<str.length;i++){
		var vd = str[i].split(",");
		instr_pro(vd[0],vd[1],vd[2],vd[3],vd[4],vd[5],vd[6],vd[7]);
	}
	}
}
}

function writeCookie(){
if (Fid("pro_list")){
	var str = "main=";
	for(var i = 0;i < pro_list.rows.length;i ++){
	str += "|"+pro_list.rows(i).cells(0).all("pro_name").value;
	str += ","+pro_list.rows(i).cells(0).all("price").value;
	str += ","+pro_list.rows(i).cells(0).all("Inte").value;
	str += ","+pro_list.rows(i).cells(0).all("pro_id").value;
	str += ","+0;
	str += ","+pro_list.rows(i).cells(3).all("number").value;
	str += ","+pro_list.rows(i).cells(0).all("pro_MerID").value;
	}
	document.cookie = str + ";path=/;";
	//alert(document.cookie);
}
}


function changepic(picurl){
document.getElementById("pic0").src=picurl;
}

var Obj=''
document.onmouseup=MUp
document.onmousemove=MMove

function MDown(Object){
Obj=Object.id
document.all(Obj).setCapture()
pX=event.x-document.all(Obj).style.pixelLeft;
pY=event.y-document.all(Obj).style.pixelTop;
}

function MMove(){
if(Obj!=''){
document.all(Obj).style.left=event.x-pX;
document.all(Obj).style.top=event.y-pY;
}
}

function MUp(){
if(Obj!=''){
document.all(Obj).releaseCapture();
Obj='';
}
}

function UPobj(Action1,obj1,Action2,obj2){
	if (Action1,obj1){Fid(obj1).style.display=Action1;}
	if (Action2,obj2){Fid(obj2).style.display=Action2;}
}
function UPobject(Action1,obj1,Action2,obj2,str,strID){
	if (Action1,obj1){Fid(obj1).style.visibility=Action1;}
	if (Action2,obj2){Fid(obj2).style.visibility=Action2;}
	if (str,strID){Fid(strID).src=str;}
}

function regok(){
	if (document.linkform.l_title.value==""){
	document.linkform.l_title.focus();
	alert("请填写链接名称");
	return false;
	}
	if (document.linkform.l_url.value==""){
	document.linkform.l_url.focus();
	alert("请填写链接地址");
	return false;
	}
	if (document.linkform.l_name.value==""){
	document.linkform.l_name.focus();
	alert("请填写联系人");
	return false;
	}
	if (document.linkform.l_Email.value==""){
	document.linkform.l_Email.focus();
	alert("请填写联系人Email");
	return false;
	}
	
}

function scrollon(){ 
if (Fid("infozone")){
	var o=Fid("infozone"); 
	window.setInterval(function(){scrollup(o,20,0);},3000); 
}
} 
function scrollup(o,d,c){ 
if(d==c){ 
var t=o.firstChild.cloneNode(true); 
o.removeChild(o.firstChild); 
o.appendChild(t); 
t.style.marginTop=o.firstChild.style.marginTop="0px"; 
} 
else{ 
var s=3,c=c+s,l=(c>=d?c-d:0); 
o.firstChild.style.marginTop=-c+l+"px"; 
window.setTimeout(function(){scrollup(o,d,c-l)},100); 
}
} 


function  scrolldiv(){
   Fid("image").style.top =  (document.compatMode=="CSS1Compat"?document.documentElement:document.body).scrollTop+80; 
} 
function OpenDiv(str1,str2,str3){
	if(Fid("image")){
		Fid("image").innerHTML="Loading...";
		Fid("image").style.visibility="visible";
		setInterval('scrolldiv()',100)
		AjaxGet("../../../save.asp?action=Mpg_img&thisIMG="+str1+"&thisID="+str2+"&thisPRO="+str3+"");
	}
}
//创建XML对象
function createXMLHttps(){
var ret = null;
try {ret = new ActiveXObject('Msxml2.XMLHTTP')}
catch (e) {
try {ret = new ActiveXObject('Microsoft.XMLHTTP')}
catch (ee) {ret = null}
}
if (!ret&&typeof XMLHttpRequest !='undefined') ret = new XMLHttpRequest();
return ret;
}
function AjaxGet(URL) {
var xmlhttp = createXMLHttps();
xmlhttp.open("Get",URL,true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status==404) {Fid("image").innerHTML='读取页面失败,文件'+URL+'不存在!';return}
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
Fid("image").innerHTML="<div class='LoadContent'>"+xmlhttp.responseText+"</div>";
}
}
xmlhttp.send(null);
}




addLoadEvent(loadCookie);
addLoadEvent(scrollon);
window.onUnload=writeCookie;