

function correctPNG()
{
   for(var i=0; i<document.images.length; i++)
   {
   var img = document.images[i]
   var imgName = img.src.toUpperCase()
   if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
   {
   var imgID = (img.id) ? "id='" + img.id + "' " : ""
   var imgClass = (img.className) ? "class='" + img.className + "' " : ""
   var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
   var imgStyle = "display:inline-block;" + img.style.cssText
   if (img.align == "left") imgStyle = "float:left;" + imgStyle
   if (img.align == "right") imgStyle = "float:right;" + imgStyle
   if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle 
   var strNewHTML = "<span " + imgID + imgClass + imgTitle
   + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
   + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
   + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
   img.outerHTML = strNewHTML
   i = i-1
   };
   };
};

if(navigator.userAgent.indexOf("MSIE")>-1)
{
window.attachEvent("onload", correctPNG);
};

function change_img(imgsrc,linkid)
{
	document.getElementById("smallpic").src=imgsrc;
	document.getElementById("bigpic").src=imgsrc;
	for(var i=1;i<7;i++)
	{
		if(document.getElementById("alink_"+i)!=null)
		 {
			document.getElementById("alink_"+i).className=""; 
			document.getElementById("aspan_"+i).className="";
		 }
	}
	document.getElementById("alink_"+linkid).className="noLinkIcon"; 
	document.getElementById("aspan_"+linkid).className="noLink";
}

function change_imglist_sp(colorid,pid)
{
	for(var i=1;i<7;i++)
	{
		if(document.getElementById("tlink_"+i)!=null)
		 {
			document.getElementById("tlink_"+i).className=""; 
			document.getElementById("tspan_"+i).className="";
		 }
	}
	document.getElementById("tlink_"+colorid).className="noLinkIcon"; 
	document.getElementById("tspan_"+colorid).className="noLink";
	ajax("spanish/getlist.asp?id="+pid+"&color="+colorid+"&r="+Math.random(),"jiaodulist");
	ajax_img("spanish/getlist_img.asp?id="+pid+"&color="+colorid+"&r="+Math.random(),"smallpic");
	ajax_img("spanish/getlist_img.asp?id="+pid+"&color="+colorid+"&r="+Math.random(),"bigpic");
	document.getElementById("color").value=colorid;
}

function change_imglist(colorid,pid)
{
	for(var i=1;i<7;i++)
	{
		if(document.getElementById("tlink_"+i)!=null)
		 {
			document.getElementById("tlink_"+i).className=""; 
			document.getElementById("tspan_"+i).className="";
		 }
	}
	document.getElementById("tlink_"+colorid).className="noLinkIcon"; 
	document.getElementById("tspan_"+colorid).className="noLink";
	ajax("getlist.asp?id="+pid+"&color="+colorid+"&r="+Math.random(),"jiaodulist");
	ajax_img("getlist_img.asp?id="+pid+"&color="+colorid+"&r="+Math.random(),"smallpic");
	ajax_img("getlist_img.asp?id="+pid+"&color="+colorid+"&r="+Math.random(),"bigpic");
	document.getElementById("color").value=colorid;
}

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 ajax(URL,DIVID)
{
var obj_div=document.getElementById(DIVID);
var script="";
if(obj_div)
{
	var xmlhttp = createXMLHttps();
	xmlhttp.open("GET",URL,true);
	xmlhttp.onreadystatechange = function(){
 	if   (xmlhttp.readyState   ==   4)   {  
 	if   (xmlhttp.status   ==   200)   {   
 	document.getElementById(DIVID).innerHTML = xmlhttp.responseText;
	}  
 else   
 {   
alert( "您所请求的页面有异常。 "); 
} 
} 
}
	xmlhttp.send(null);
}
}

function ajax_img(URL,DIVID)
{
var obj_div=document.getElementById(DIVID);
var script="";
if(obj_div)
{
	var xmlhttp = createXMLHttps();
	xmlhttp.open("GET",URL,true);
	xmlhttp.onreadystatechange = function(){
 	if   (xmlhttp.readyState   ==   4)   {  
 	if   (xmlhttp.status   ==   200)   {   
 	document.getElementById(DIVID).src = xmlhttp.responseText;
	}  
 else   
 {   
alert( "您所请求的页面有异常。 "); 
} 
} 
}
	xmlhttp.send(null);
}
}


function gettotal()
{
   var t1=document.getElementById("num1").value;
   var t2=document.getElementById("num2").value;
   var t3=document.getElementById("num3").value;
   var t4=document.getElementById("num4").value;
   var t5=document.getElementById("num5").value;
   var total=0;
   if (isNaN(t1)==true||isNaN(t2)==true||isNaN(t3)==true||isNaN(t4)==true||isNaN(t5)==true)
   {
	   alert("Please enter a figure!");
   }
   else
   {
	  if(t1<0||t1<0||t1<0||t1<0||t1<0) 
	  {
		  alert("Please enter a positive number!");
	  }
	  else
	  {
		  total=parseInt(t1)+parseInt(t2)+parseInt(t3)+parseInt(t4)+parseInt(t5);
		  total=ForDight(total*parseFloat(document.getElementById("selfprice").value),2);
		  document.getElementById("total_num").innerHTML="Total:$"+total;
	  }
   }
}

function ForDight(Dight,How)

 { 

var Dight = Math.round (Dight*Math.pow(10,How))/Math.pow(10,How); 

return Dight; 

} 
function gettotal2()
{
   var t1=document.getElementById("num").value;
   var total=0;
   if (isNaN(t1)==true)
   {
	   alert("Please enter a figure!");
   }
   else
   {
	  if(t1<0||t1<0||t1<0||t1<0||t1<0) 
	  {
		  alert("Please enter a positive number!");
	  }
	  else
	  {
		  total=parseInt(t1);
		  total=ForDight(total*parseFloat(document.getElementById("selfprice").value),2);
		  document.getElementById("total_num").innerHTML="Total:$"+total;
	  }
   }
}


function subformlist()
{
   var t1=document.getElementById("num1").value;
   var t2=document.getElementById("num2").value;
   var t3=document.getElementById("num3").value;
   var t4=document.getElementById("num4").value;
   var t5=document.getElementById("num5").value;
   var total=0;
   if (isNaN(t1)==true||isNaN(t2)==true||isNaN(t3)==true||isNaN(t4)==true||isNaN(t5)==true)
   {
	   alert("Please enter a figure!");
   }
   else
   {
	  if(t1<0||t1<0||t1<0||t1<0||t1<0) 
	  {
		  alert("Please enter a positive number!");
	  }
	  else
	  {
		  total=parseInt(t1)+parseInt(t2)+parseInt(t3)+parseInt(t4)+parseInt(t5);
		  if(total>0)
		  {
			  document.getElementById("num").value=total;
			  var id=document.getElementById("pid").value;
			  var color=document.getElementById("color").value;
			  var url="save_cart.asp?pid="+id+"&color="+color+"&num1="+t1+"&num2="+t2+"&num3="+t3+"&num4="+t4+"&num5="+t5+"&num="+total;
			  location.href=url;
		  }
		  else
		  {
			  alert("Product quantity must be greater than 0!");
		  }
	  }
   }
}


function subform()
{
	var t1=document.getElementById("num").value;
   var total=0;
   if (isNaN(t1)==true)
   {
	   alert("Please enter a figure!");
   }
   else
   {
	  if(t1<0) 
	  {
		  alert("Please enter a positive number!");
	  }
	  else
	  {
		  total=parseInt(t1);
		  if(total>0)
		  {
			  var id=document.getElementById("pid").value;
			  var color=document.getElementById("color").value;
			  var url="save_cart.asp?pid="+id+"&color="+color+"&num="+total;
			  location.href=url;
		  }
		  else
		  {
			  alert("Product quantity must be greater than 0!");
		  }
	  }
   }
}

function adduser()
{
	var username=document.getElementById("username").value;
	if(checkspace_self(username) || username.length < 0)
	{
	   document.getElementById("username").focus();
       alert("Personnel Name should not be empty, please re-enter!");
	}
	else
	{
	  ajax("getuserc.asp?username="+username+"&r="+Math.random(),"userlist");
	}
}

function adduser_list(id)
{
	var username=escape(document.getElementById("username").value);
	if(checkspace_self(username) || username.length < 0)
	{
	   document.getElementById("username").focus();
       alert("Personnel Name should not be empty, please re-enter!");
	}
	else
	{
	  ajax("getuserlist.asp?id="+id+"&username="+username+"&r="+Math.random(),"userlist");
	  document.getElementById("circlelist").src="design_circle_mamage_content.asp?id="+id+"&r="+Math.random();
	}
}

function checkspace_self(checkstr) {
  var str = '';
  for(i = 0; i < checkstr.length; i++) {
    str = str + ' ';
  }
  return (str == checkstr);
}
