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());
}



function showContentAds(metainfo)
{
	var cont='';
	desc = ""; 
	keyword = ""; 
	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=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;
		}
	}
	
	var url=show_ads_url;
	url=url+"?id="+show_ads_id;	
	url=url+"&ht="+iframe_height;	
	url=url+"&blockcount="+block_count;
	url=url+"&content_type="+cont;
	url=url+"&search="+Url.encode(keyword).slice(0,200);
	url=url+"&title="+Url.encode(title).slice(0,50);
	url=url+"&desc="+Url.encode(desc).slice(0,100);
	url=url+"&ref="+Url.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];
					}
			 }
		}
	}

	var url=show_ads_url;
	url=url+"?id="+show_ads_id;	
	url=url+"&ht="+iframe_height;	
	url=url+"&blockcount="+block_count;
	url=url+"&content_type="+cont;
	url=url+"&search="+Url.encode(keyword);
	url=url+"&ref="+Url.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;
}


