var dhtmlpopup_popupsIncluded;
/*
afb 7/8/2005
dhtmlpopup replaces exitPopUp()
*/
function dhtmlPopUp(){
	dhtmlpopup_ns=(document.layers);
	dhtmlpopup_ie=(document.all);
	dhtmlpopup_w3=(document.getElementById && !dhtmlpopup_ie);
	dhtmlpopup_popupsIncluded = true;
	dhtmlpopup_timerid = 0;

	if(navigator.cookieEnabled){ // not on cookieless browsers
		var cookiename = "dhtmlpopup=";
		var cookieval="";
		// check for cookie, 
		var strCookie = document.cookie;
		// if cookie exists , get val
		var i = strCookie.indexOf(cookiename);
		
		if(i==-1){
			// if it doesn't exist set val=1, no expire value exit func
			strCookie="dhtmlpopup=1;path=/";
			document.cookie=strCookie;
			return;
		} else {
			// check for nodhtmlpopup cookie
			if(strCookie.indexOf("nodhtmlpopup")!=-1){
			
				return;
			}
		}
		// check document.referrer, if pcworld.com  then it is second page view
		if(document.referrer.indexOf("pcworld.com")!=-1 && !blockExcludedPages()){
			var d = new Date();
			d.setDate(d.getDate()+7); //expire in 7 days
			strCookie="nodhtmlpopup=1;expires="+d.toGMTString();
			strCookie += "; domain=.pcworld.com; path=/";
			document.cookie=strCookie;
			showDHTMLPopUpAd();
		}	
	}
}

function initDHTMLPopUpAd(){
	if(!dhtmlpopup_ns && !dhtmlpopup_ie && !dhtmlpopup_w3) return;
	var dart = '<img src="http://ad.doubleclick.net/ad/idg.us.pcw.wts/wtssoMF;sz=1x1" width="1" height="1" />';
	if(dhtmlpopup_ie) {
		eval('document.all.dart.innerHTML = dart');
	    adDiv=eval('document.all.sponsorAdDiv.style');
	    adCloseDiv=eval('document.all.adCloseBoxDiv.style');
	}
	else if(dhtmlpopup_ns)	{
		eval('document.layers["dart"].innerHTML = dart');
	    adDiv=eval('document.layers["sponsorAdDiv"]');
	    adCloseDiv=eval('document.layers["adCloseBoxDiv"]');
    }
	else if(dhtmlpopup_w3)	{
		eval ('document.getElementById("dart").innerHTML = dart');
	    adDiv=eval('document.getElementById("sponsorAdDiv").style');
	    adCloseDiv=eval('document.getElementById("adCloseBoxDiv").style');
    }
	if (dhtmlpopup_ie||dhtmlpopup_w3){
		adDiv.visibility="visible";
	} else {
		adDiv.visibility ="show";
	}
}

function showDHTMLPopUpAd(){
	initDHTMLPopUpAd();
	adDiv.left="280px";adDiv.top="220px";adDiv.zIndex=Number.MAX_VALUE;
	dhtmlpopup_timerid=setTimeout("closeDHTMLPopUpAd()",20000);
	dhtmlpopup_zindexid = setInterval(setPopUpZindex, 100);
}

function closeDHTMLPopUpAd(){
	clearInterval(dhtmlpopup_zindexid);
	if (dhtmlpopup_ie||dhtmlpopup_w3)
		adDiv.display="none";
	else
		adDiv.visibility ="hide";
}

function validateDHTMLPopUpForm(frm){
	with(frm){
		if(cds_name.value==""){
			alert("Please Enter Name");
			cds_name.focus();
			return false;
		}
		
		if(cds_address_1.value==""){
			alert("Please Enter Address");
			cds_address_1.focus();
			return false;
		}
		
		if(cds_city.value==""){
			alert("Please Enter City");
			cds_city.focus();
			return false;
		}
		
		if(cds_state.value==""){
			alert("Please Enter State");
			cds_state.focus();
			return false;
		}
		if(cds_zip.value==""){
			alert("Please Enter Zip Code");
			cds_zip.focus();
			return false;
		}
		
		return true;
	}
}

function setPopUpZindex() {
	if(adDiv) {
		adDiv.zIndex = 999;
	}	 
}

function blockExcludedPages(){
	var path=location.href;
	path=path.substring(path.indexOf('.com/')+4);
	switch(path.toLowerCase()){
		case '/':
		case '/ic/desktops/':
		case '/ic/laptops/':
		case '/ic/windows/':
		case '/reviews/hardware/':
		case '/reviews/software/':
		case '/howto/':
		case '/news/':
		return true;
	}
	return false;
}