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;
	}
 
}


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());
}

var xmlHttp
function PPCShowAds()
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
//  alert(ppc_show_ads_url);
ppc_keyword=Url.encode(ppc_keyword);
ref=document.referrer;
var url=ppc_show_ads_url;
url=url+"?search="+ppc_keyword;
url=url+"&format="+ppc_ad_format;
url=url+"&imageads="+ppc_show_image_ads;
url=url+"&adscount="+ppc_total_text_ads;
url=url+"&showborder="+ppc_show_border;
url=url+"&banners="+ppc_allowed_banner_sizes;
url=url+"&bc="+ppc_border_color;
url=url+"&bgc="+ppc_background_color;
url=url+"&blockcount="+ppc_block_count;

url=url+"&titlecolor="+ppc_text_ad_title_color;
url=url+"&desccolor="+ppc_text_ad_desc_color;
url=url+"&urlcolor="+ppc_text_ad_url_color;
url=url+"&credit="+ppc_enable_credit_text;
url=url+"&creditposition="+ppc_credit_align;
url=url+"&creditcolor="+ppc_credit_text_color;
url=url+"&credittext="+ppc_show_credit_text;
url=url+"&publicads="+ppc_enable_public_ads;
url=url+"&ref="+Url.encode(ref);
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);  
xmlHttp.send(null);
} 

function PPCShowContentAds(metainfo)
{
	
	xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  
ppc_desc = ""; 
ppc_keyword = ""; 
for(i=0; i<metainfo.length;i++)
{
	if(metainfo[i].name.equalsIgnoreCase ('keywords'))
	{
		ppc_keyword=metainfo[i].content;
	}
	if((ppc_title=="" ||ppc_title.equalsIgnoreCase ('Untitled Document'))&& metainfo[i].name.equalsIgnoreCase('title'))
	{
	 	ppc_title=metainfo[i].content;
	}
	if(metainfo[i].name.equalsIgnoreCase ('description'))
	{
		ppc_desc=metainfo[i].content;
	}
}
ppc_keyword=Url.encode(ppc_keyword);
ppc_title=Url.encode(ppc_title);
ppc_desc=Url.encode(ppc_desc);
ref=document.referrer;
var url=ppc_show_ads_url;
url=url+"?search="+ppc_keyword;
url=url+"&title="+ppc_title;
url=url+"&desc="+ppc_desc;
url=url+"&format="+ppc_ad_format;
url=url+"&imageads="+ppc_show_image_ads;
url=url+"&adscount="+ppc_total_text_ads;
url=url+"&showborder="+ppc_show_border;
url=url+"&banners="+ppc_allowed_banner_sizes;
url=url+"&bc="+ppc_border_color;
url=url+"&bgc="+ppc_background_color;
url=url+"&blockcount="+ppc_block_count;
url=url+"&titlecolor="+ppc_text_ad_title_color;
url=url+"&desccolor="+ppc_text_ad_desc_color;
url=url+"&urlcolor="+ppc_text_ad_url_color;
url=url+"&credit="+ppc_enable_credit_text;
url=url+"&credittext="+ppc_show_credit_text;
url=url+"&creditposition="+ppc_credit_align;
url=url+"&creditcolor="+ppc_credit_text_color;
url=url+"&publicads="+ppc_enable_public_ads;
url=url+"&ref="+Url.encode(ref);
//alert(url);

xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);

}




function stateChanged() 
{ 

if (xmlHttp.readyState==4)
{ 
//document.write(xmlHttp.responseText);
document.getElementById("show_PPC_Ads_"+ppc_show_ads_id).innerHTML=xmlHttp.responseText;
}
//xmlHttp.readyState=1;
//xmlHttp.onreadystatechange=0;
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

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;
}
