
//var url = 'http://'+location.hostname+'/adgen.php?'
// lets control the size of hte iframe
switch (adsize)
{
// cycle through ad sizes. this also serves as a reference for me to know which code matches which ad.
// ad sizes starting with 1's mean horizontal, 2-vertical, 3-square (not an exact square, but more square in size, thats all.
// this switch statement will be used in each of the CSS sections to determine the sizes and what not.
case 11:
// 728 x 90
var adwidth = 728+2;
var adheight = 90+2;
break;

case 12:
// 468 x 60
var adwidth = 468+2;
var adheight = 60+2;
break;

case 13:
// 468 x 60
var adwidth = 450+2;
var adheight = 150+2;
break;

case 21:
// 120 x 600
var adwidth = 120+2;
var adheight = 600+2;
break;

case 22:
// 160 x 600
var adwidth = 160+2;
var adheight = 600+2;
break;

case 31:
// 336 x 280
var adwidth = 336+2;
var adheight = 280+2;
break;

case 32:
// 300 x 250
var adwidth = 300+2;
var adheight = 250+2;
break;

case 33:
// 250 x 250
var adwidth = 250+2;
var adheight = 250+2;
break;

case 34:
// 200 x 200
var adwidth = 200+2;
var adheight = 200+2;
break;

case 35:
// 500 x 160
var adwidth = 500+2;
var adheight = 160+2;
break;


case 36:
// 125 x 125
var adwidth = 125+2;
var adheight = 125+2;
break;

case 41:
// 500 x 265
var adwidth = 500+2;
var adheight = 265+2;
break;

case 42:
// 450 x 225
var adwidth = 450+2;
var adheight = 225+2;
break;

case 43:
// 450 x 225
var adwidth = 500+2;
var adheight = 200+2;
break;

case 44:
// 450 x 225
var adwidth = 450+2;
var adheight = 150+2;
break;

}

var Keyword = {

	// 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;
	}

}

keyword = Keyword.encode(keyword);
fontfamily = Keyword.encode(fontfamily);

if (typeof channel == 'undefined') {
var channel='0';
}

if (typeof PID2 == 'undefined') {
var PID2='';
}

if (typeof PID3 == 'undefined') {
var PID3='';
}

if (typeof PID4 == 'undefined') {
var PID4='';
}

// part to pick the file type - whether to pick single product (adgen.php) or multi (adgenmulti.php)
if(typeof adtype != 'undefined' && adtype=='multi' && adsize<41)
{
   var is_multi=1;
}
else{
   var is_multi=0;
}

if (typeof altcontent == 'undefined') {
var altcontent='';
}

if(typeof repeat == 'undefined')
{
var repeat = 0;
}
else
{
repeat=repeat+1;
}

var rchannel=0;

if(typeof preview == 'undefined'){
   preview=0;
}


if(typeof vchannel == 'undefined')
{
var vchannel = new Array();
vchannel[repeat]=channel;
}
else
{

for (x in vchannel)
{
	if(vchannel[x]==channel)
	{
	rchannel=1;
	}
}

vchannel[repeat]=channel;
}

if(rchannel==1)
{
var view='no';
}
else
{
var view='yes';
}

if(typeof categoryid == 'undefined')
{
var categoryid = 0;
}

//var url = 'http://www.ttzmedia.com/affiliate/adgen.php?'
var url = 'http://www.ttzmedia.com/affiliate/adgen.php?'
//var url = 'http://localhost/moto/library/moto_library/'+phpfilename+'.php?'
//var url = 'http://localhost/blacktip2/affiliate/adgen.php?'
//var url = '{url:affiliate.adgen.}';
var randomnumber=Math.floor(Math.random()*11);

//alert(keyword);
document.write('<div><iframe marginheight="0" marginwidth="0" hspace="0" vspace="0" src="'+url+'keyword='+keyword+'&channel='+channel+'&is_multi='+is_multi+'&view='+view+'&PID='+PID+'&PID2='+PID2+'&PID3='+PID3+'&PID4='+PID4+'&adsize='+adsize+'&userid='+userid+'&bordercolor='+bordercolor+'&bgcolor='+bgcolor+'&darkfont='+darkfont+'&lightfont='+lightfont+'&desctext='+desctext+'&pricefont='+pricefont+'&linkcolor='+linkcolor+'&hovercolor='+hovercolor+'&fontfamily='+fontfamily+'&ttz='+ttz+'&altcontent='+altcontent+'&rand='+randomnumber+'&preview='+preview+'" frameborder="0" scrolling="No" marginheight="0" marginwidth="0" name="ttzad" style="width:'+adwidth+';height:'+adheight+';" height="'+adheight+'" width="'+adwidth+'&categoryid='+categoryid+'"></iframe></div>');
//$('ad_preview_frame_div').innerHTML = '<iframe id="ad_preview_frame" marginheight="0" marginwidth="0" hspace="0" vspace="0" src="'+url+'keyword='+keyword+'&channel='+channel+'&is_multi='+is_multi+'&view='+view+'&PID='+PID+'&PID2='+PID2+'&PID3='+PID3+'&PID4='+PID4+'&adsize='+adsize+'&userid='+userid+'&bordercolor='+bordercolor+'&bgcolor='+bgcolor+'&darkfont='+darkfont+'&lightfont='+lightfont+'&desctext='+desctext+'&pricefont='+pricefont+'&linkcolor='+linkcolor+'&hovercolor='+hovercolor+'&fontfamily='+fontfamily+'&ttz='+ttz+'&altcontent='+altcontent+'&rand='+randomnumber+'&preview=1" frameborder="0" scrolling="No" marginheight="0" marginwidth="0" name="ttzad" style="width:'+adwidth+';height:'+(adheight+18)+';" height="'+(adheight+18)+'" width="'+adwidth+'"></iframe>';
//alert(keyword);
//alert($('ad_preview_frame_div').innerHTML);