var ie=document.all && !window.opera;
var iebody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body ;
var ht=(ie)? iebody.clientHeight: window.innerHeight ;//screen.height
//alert(ht);
var wt=(ie)? iebody.clientWidth : window.innerWidth ;//screen.width

var today = new Date();
today.setTime( today.getTime() );
today.setHours(today.getHours()+1);
today.setMinutes(0);
today.setSeconds(0);

//alert(today);
//alert(today.getTime());

/*var Url = 
{
 
	// public method for url encoding
	encode : function (string) 
	{
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) 
	{
		return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) 
	{
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) 
		{
 
			var c = string.charCodeAt(n);
 
			if (c < 128) 
			{
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) 
			{
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else 
			{
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) 
	{
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) 
		{
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) 
			{
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) 
			{
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else 
			{
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}*/



 
 
function	utf8_encode  (string) 
{
	string = string.replace(/\r\n/g,"\n");
	var utftext = "";

	for (var n = 0; n < string.length; n++) 
	{

		var c = string.charCodeAt(n);

		if (c < 128) 
		{
			utftext += String.fromCharCode(c);
		}
		else if((c > 127) && (c < 2048)) 
		{
			utftext += String.fromCharCode((c >> 6) | 192);
			utftext += String.fromCharCode((c & 63) | 128);
		}
		else 
		{
			utftext += String.fromCharCode((c >> 12) | 224);
			utftext += String.fromCharCode(((c >> 6) & 63) | 128);
			utftext += String.fromCharCode((c & 63) | 128);
		}

	}

	return escape(utftext);
}
 




String.prototype.equalsIgnoreCase=myEqualsIgnoreCase;
String.prototype.equals=myEquals;

function myEquals(arg)
{
        return (this.toString()==arg.toString());
}

function myEqualsIgnoreCase(arg)
{               
        return (new String(this.toLowerCase())==(new String(arg)).toLowerCase());
}




function showAdsforContent(show_ads_id,iframe_width,iframe_height,show_ads_url,block_count,span_id)
{
	title = document.title; 
	metainfo=document.getElementsByTagName('meta');
	ref=document.referrer;

	var cont='';
	desc = ""; 
	keyword_from_meta = ""; 
	for(i=0; i<metainfo.length;i++)
	{
		if(metainfo[i].httpEquiv.equalsIgnoreCase ('Content-Type'))
		{
			 var tmp=metainfo[i].content;
			 var arr1=tmp.split(";");
			 for(var j=0; j<arr1.length;j++)
			 {
					if(arr1[j].substr(1,7).equalsIgnoreCase ("charset"))
					{
						//alert(arr1[j]);
						var arr2=arr1[j].split("=");
						if(arr2.length>=2)
							cont=arr2[1];
					}
			 }
		}

		if(metainfo[i].name.equalsIgnoreCase ('keywords'))
		{
			keyword_from_meta=metainfo[i].content;
		}
		if((title=="" ||title.equalsIgnoreCase ("Untitled Document"))&& metainfo[i].name.equalsIgnoreCase ('title'))
		{
			title=metainfo[i].content;
		}
		if(metainfo[i].name.equalsIgnoreCase ('description'))
		{
			desc=metainfo[i].content;
		}
	}


	adunitrendered='f';
	var adunits=Get_Cookie('_io_ads');
	if(adunits)
	{
		var adunitsarr=adunits.split(",");
		for(var j=0; j<adunitsarr.length;j++)
		{
			if(adunitsarr[j]==show_ads_id)
			{
				adunitrendered='t';
				break;
			}
		}
		if(adunitrendered=='f')
		{
			adunits=adunits+show_ads_id+',';
		}
	}
	else
		adunits=show_ads_id+',';

	//alert(adunitrendered+adunits);

	Set_Cookie( '_io_ads', adunits, 0 , "/") ;

	var url=show_ads_url;
	url=url+"?id="+show_ads_id;	
	url=url+"&ht="+iframe_height;	
	url=url+"&r="+adunitrendered;	
	url=url+"&blockcount="+block_count;
	url=url+"&content_type="+cont;
	url=url+"&search="+utf8_encode(keyword_from_meta);
	url=url+"&title="+utf8_encode(title);
	url=url+"&desc="+utf8_encode(desc);
	url=url+"&ref="+utf8_encode(ref);
	//alert(url); 

	frame="";
	ad_pos=eval(span_id+"_"+show_ads_id+"_position");
	//alert(ad_pos);
	
	if(ad_pos)
	{
		horiz_center=((wt/2 )- (iframe_width/2))+"px";
		ver_center=((ht/2 )- (iframe_height/2))+"px";
		
	}
	//alert("hai");

		frame+="<iframe frameborder=\"0\" src=\""+url+"\" height=\""+iframe_height+"\" width=\""+iframe_width+"\" scrolling=\"no\" ></iframe>";
	//alert(frame);







//document.open();
//document.write(frame);
//document.close();


	document.getElementById("show_"+span_id+'_'+show_ads_id).innerHTML=frame;










	
}



function showAdsforKeyword(show_ads_id,iframe_width,iframe_height,show_ads_url,block_count,span_id)
{
	
	title = document.title; 
	metainfo=document.getElementsByTagName('meta');
	ref=document.referrer;
	var cont='';
	for(i=0; i<metainfo.length;i++)
	{
		if(metainfo[i].httpEquiv.equalsIgnoreCase('Content-Type'))
		{
			 var tmp=metainfo[i].content;
			 var arr1=tmp.split(";");
			 for(var j=0; j<arr1.length;j++)
			 {
					if(arr1[j].substr(1,7).equalsIgnoreCase ("charset"))
					{
						//alert(arr1[j]);
						var arr2=arr1[j].split("=");
						if(arr2.length>=2)
							cont=arr2[1];
					}
			 }
		}
	}

	adunitrendered='f';
	var adunits=Get_Cookie('_io_ads');
	if(adunits)
	{
		var adunitsarr=adunits.split(",");
		for(var j=0; j<adunitsarr.length;j++)
		{
			if(adunitsarr[j]==show_ads_id)
			{
				adunitrendered='t';
				break;
			}
		}
		if(adunitrendered=='f')
		{
			adunits=adunits+show_ads_id+',';
		}
	}
	else
		adunits=show_ads_id+',';

	//alert(adunitrendered+adunits);

	Set_Cookie( '_io_ads', adunits, 0 , "/") ;


	//alert(keyword);
	var url=show_ads_url;
	url=url+"?id="+show_ads_id;	
	url=url+"&ht="+iframe_height;	
	url=url+"&r="+adunitrendered;	
	url=url+"&blockcount="+block_count;
	url=url+"&content_type="+cont;
	url=url+"&search="+utf8_encode(keyword);
	url=url+"&ref="+utf8_encode(ref);
	//alert(url);
	frame="";
	ad_pos=eval(span_id+"_"+show_ads_id+"_position");
	
	if(ad_pos)
	{
		horiz_center=((wt/2 )- (iframe_width/2))+"px";
		ver_center=((ht/2 )- (iframe_height/2))+"px";
		switch(ad_pos)
		{}
	}
	
		frame+="<iframe frameborder=\"0\" src=\""+url+"\" height=\""+iframe_height+"\" width=\""+iframe_width+"\" scrolling=\"no\" ></iframe>";
	
	//alert(frame);
	


//document.open();
//document.write("<iframe frameborder=\"0\" src=\""+url+"\" height=\""+iframe_height+"\" width=\""+iframe_width+"\" scrolling=\"no\" ></iframe>");
//document.close();





document.getElementById("show_"+span_id+'_'+show_ads_id).innerHTML=frame;





	
	
}


function showContentAds(metainfo)
{
	var cont='';
	desc = ""; 
	keyword_from_meta = ""; 
	for(i=0; i<metainfo.length;i++)
	{
		if(metainfo[i].httpEquiv.equalsIgnoreCase ('Content-Type'))
		{
			 var tmp=metainfo[i].content;
			 var arr1=tmp.split(";");
			 for(var j=0; j<arr1.length;j++)
			 {
					if(arr1[j].substr(1,7).equalsIgnoreCase ("charset"))
					{
						//alert(arr1[j]);
						var arr2=arr1[j].split("=");
						if(arr2.length>=2)
							cont=arr2[1];
					}
			 }
		}
		
		
		if(metainfo[i].name.equalsIgnoreCase ('keywords'))
		{
			keyword_from_meta=metainfo[i].content;
		}
		if((title=="" ||title.equalsIgnoreCase ("Untitled Document"))&& metainfo[i].name.equalsIgnoreCase ('title'))
		{
			title=metainfo[i].content;
		}
		if(metainfo[i].name.equalsIgnoreCase ('description'))
		{
			desc=metainfo[i].content;
		}
	}
	
	adunitrendered='f';
	var adunits=Get_Cookie('_io_ads');
	if(adunits)
	{
		var adunitsarr=adunits.split(",");
		for(var j=0; j<adunitsarr.length;j++)
		{
			if(adunitsarr[j]==show_ads_id)
			{
				adunitrendered='t';
				break;
			}
		}
		if(adunitrendered=='f')
		{
			adunits=adunits+show_ads_id+',';
		}
	}
	else
		adunits=show_ads_id+',';

	//alert(adunitrendered+adunits);

	Set_Cookie( '_io_ads', adunits, 0 , "/") ;


	var url=show_ads_url;
	url=url+"?id="+show_ads_id;	
	url=url+"&ht="+iframe_height;	
	url=url+"&r="+adunitrendered;	
	url=url+"&blockcount="+block_count;
	url=url+"&content_type="+cont;
	url=url+"&search="+utf8_encode(keyword_from_meta);
	url=url+"&title="+utf8_encode(title);
	url=url+"&desc="+utf8_encode(desc);
	url=url+"&ref="+utf8_encode(ref);
	//alert(url); 
	frame="<iframe frameborder=\"0\" src=\""+url+"\" height=\""+iframe_height+"\" width=\""+iframe_width+"\" scrolling=\"no\" ></iframe>";
	
	document.getElementById("show_ads_"+show_ads_id).innerHTML=frame;
		
}



function showKeywordAds()
{
	var cont='';
	for(i=0; i<metainfo.length;i++)
	{
		if(metainfo[i].httpEquiv.equalsIgnoreCase('Content-Type'))
		{
			 var tmp=metainfo[i].content;
			 var arr1=tmp.split(";");
			 for(var j=0; j<arr1.length;j++)
			 {
					if(arr1[j].substr(1,7).equalsIgnoreCase ("charset"))
					{
						//alert(arr1[j]);
						var arr2=arr1[j].split("=");
						if(arr2.length>=2)
							cont=arr2[1];
					}
			 }
		}
	}

	adunitrendered='f';
	var adunits=Get_Cookie('_io_ads');
	if(adunits)
	{
		var adunitsarr=adunits.split(",");
		for(var j=0; j<adunitsarr.length;j++)
		{
			if(adunitsarr[j]==show_ads_id)
			{
				adunitrendered='t';
				break;
			}
		}
		if(adunitrendered=='f')
		{
			adunits=adunits+show_ads_id+',';
		}
	}
	else
		adunits=show_ads_id+',';

	//alert(adunitrendered+adunits);

	Set_Cookie( '_io_ads', adunits, 0 , "/") ;


	var url=show_ads_url;
	url=url+"?id="+show_ads_id;	
	url=url+"&ht="+iframe_height;	
	url=url+"&r="+adunitrendered;	
	url=url+"&blockcount="+block_count;
	url=url+"&content_type="+cont;
	url=url+"&search="+utf8_encode(keyword);
	url=url+"&ref="+utf8_encode(ref);
	//alert(url);
	frame="<iframe frameborder=\"0\" src=\""+url+"\" height=\""+iframe_height+"\" width=\""+iframe_width+"\" scrolling=\"no\" ></iframe>";
	document.getElementById("show_ads_"+show_ads_id).innerHTML=frame;
	
}

/*
function URLEncode (clearString) 
{
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) 
  {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') 
	{
    	output += match[1];
      x += match[1].length;
    } else 
	{
      if (clearString[x] == ' ')
        output += '+';
      else 
	  {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

function getCookie(name)
{
	var cookies = document.cookie;
	if (cookies.indexOf(name) != -1)
	{
		var startpos = cookies.indexOf(name)+name.length+1;
		var endpos = cookies.indexOf(";",startpos)-1;
		if (endpos == -2) endpos = cookies.length;
		return unescape(cookies.substring(startpos,endpos));
	}
	else
	{
		return false;
	}
}

function setCookie(name, value, expires)
{
	// no expiration date specified? use this date and it will just be deleted soon.
	if (!expires) expires = new Date(); 
		document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() + "; path=/";
}

function delete_cookie ( cookie_name )
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}
*/


function pf204652show(span_id,ad_pos,show_ads_id)
{
	//alert(eval("this.pf204652bottomLayer"+span_id+show_ads_id));
	if(ad_pos>4)
	{
		eval("this.pf204652curHeight"+span_id+show_ads_id+" -= 2;");
		eval("if (this.pf204652curHeight"+span_id+show_ads_id+" < this.pf204652maxHeight"+span_id+show_ads_id+"){clearInterval ( this.pf204652IntervalId"+span_id+show_ads_id+" );}this.pf204652bottomLayer"+span_id+show_ads_id+".style.top = this.pf204652curHeight"+span_id+show_ads_id+"+'px';");
	}
	else		
	{
		eval("this.tempTop"+span_id+show_ads_id+" += 2;");
		eval("if (this.tempTop"+span_id+show_ads_id+" >=0){clearInterval ( this.pf204652IntervalId"+span_id+show_ads_id+" );}this.pf204652bottomLayer"+span_id+show_ads_id+".style.top = this.tempTop"+span_id+show_ads_id+"+'px';");
	}
}





function get_current_working_path(str)
{
	var end_pos=(str.search(/publisher-show-ads.php/));
	var url_str_var;
	if(end_pos!=-1)
	{
		url_str_var=(str.substring(0,end_pos));
	}
	else
	{
		var end_pos=(str.search(/show-ads.php/));
		if(end_pos!=-1)
			url_str_var=(str.substring(0,end_pos));
	}
	return(url_str_var);
}



function Set_Cookie( name, value, expires, path, domain, secure ) 
{	

	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 ;
	}
	var expires_date = new Date( today.getTime() + (expires) );
//alert(expires_date);
	document.cookie = name + "=" +escape( value ) +

		 ";expires=" + expires_date.toGMTString()  + //expires.toGMTString()

		( ( path ) ? ";path=" + path : "" ) + 

		( ( domain ) ? ";domain=" + domain : "" ) +

		( ( secure ) ? ";secure" : "" );

}


function Get_Cookie( name )
 {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}

	if ( start == -1 ) return null;

	var end = document.cookie.indexOf( ";", len );

	if ( end == -1 ) end = document.cookie.length;

	return unescape( document.cookie.substring( len, end ) );

}



function Delete_Cookie( name, path, domain ) 
{
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +

			( ( path ) ? ";path=" + path : "") +

			( ( domain ) ? ";domain=" + domain : "" ) +

			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

