var hexmap = new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");
var ud="undefined";
var ef = false;
var alimama_dc = alimama_doc();
var alimama_iniframe = 1;
var alimama_cans=true;
var BODER_WIDTH=1;
var CPS_LR_WIDTH_A = 298;
var CPS_LR_HEIGHT_A = 103;
var CPS_LR_WIDTH_B = 202;
var CPS_LR_HEIGHT_B = 103;

var CPS_IMAGE_WIDTH = 102;
var CPS_IMAGE_HEIGHT = 103;

var CPS_UD_TITLE_HEIGHT = 42;
var CPS_UD_PRICE_HEIGHT = 24;
var CPS_UD_BUTTON_HEIGHT = 41;
var CPS_UD_IMAGE_HEIGHT = 103;
var CPS_UD_WIDTH = 190;
var CPS_UD_WIDTH2 = 102;

var CPA_MAX_ROW = 4;
var CPA_MAX_COL =3;
var CPA_MIN_ROW =1;
var CPA_MIN_COL =1;
if(typeof alimama_row == ud)
{
	alimama_row = 1;
}
if (typeof alimama_col == ud)
{
	alimama_col = 1;
}
if (alimama_row>CPA_MAX_ROW)
{
	alimama_row=CPA_MAX_ROW;
}
if (alimama_col>CPA_MAX_COL)
{
	alimama_col=CPA_MAX_COL;
}
if (alimama_row<CPA_MIN_ROW)
{
	alimama_row=CPA_MIN_ROW;
}
if (alimama_col<CPA_MIN_COL)
{
	alimama_col=CPA_MIN_COL;
}

if (typeof alimama_type == ud)
{
	alimama_cans = false;
	alimama_width=0;
	alimama_height=0;
	alimama_have_title=0;
	alimama_have_price=0;
	alimama_have_button=0;
	alimama_lr_or_ud=1;
}else if(alimama_type.length != 4)
{
	alimama_cans = false;
	alimama_width=0;
	alimama_height=0;
	alimama_have_title=0;
	alimama_have_price=0;
	alimama_have_button=0;
	alimama_lr_or_ud=1;
}else
{
	alimama_have_title = alimama_type.substring(0,1);
	alimama_have_title = (alimama_have_title=="1"?1:0);
	alimama_have_price = alimama_type.substring(1,2);
	alimama_have_price = (alimama_have_price=="1"?1:0);
	alimama_have_button = alimama_type.substring(2,3);
	alimama_have_button = (alimama_have_button=="1"?1:0);
	alimama_lr_or_ud = alimama_type.substring(3,4);
	alimama_lr_or_ud = (alimama_lr_or_ud=="1"?1:0);
	if (alimama_lr_or_ud==1)
	{
		if (alimama_have_title==1)
		{
			alimama_width = CPS_LR_WIDTH_A * alimama_col+BODER_WIDTH*2;
			alimama_height = CPS_LR_HEIGHT_A *alimama_row + BODER_WIDTH*2;
		}else if (alimama_have_price==1 || alimama_have_button==1)
		{
			alimama_width = CPS_LR_WIDTH_B * alimama_col+BODER_WIDTH*2;
			alimama_height = CPS_LR_HEIGHT_B *alimama_row + BODER_WIDTH*2;
		}else
		{
			alimama_width = CPS_IMAGE_WIDTH * alimama_col+BODER_WIDTH*2;
			alimama_height = CPS_IMAGE_HEIGHT * alimama_row +BODER_WIDTH*2;
		}	
	}else
	{
		if (alimama_have_title==1)
		{
			alimama_height  = (CPS_UD_IMAGE_HEIGHT + CPS_UD_TITLE_HEIGHT*alimama_have_title + CPS_UD_PRICE_HEIGHT*alimama_have_price +CPS_UD_BUTTON_HEIGHT* alimama_have_button)*alimama_row +BODER_WIDTH*2;
			alimama_width= CPS_UD_WIDTH * alimama_col +BODER_WIDTH*2;
		}else if(alimama_have_price==1 || alimama_have_button ==1)
		{
			alimama_height  = (CPS_UD_IMAGE_HEIGHT + CPS_UD_TITLE_HEIGHT*alimama_have_title + CPS_UD_PRICE_HEIGHT*alimama_have_price +CPS_UD_BUTTON_HEIGHT* alimama_have_button)*alimama_row +BODER_WIDTH*2;
			alimama_width= CPS_UD_WIDTH2 * alimama_col +BODER_WIDTH*2;			
		}else
		{
			alimama_width = CPS_IMAGE_WIDTH * alimama_col+BODER_WIDTH*2;
			alimama_height = CPS_IMAGE_HEIGHT * alimama_row +BODER_WIDTH*2;
		}
	}
}


function hex(a){
	if(a<256) return "%"+hexmap[a>>4]+hexmap[a&0xf];
	else return hex(a>>8)+hex(a&0xf);
}
function getx (obj){
        var curleft = 0;
       try{
        if (obj.parentNode)
        {
          while (obj.parentNode)
          {
            if (typeof obj.offsetLeft != ud)
            { 
          		curleft += obj.offsetLeft;
            }
            obj = obj.parentNode;
          }
        }
        else if (obj.x) {
          curleft += obj.x;
        }
       }catch(err)
       {
          curleft = 0;
        }
        return curleft;
}
function gety (obj){
	var curtop = 0;
    try{
        if (obj.parentNode)
        {
          while (obj.parentNode)
          {
            if (typeof obj.offsetTop != ud)
            { 
            	curtop += obj.offsetTop;
            }	
             obj = obj.parentNode;
          }
        }
        else if (obj.y){
          curtop += obj.y;
	}
     }catch(err)
     {
        curtop = 0;
     }
    return curtop;
}
function encodeUTF8(d) {
	var utft = "";var a=d.toString();
	for(var n=0; n<a.length; n++)
	{
		var c=a.charCodeAt(n);
		if(c<128){
			 if(c==46||c==40||c==41||(c>47&&c<58)||(c>64&&c<91)||(c>96&&c<123)){
				   utft += a.charAt(i);
			 }else{
				   utft += hex(c);
			 }
		}
		else if(127<c && c<0x800)
		{
			utft += hex((c>>6)|192);
			utft += hex((c&63)|128);
		} else if(0x7ff<c && c<0x10000)
		{
			utft += hex((c>>12)|224);
			utft += hex(((c>>6)&63)|128);
			utft += hex((c&63)|128);
		} else if(0xffff<c && c<0x200000)
		{
			utft += hex((c>>18)|0xf0);
			utft += hex(((c>>12)&63)|128);
			utft += hex(((c>>6)&63)|128);
			utft += hex((c&63)|128);
		} else if(0x1FFFFF<c && c<0x4000000)
		{
			utft += hex((c>>24)|0xf8);
			utft += hex(((c>>18)&63)|128);
			utft += hex(((c>>12)&63)|128);
			utft += hex(((c>>6)&63)|128);
			utft += hex((c&63)|128);
		} else if(0x3FFFFFF<c && c<0x80000000)
		{
			utft += hex((c>>30)|0xfc);
			utft += hex(((c>>24)&63)|128);
			utft += hex(((c>>18)&63)|128);
			utft += hex(((c>>12)&63)|128);
			utft += hex(((c>>6)&63)|128);
			utft += hex((c&63)|128);
		}
	}
	return utft;
}
var qv=new Array();

qv[0]="wd";
qv[1]="p";
qv[2]="q";
qv[3]="keyword";
qv[4]="kw";
qv[5]="w";
qv[6]="key";
qv[7]="word";
qv[8]="query";
qv[9]="q1";
qv[10]="name";

function alimama_b(a)
{
	if( typeof encodeURIComponent=="function" )
	{
		return encodeURIComponent(a.toString());
	} else return encodeUTF8(a.toString());
}

function meta_keywords(name)
{
	try
	{
		if(alimama_h()) return alimama_dc.getElementsByName(name)[0].getAttribute("content");
		return document.getElementsByName(name)[0].getAttribute("content");
	}
	catch(err)
	{
		return "";
	}
}

var mknames=new Array("keywords","Keywords","KEYWORDS");
function mk()
{
	var mk="";
	try 
	{
		for(var i=0;i<mknames.length;i++)
		{
			mk=meta_keywords(mknames[i]);
			if(mk!="") break;
		}
		mk=mk.replace(/[/| £¬¡¢¡¡]/g,',');
		if (mk.length>200)
		{
			var tmpstr = mk.substring(192,mk.length-1);
			var pos = tmpstr.indexOf(",");
			mk = mk.substring(0, pos+192);
		}
	}	
	catch(err)
	{
		mk="";
	}
	return mk;
}
function getSessionID(){
	cg="";
	for (var i=1;i<=32;i++)
	{
		var n=Math.floor(Math.random()*16.0).toString(16);
		cg +=n;
	}
	return cg;
}
function getBrowserInfo(){
	var cs = window.screen;
	var ct = new Date();
	rs = "&cah="+cs.availHeight;
	rs += "&caw="+cs.availWidth;
	rs += "&ccd="+cs.colorDepth;
	rs += "&ctz=" + (-ct.getTimezoneOffset()/60);
	rs += "&chl=" + history.length;
	rs += "&cbh=" + (alimama_dc.body?alimama_dc.body.clientHeight:-1);
	rs += "&cbw=" + (alimama_dc.body?alimama_dc.body.clientWidth:-1);
	if(navigator.javaEnabled()){
		rs += "&cja=1";	
	}
	if(navigator.plugins){
		rs += "&cpl="+navigator.plugins.length;
	}
	if(navigator.mimeTypes){
		rs += "&cmm="+navigator.mimeTypes.length;			
	}
	return rs;
}
function getFlashVersion(){
	var cv="-1";
	var cn=navigator;
	if(cn.plugins && cn.plugins.length){
		for(var i=0;i<cn.plugins.length;i++){
			if(cn.plugins[i].name.indexOf('Shockwave Flash')!=-1){
				cv=cn.plugins[i].description.split('Shockwave Flash ')[1];
				break;
			}
		}
	}else if(window.ActiveXObject){
		for(var i=10;i>=2;i--){
			try{
				var cf=eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash."+i+"');");
				if (cf){ 
					cv=i + '.0'; 
					break; 
				}
			}catch(e){}
		}
	}
	if(cv != "-1"){
		cv = cv.substring(0,cv.indexOf(".")+2);
	}
	return cv;	
}
function appendRandomPr(){
	var ct=0;
	var cn=16;
	var cs=0;
	for(var i=1;i<=cn;i++){
		var cx=Math.random();
		var cy=Math.random();
		if((Math.pow(cx,2)+Math.pow(cy,2))<=1){
			ct++;
		}
		if(i<=12){
			cs=cs+cx;	
		}			
	}
	var ck = 'pr'+String.fromCharCode(97+ct);
	var cv = (Math.round(cs*4973)|((alimama_dc.body?alimama_dc.body.clientWidth:0)<<16));
	return "&"+ck+"="+cv+"&cas="+ck;
}
function alimama_t()
{ 
	var alimama_t="";
	if(alimama_h())
	{
		try
		{
			alimama_t=alimama_dc.title;
		}catch(err)
		{
			alimama_t="";
		}
	} else 
	{
		alimama_t=document.title;
	}
	return alimama_t;
}
function alimama_h()
{
	try
	{
		if(alimama_iniframe==1 || alimama_iniframe=="yes")
		{
			return true;
		} else
		{
			if(document.title == "")
			{
				return true;
			} else
			{
				return false;
			}
		}
	}
	catch(err)
	{
	}
	return false;   
}
function alimama_u() 
{ 
	if(!alimama_h()) return document.location.href;

	if(ef) return alimama_dc.referrer;
	return alimama_dc.location.href;
}
function alimama_e() 
{ 
	var r="";
	if(alimama_h())
	{
		try
		{
			r=alimama_dc.referrer;
		}catch(err)
		{
			r="";
		}
	} else{
		r=document.referrer;
	}
	if(r==null)	r = "";
	return r;
}
function alimama_s(a)
{
	var r = a;
	if(r != "" && r != null)
	{
		for(var i=0; i<qv.length; i++)
		{
			var kw = new RegExp("[^1-9a-zA-Z]"+qv[i]+"=\([^&]*\)");
			var alimama_k = r.match(kw);
			if(alimama_k != null)
			{
				kw = new RegExp("^[0-9]*$");
				if(alimama_k[1].match(kw) == null)
				{
					return alimama_k[1];
				}
			}
		}
	}
	return "";  
}

function alimama_k()
{
	var alimama_k=alimama_s(alimama_u());
	if(alimama_k=="")
	{
		return alimama_s(alimama_e());
	}else
	{
		return alimama_k;
	}
}
function alimama_doc()
{
	try
	{
		var x=top.document.location;
		return top.document;
	}catch(err)
	{
		ef=true;
	}

	for(var wd=window;;)
	{
		var p = wd.parent;
		try
		{
			var x=p.document.location;
		}catch(err)
		{
			return wd.document;
		}
		wd = p;
	}
}

function alimama_p()
{
	alimama_type = alimama_have_title.toString() + alimama_have_price.toString() + alimama_have_button.toString() + alimama_lr_or_ud.toString();
	var ps = (typeof alimama_type == ud)? "":"&t="+alimama_type;
	ps += (typeof alimama_titlecolor == ud)?"":"&tc="+alimama_titlecolor;
	ps += (typeof alimama_picolor == ud)?"":"&pc="+alimama_picolor;
	ps += (typeof alimama_bgcolor == ud)?"":"&bgc="+alimama_bgcolor;
	ps += (typeof alimama_bordercolor == ud)?"":"&bdc="+alimama_bordercolor;
	ps += (typeof alimama_col == ud)?"":"&cn="+alimama_col;
	ps += (typeof alimama_row == ud)?"":"&rn="+alimama_row;
	ps += (typeof alimama_key == ud)?"":"&ky="+alimama_b(alimama_key);
	ps += (typeof alimama_uniteid  == ud)?"":"&uid="+alimama_b(alimama_uniteid);
	ps += (typeof alimama_mode == ud)?"":"&md="+alimama_b(alimama_mode);
	ps += (typeof alimama_shopcat == ud)?"":"&sc="+alimama_shopcat;
	ps += (typeof alimama_defaultid == ud)?"":"&dfid="+alimama_defaultid;
	ps += (typeof alimama_timestr == ud)?"":"&gupt="+alimama_timestr;
	return ps;
}
function cl()	
{
	alimama_pid = "";
	alimama_type = "";
	alimama_size = "";
	alimama_bgcolor = "";
	alimama_bordercolor = "";
	alimama_titlecolor = "";
	alimama_descolor = "";
	alimama_adsnum = "";
	alimama_titlebgcolor = "";
	alimama_desbgcolor = "";
	alimama_rows = "";
	alimama_cols = "";
	alimama_width = "";
	alimama_height = "";
	alimama_defaultid = "";
	alimama_shopcat = "";
	alimama_uniteid = "";
	alimama_mode = "";
	alimama_timestr = "";
}
try{
	if (typeof window.alimama_count != ud && typeof window.top.alimama_tcount !=ud )
	{
		if (window.alimama_count>=window.top.alimama_tcount)
		{
		        adc = window.alimama_count;
		}else
		{
		        adc = window.top.alimama_tcount;
		}
	}else
	{
		mrand = Math.floor(Math.random()*20)+21;
		adc =mrand;		
	}
}catch(err){
	mrand = Math.floor(Math.random()*20)+21;
	adc =mrand;
}


var alimama_tmp_label_id = "alimamatmp"+Math.random();
document.write("<label style='height:"+alimama_height+"px;width:"+alimama_width+"px;display:none;' id='"+alimama_tmp_label_id+"'></label>");
try{
	var frm_obj = document.getElementById(alimama_tmp_label_id);
	var obj2 = window;
	sx = getx(frm_obj);
	sy = gety(frm_obj);
	var i= 0;
	if (obj2.parent.window && typeof obj2.parent.window != ud)
	{

		while (obj2.location != window.top.location)
		{
		    sx += getx.call(obj2.parent,obj2.frameElement);
			sy += gety.call(obj2.parent,obj2.frameElement);
			obj2 = obj2.parent.window;
		}
	}
}catch (err)
{
	sx = 0;
    sy = 0;
}
var c = navigator.userAgent.toLowerCase();
try{
	var topurl=document.referrer;
	if(c.indexOf('firefox/ss')>-1 && topurl.indexOf('alimamapid=')){
		if (topurl.substr(topurl.indexOf("alimamapid=")+11) == alimama_pid)
		{
			isfiress = "&iss=1";
			document.write("<a name="+alimama_pid+"></a>")
		}else
		{
			isfiress = "&iss=0";
		}
	}else{ 
		isfiress = "&iss=0";
	}
}catch(err)
{
	isfiress = "&iss=0";
}
try{
	screenx = window.screen.width;
	screeny = window.screen.height;
}catch(err)
{
	screenx = 0;
	screeny = 0;
}
resolution = screenx+"x"+screeny;

adu = "http://z.alimama.com/cps.php?" + "u=" + alimama_b(alimama_u()) + isfiress+"&i=" + alimama_pid +  alimama_p() + "&k=" + alimama_k() + "&cg="+getSessionID()+"&tt=" + alimama_b(alimama_t()) + "&r=" + alimama_b(alimama_e()) +"&re="+resolution + "&sx="+  sx + "&sy=" + sy +"&ac="+ adc  + "&pf=4&cf="+getFlashVersion()+getBrowserInfo()+appendRandomPr();
if(alimama_cans)
{
	document.write("<iframe name=\"alimamafrm\" id=\"alimamafrm\" border=0 frameborder=0  marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" style='width:"+alimama_width+"px; height:"+alimama_height+"px;' src=\""+adu.substring(0, 2048)+"\"></iframe>");
}
cl();
