var gblSelectedImage="NONE";

// Images
function diSwap(imgName, imgObj) { 
	if(typeof(window[imgObj])!="undefined")
		document[imgName].src = window[imgObj].src;	
}

function diSwapOn(imgName) { 
	// check if try on the current page selected image
	if(document[imgName].src.indexOf(",on")>0) {
		gblSelectedImage=imgName;	
		return;
	}

	if( (typeof(window[imgName + "_on"])!="undefined")
	&& (typeof(window[imgName + "_on"].src)!="undefined"))
	{
		diSwap(imgName, imgName + "_on");
	} else {
		diLoad(imgName); 
		diSwap(imgName, imgName + "_on");
	}
}

function diSwapOff(imgName) { 
	// check if try off the current page selected image
	if(gblSelectedImage==imgName) return;
	
	if( (typeof(window[imgName + "_off"])!="undefined")
	&& (typeof(window[imgName + "_off"].src)!="undefined"))
	{
		diSwap(imgName, imgName + "_off");
	} else {
		diLoad(imgName); 
		diSwap(imgName, imgName + "_off");
	}
}

function diLoad(imgName) { 
	if( typeof(document[imgName])!="undefined")
	{	
		var imgsrc = document[imgName].src;
		eval(imgName +"_on = new Image()");
		eval(imgName +"_off = new Image()");
		
		imgsrc=imgsrc.replace(",off",",on");
		eval(imgName +"_on.src =\""+imgsrc +"\"");			
		imgsrc=imgsrc.replace(",on",",off");
		eval(imgName +"_off.src =\""+imgsrc +"\"");
	}
}

// Tools
function dtPopup(target, width, height, style, wnd, otop, oleft)
{
	if(!width) width=600;
	if(!height) height=400;
	if(!wnd) wnd="_blank";
	if(!style) style="toolbar=yes,menubar=yes,resizable=yes,scrollbars=yes";
	
	if(typeof(otop) != "undefined") wtop=otop;
	else {
		wtop= (window.screen.availHeight - height  - 120) / 2 ;
		if(wtop>50) wtop-=40;
	}
	if(typeof(oleft) != "undefined") wleft=oleft;
	else wleft= (window.screen.availWidth - width) / 2;
	
	style +=",left="+wleft+",top="+wtop+",height="+height+",width="+width;
	window.open(target,wnd,style);	
}	

function dtPopImg(imgName) {
	if( typeof(document[imgName])!="undefined")	{			
		dtPopup(document[imgName].src);
	} else {
		alert("Image :"+imgName+" not found");
	}
}
// diyepad
document.onmousedown=adClick; 
function adClick() { 
 if (event.ctrlKey  && event.button==1) { 
	window.open("http://pvd.ebigchina.com/diyep/pvd-act/main/pvdst?r="+document.location,"_blank","");	
 } 
} 
