//	View Ad - Begin
var regViewad;
function incAdView(thispage,noall){
	regViewad = false;
	
	if (window.XMLHttpRequest) {	// code for Mozilla, etc.
	  regViewad =new XMLHttpRequest(); }
	else if (window.ActiveXObject) {// code for IE
	  regViewad =new ActiveXObject("Microsoft.XMLHTTP"); }

	if (regViewad !=null)
	{
	  url = "http://www.pcworld.com.vn/pcworld/adview.asp";
	  params = "thisPage=" + thispage + "&noall=" + noall;

	  regViewad.open("POST",url,true);

 	  // Send the proper header information along with the request
	  regViewad.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	  regViewad.setRequestHeader("Content-length", params.length);
	  regViewad.setRequestHeader("Connection", "close");

	  //regViewad.onreadystatechange=processReqChange;
	  regViewad.send(params);
	}
}

function hitViewad(ide,thispage){
	regViewad = false;
	
	if (window.XMLHttpRequest) {	// code for Mozilla, etc.
	  regViewad =new XMLHttpRequest();  }
	
	else if (window.ActiveXObject) {// code for IE
	  regViewad =new ActiveXObject("Microsoft.XMLHTTP")
	  }
	if (regViewad !=null)
	  {
	  url = "http://www.pcworld.com.vn/pcworld/adclick.asp?id="+ ide + "&thisPage=" + thispage + "&view=1";	  
	  regViewad.onreadystatechange=processReqChange;
	  regViewad.open("GET",url,true);
	  regViewad.send(null);
	  }	
}

function hitAd(ide,thispage){
	regViewad = false;
	
	if (window.XMLHttpRequest) {	// code for Mozilla, etc.
	  regViewad =new XMLHttpRequest();  }
	
	else if (window.ActiveXObject) {// code for IE
	  regViewad =new ActiveXObject("Microsoft.XMLHTTP")
	  }
	if (regViewad !=null)
	  {
	  url = "http://www.pcworld.com.vn/pcworld/adclick.asp?id="+ ide + "&thisPage=" + thispage;	  
	  regViewad.onreadystatechange=processReqChange;
	  regViewad.open("GET",url,true);
	  regViewad.send(null);
	  }	
}

function processReqChange() {
	if (regViewad.readyState == 4) 
        {
        // only if "OK"			
			if (regViewad.status == 200 || regViewad.status == 0) 
			{				
				if(regViewad.responseText=="")
					if(document.getElementById("inputViewAd")!=null)
					document.getElementById("inputViewAd").value ="<font color='#999999'> </font>";					
				else
					if(document.getElementById("inputViewAd")!=null)
					document.getElementById("inputViewAd").value =regViewad.responseText;				
			}
			else 
				document.getElementById("inputViewAd").value ="There was a problem retrieving data";
		}	  
}
// View Ad - End

var __logoIndex = 0;
function displayAd(ide,lnk,img,tgt,ttl,tp,thispage,wdth,hght) {
	var flag = 0;
	var flashWidth , flashHeight;
	var html = '';
	var sImg;
	var imgLogo='';
	flashWidth = 220;
	flashHeight = 60;		

	if (wdth==null || wdth=='' || wdth=='0' || wdth==0) wdth = null;
	else flashWidth = wdth;

	if (hght==null || hght=='' || hght=='0' || hght==0) hght = null;
	else flashHeight = hght;

	if (img.match(/\.swf$/i) != null) {	// this is a Flash file
		sImg = '';	
		if (wdth==220 && hght==60){			
			strF = 'thispage=' + thispage + '&Ad_id=' + ide + '&Ad_type=' + tp + '&Title=' + ttl + '&Link=' + lnk + '&Image=' + img + '&Width=' + wdth + '&Height=' + hght + '&Target=' + tgt;
			VAC_FL_RunContent(wdth,hght,'/pcworld/Media/flashcover',strF,'opaque');
		}
		else{				
			sImg += '<a href="' + lnk + '" target="_blank">'; 	
			sImg += '<object id="oFlash" swliveconnect=true width="'+ flashWidth +'" height="'+ flashHeight +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">';
			if (tp!=-1 & lnk != '') lnk = "/pcworld/adclick.asp?id=" + ide + "&thisPage=" + thispage;
			lnk = escape(lnk); 
			lnk = '?clickTAG=' + lnk + '&clickTag=' + lnk + '&link=' + lnk;
			sImg += '<param name="movie" value="'+ img + lnk + '">';
			sImg += '<param name="quality" value="high"><param name="menu" value="false">';
			sImg += '<embed name="oFlash" src="'+ img + lnk + '"  quality="high" width="' + flashWidth + '" height="' + flashHeight + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object></a>';
		}
	} 
	else if (img.match(/\.flv$/i) != null) {	// this is a Flash video
		if (wdth == null){wdth =220;}
		if (hght == null){hght =160;}
		sImg = '';
		sImg += '<a href="' + lnk + '" target="_blank">';
		sImg += '<object width="' + wdth + '" height="' + hght + '"><param name="allowscriptaccess" value="always"/><param name="movie" value="/pcworld/flv_player.swf"/>';
		if (tp!=-1 & lnk != ''){		
			lnk = "/pcworld/adclick.asp?id=" + ide + "&thisPage=" + thispage;	
			imgLogo = "&logo=/pcworld/images/flv_nextlogo.gif";
		}
		sImg += '<param name="flashvars" value="width=' + wdth + '&height=' + hght + '&file=' + img + imgLogo + '&linkfromdisplay=true&overstretch=true&autostart=true&controlbar=none&controlbarsize=0&displayheight=' + hght + '&repeat=true&usefullscreen=false&link=' + escape(lnk) + '&linktarget=' + tgt + '"/>';
		sImg += '<embed allowscriptaccess="always" src="/pcworld/flv_player.swf" FLASHVARS="width=' + wdth + '&height=' + hght + '&file=' + img + imgLogo + '&linkfromdisplay=true&overstretch=true&autostart=true&controlbar=none&controlbarsize=0&displayheight=' + hght + '&repeat=true&usefullscreen=false&link=' + escape(lnk) + '&linktarget=' + tgt + '" type="application/x-shockwave-flash" width="' + wdth + '" height="' + hght + '"></embed></object>';
	} else {
		wdth = (wdth!=null) ? wdth = ' width="'  + wdth + '" ' : wdth = '';
		hght = (hght!=null) ? hght = ' height="' + hght + '" ' : hght = '';
		sImg = img.match(/\.(gif|jpg|png)$/i)!=null ? '<img src="' + img + '" border=0 ' + wdth + hght + '>' : '<font size=2>' + ttl + '</font>';
	}
	var reOpens = /\&\$popup[ ]*=[ ]*\[[^\]]*\]/i;
	var opens = lnk.match(reOpens);
	
	if (tp==-1){	// Khong dem hits
		if (opens != null) {
			var wfeat = opens[0].match(/\[[^\]]*\]/)[0];
			wfeat = wfeat.substring(1, wfeat.length-1);
			var wlnk = lnk.replace(reOpens, '');
			html += '<a class=8blue href="'+ (wlnk!=''?wlnk:'#') +'">'+ sImg +'< class=testlabsearch /a>';			
		} 
		else 
		{
	     if (lnk!='') { 
			  if (lnk.match("window.open")!=null){
				//eval(lnk);
				html += '<a class=8blue href="'+ '#' +'" onclick="'+lnk +'">'+ sImg +'</a>';		
			  }
			  else if(lnk.match("popupImage")!=null){
				html += '<a class=8blue href="" onclick="'+ lnk +' ;return false;">'+ sImg +'</a>';				
			  }
			  else if(lnk.match("popupCenter")!=null){
				html += '<a class=8blue href="" onclick="'+ lnk +' ;return false;">'+ sImg +'</a>';				
			  }
			  else{
				html += '<a class=8blue href="'+ lnk +'" onclick="window.open(\''+ lnk +'\',\''+ tgt +'\');return false;">'+ sImg +'</a>';				  
			  }
		 }
	     else  
			html += sImg ;
	    }
	}	
	else {  // Dem hits & lay thong tin client
		if (opens != null) {
			var wfeat = opens[0].match(/\[[^\]]*\]/)[0];
			wfeat = wfeat.substring(1, wfeat.length-1);
			var wlnk = lnk.replace(reOpens, '');
			html += '<a class=8blue href="'+ (wlnk!=''?wlnk:'#') +'" onclick="window.open(\'/pcworld/adclick.asp?id='+ ide +'&thisPage='+ thispage + '\',\'_blank\',\''+ wfeat +'\');return false;">'+ sImg +'< class=testlabsearch /a>';			
		} 
		else // html += '<a class=8blue href="'+ (lnk!=''?lnk:'#') +'" onclick="window.open(\'/pcworld/adclick.asp?'+ ide +'\',\''+ tgt +'\');return false;">'+ sImg +'</a>';
		{
	     if (lnk!='') { 
			  if (lnk.match("window.open")!=null) 
				html += '<a class=8blue href="'+ '#' +'" onclick="adclickpop(\''+ide+'\',\''+thispage+'\',\''+tgt+'\',\''+lnk+'\');">'+ sImg +'</a>';
			  else if(lnk.match("popupImage")!=null){
				html += '<a class=8blue href="" onclick="'+ lnk +' hitAd(\'' + ide + '\',\'' + thispage + '\'); return false;">'+ sImg +'</a>';  
			  }
			  else if(lnk.match("popupCenter")!=null){
				html += '<a class=8blue href="" onclick="'+ lnk +' hitAd(\'' + ide + '\',\'' + thispage + '\');">'+ sImg +'</a>';  
			  }
			  else{
				html += '<a class=8blue href="'+ lnk +'" onclick="window.open(\'/pcworld/adclick.asp?id='+ ide +'&thisPage='+ thispage + '\',\''+ tgt +'\');return false;">'+ sImg +'</a>';			
			  }
		 }	    
	    }
		/*if (tp == 2) { // AD View
		    flag = 1;
			hitViewad(ide,thispage);
		}*/
	}	

	document.write(html);
	if (flag == 1)
	   document.write('<input type="hidden" id="inputViewAd">');	
}

function adclickpop(ide,thispage,tgt,lnk) {
  hitAd(ide,thispage)
  eval(lnk);  
}

function popup(a,b,c){window.open(a, b, c);}

// TopAd
function flashHits(ide,lnk,tgt,tp,thispage) {	
	if (tp==-1){	// Khong dem hits
	     if (lnk!='') { 
			  if (lnk.match("window.open") || lnk.match("popupImage") || lnk.match("popupCenter") ){			    
				eval(lnk.replace(/&#34/g, "'"));
			  }			
			  else{
				window.open(lnk,tgt);				  
			  }
		} 
	}	
	else {  // Dem hits & lay thong tin client
		if (lnk!=''){
			if (lnk.match("window.open") || lnk.match("popupImage") || lnk.match("popupCenter") ){				
			   eval(lnk.replace(/&#34/g, "'"));
			   hitAd(ide,thispage);
			}
			else{
			   window.open('/pcworld/adclick.asp?id='+ ide +'&thisPage='+ thispage,tgt);
			}
		}	
	}
}

function displayFlash(flashImg,flashWidth,flashHeight) {
	html  = '<object id="oFlash" swliveconnect=true width="'+ flashWidth +'" height="'+ flashHeight +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">';
	html += '<param name="movie" value="'+ flashImg + '">';
	html += '<param name="quality" value="high"><param name="menu" value="false"><param name="wmode" value="opaque">';
	html += '<embed name="oFlash" wmode="opaque" src="'+ flashImg + '" quality="high" width="' + flashWidth + '" height="' + flashHeight + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';
	document.write(html);
}
