// JavaScript Document
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// JavaScript Document
function addLoad(func) {
   var oldLoad = window.onload;
   if (typeof oldLoad != "function") {
     window.onload = func;
  } else {
     window.onload = function() {
         oldLoad();
         func();
     }
  }
}
//
function CalculatePrice()
{
	var howMuchTbl=document.getElementById("howMuch");
	if(howMuchTbl==null){return;}
	var inputs=howMuchTbl.getElementsByTagName("input");
	if(inputs==null || inputs.length==0)
	{
		return false;
	}
	for(var i=0;i<inputs.length;i++)
	{
		inputs[i].onkeyup=function(){
			if(this.value.search("^-?\\d+(\\.\\d+)?$")!=0){
					var img=document.getElementById("img"+this.id);
					if(img!=null)
					{
						img.src="images/wrong_icon.gif";
						img.alt="Wrong";
					}
					this.value="";
				}else{
					var img=document.getElementById("img"+this.id);
					if(img!=null)
					{
						img.src="images/right_icon.gif";
						img.alt="Right";
					}
				}
			Price();
		};
	}
}
function Price()
{
	var num75w=document.getElementById("num75w")!=null ? (document.getElementById("num75w").value!='' ? document.getElementById("num75w").value :0) :0;
	var num100w=document.getElementById("num100w")!=null ? (document.getElementById("num100w").value!='' ? document.getElementById("num100w").value :0) :0;
	var num150w=document.getElementById("num150w")!=null ? (document.getElementById("num150w").value!='' ? document.getElementById("num150w").value :0) :0;
	var num200w=document.getElementById("num200w")!=null ? (document.getElementById("num200w").value!='' ? document.getElementById("num200w").value :0) :0;
	
	var num250w=document.getElementById("num250w")!=null ? (document.getElementById("num250w").value!='' ? document.getElementById("num250w").value :0) :0;
	var num300w=document.getElementById("num300w")!=null ? (document.getElementById("num300w").value!='' ? document.getElementById("num300w").value :0) :0;
	var num333w=document.getElementById("num333w")!=null ? (document.getElementById("num333w").value!='' ? document.getElementById("num333w").value :0) :0;
	var num400w=document.getElementById("num400w")!=null ? (document.getElementById("num400w").value!='' ? document.getElementById("num400w").value :0) :0;
	//test	
	//alert(num75w);
	//alert(num100w);
	//alert(num150w);
	//alert(num200w);
	
	//alert(num250w);
	//alert(num300w);
	//alert(num333w);
	//alert(num400w);
	//total
	var total=document.getElementById("total");
	if(total!=null)
	{
		s=parseInt(num75w)
			+parseInt(num100w)
			+parseInt(num150w)
			+parseInt(num200w)
			+parseInt(num250w)
			+parseInt(num300w)
			+parseInt(num333w)
			+parseInt(num400w);
		total.innerHTML=s;
	}
	//totalKWH
	var totalKWH=document.getElementById("totalKWH");
	if(totalKWH!=null)
	{
		s=parseInt(num75w)*504+
			parseInt(num100w)*672
			+parseInt(num150w)*1008
			+parseInt(num200w)*1344
			+parseInt(num250w)*1681
			+parseInt(num300w)*2017
			+parseInt(num333w)*2238
			+parseInt(num400w)*2689;
		totalKWH.innerHTML=s;
	}
		
	//rate
	var rateAvg=document.getElementById("rateAvg")!=null ? (document.getElementById("rateAvg").innerHTML!='' ? document.getElementById("rateAvg").innerHTML :0.08) :0.08;
	//alert(rateAvg);
	//costLights
	var costLights=document.getElementById("costLights");
	//costLights=totalkwh*rateAvg
	if(costLights!=null)
	{
		if(totalKWH!=null)
		{
			costLights.innerHTML=parseInt(parseFloat(totalKWH.innerHTML)*parseFloat(rateAvg));
		}
	}
	//expect10Cost
	var expect10Cost=document.getElementById("expect10Cost");
	if(expect10Cost!=null)
	{
		if(costLights!=null)
		{
			expect10Cost.innerHTML=parseInt(parseFloat(costLights.innerHTML)*12.578);
		}
	}
	
	
	//kwhLEDS
	var kwhLEDS=document.getElementById("kwhLEDS");
	if(kwhLEDS!=null)
	{
		s=parseFloat(num75w)*151.7+
			parseFloat(num100w)*213.2
			+parseFloat(num150w)*319.8
			+parseFloat(num200w)*479.7
			+parseFloat(num250w)*639.6
			+parseFloat(num300w)*639.6
			+parseFloat(num333w)*639.6
			+parseFloat(num400w)*848.7;
		kwhLEDS.innerHTML=parseInt(s);
	}
	//ledCost
	var ledCost=document.getElementById("ledCost");
	//costLights=totalkwh*rateAvg
	if(ledCost!=null)
	{
		if(kwhLEDS!=null)
		{
			ledCost.innerHTML=parseInt(parseFloat(kwhLEDS.innerHTML)*parseFloat(rateAvg));
		}
	}
	//costSaveLEDS
	var costSaveLEDS=document.getElementById("costSaveLEDS");
	if(costSaveLEDS!=null){
		if(costLights!=null && ledCost!=null)
		{
		    costSaveLEDS.innerHTML=parseInt(costLights.innerHTML) - parseInt(ledCost.innerHTML);
		}	
	}
	//led10Save
	var led10Save=document.getElementById("led10Save");
	if(led10Save!=null){
		if(expect10Cost!=null && ledCost!=null)
		{
		    led10Save.innerHTML=parseInt(parseFloat(expect10Cost.innerHTML) - parseFloat(ledCost.innerHTML)*12.578);
		}	
	}
	//
	//energySave
	var energySave=document.getElementById("energySave");
	if(energySave!=null)
	{
		if(totalKWH!=null && kwhLEDS!=null)
		{
			energySave.innerHTML=parseInt(totalKWH.innerHTML) - parseInt(kwhLEDS.innerHTML)+" kWh";
		}
	}
	//energySave10
	var energySave10=document.getElementById("energySave10");
	if(energySave10!=null)
	{
		if(energySave!=null)
		{
			energySave10.innerHTML=parseInt(energySave.innerHTML)*10+" kWh";
		}
	}
	//co2Save
	var co2Save=document.getElementById("co2Save");
	if(co2Save!=null)
	{
		if(energySave!=null)
		{
			co2Save.innerHTML=parseFloat(energySave.innerHTML)*0.0007+" Metric Tons";
		}
	}
	//co2_10_Save
	var co2_10_Save=document.getElementById("co2_10_Save");
	if(co2_10_Save!=null)
	{
		if(energySave10!=null)
		{
			co2_10_Save.innerHTML=parseFloat(energySave10.innerHTML)*0.0007+" Metric Tons";
		}
	}	
}
//弹出放大图
// JavaScript Document
var docEle = function() 
{
    return document.getElementById(arguments[0]) || false;
}

function getOffset(e) 
{  
	var t=e.offsetTop;  
	var l=e.offsetLeft;  
	while(e=e.offsetParent) 
	{  
	  t+=e.offsetTop;  
	  l+=e.offsetLeft;  
	}  
	var rec = new Array(1); 
	rec[0]  = t; 
	rec[1] = l; 
	return rec ;
} 

function showPic(thisObj,_id,imgSrc,imgWidth,imgHeight)
{
	var m = "mask";
	var pos =getOffset(thisObj);
    newMask = document.createElement("div");
    newMask.id = m;
    newMask.style.position = "absolute";
    newMask.style.zIndex = "1";
	newMask.style.cursor="pointer";
    _scrollWidth =thisObj.scrollWidth;
    _scrollHeight =thisObj.scrollHeight;
    newMask.style.width = _scrollWidth + "px";
    newMask.style.height = _scrollHeight + "px";
    newMask.style.top =pos[0] +"px";
    newMask.style.left =pos[1]+ "px";
    newMask.style.background = "#33393C";
    newMask.style.filter = "alpha(opacity=40)";
    newMask.style.opacity = "0.40";
    newMask.onmouseout = function()
    {
        document.body.removeChild(docEle(_id));
        document.body.removeChild(docEle(m));
    }
	document.body.appendChild(newMask);
	//新弹出层
    var newDiv = document.createElement("div");
    newDiv.id = _id;
    newDiv.style.position = "absolute";
    newDiv.style.zIndex = "9999";
    newDiv.style.width = imgWidth + "px";
    newDiv.style.height = imgHeight + "px";
	//getHeight
	var top= pos[0]-imgHeight+20;	
    newDiv.style.top =top<0? "0":top+ "px";
	//get left
	var left=0;
	//alert(document.body.clientWidth);
	if((pos[1]+imgWidth+20)<document.body.scrollWidth)
	{
		left=pos[1]+20;
	}
	else
	{
		var temp=document.body.scrollWidth-imgWidth;
		left=temp<0? 0: temp;
		//alert(left);
	}
    newDiv.style.left =left+"px";
    newDiv.style.background = "#EFEFEF";
    newDiv.style.padding = "5px";
    newDiv.innerHTML =" <img src="+imgSrc+">";
	document.body.appendChild(newDiv);
}





















