/**
* 主js文件
*/

smartclick_Cookie = {

	get: function(name) {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = smartclick_Cookie.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
	},
	set: function(key, value, ttl, path, domain, secure) {
		cookie = [key+'='+    encodeURIComponent(value),
		 		  'path='+    ((!path   || path=='')  ? '/' : path),
		 		  'domain='+  ((!domain || domain=='')?  window.location.hostname : domain)];
		
		if (ttl)         cookie.push( 'expires='+smartclick_Cookie.hoursToExpireDate(ttl));
		if (secure)      cookie.push('secure');
        
		return document.cookie = cookie.join('; ');
	},

	//@param integer	ttl		Time To Live (hours)
	hoursToExpireDate: function(ttl) {
		if (parseInt(ttl) == 'NaN' ) return '';
		else {
			now = new Date();
			now.setTime(now.getTime() + (parseInt(ttl) * 60 * 60 * 1000));
			return now.toGMTString();
		}
	},
    trim: function( text ) {
		return (text || "").replace( /^\s+|\s+$/g, "" );
	}
}
//uuid
function smartclick_randomUUID() {
  var s = [], itoh = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'];
  for (var i = 0; i < 32; i++){s[i] = Math.floor(Math.random()*0x10);}
  s[14] = 4;
  s[19] = (s[19] & 0x3) | 0x8;
    
  // Convert to hex chars
  for (var i = 0; i < 32; i++){
    s[i] = itoh[s[i]];
  }
  // Insert '.'s
  //s[8] = s[13] = s[18] = s[23] = '.';
  return s.join('');
};
//set uuid
if( smartclick_Cookie.get('smartclick_uuid') == null || smartclick_Cookie.get('smartclick_uuid').length != 32 )
{
    var smartclick_uuid = smartclick_randomUUID();
    smartclick_Cookie.set('smartclick_uuid', smartclick_uuid, 240000, '/');
}else{
    var smartclick_uuid = smartclick_Cookie.get('smartclick_uuid');
}

//set history urls
var smartclick_historyurls = smartclick_Cookie.get('smartclick_historyurls') || "";
//string to list
var smartclick_historyurls_sets = smartclick_historyurls.split(';');
//
for( var i in smartclick_historyurls_sets )
{
    if( smartclick_historyurls_sets[i] == (window.location.href || "") )
    {
        //delete the same vaule element
        smartclick_historyurls_sets.splice(i,1);
    }
}
//unshift new location.href
smartclick_historyurls_sets.unshift( window.location.href || "" );
while( smartclick_historyurls_sets.length >= 4)
{//keep num <= 3
    smartclick_historyurls_sets.pop();
}
//set into cookie
smartclick_Cookie.set('smartclick_historyurls', smartclick_historyurls_sets.join(';'), 240000, '/');


try{

/* 设置默认值 */
/* 宽度 */
if(!window.smartclick_width) { var smartclick_width = 728; }
/* 高度 */
if(!window.smartclick_height) { var smartclick_height = 90; }
/* 是否显示边框 */
if(!window.smartclick_border) { var smartclick_border = 'show'; }
/* 是否显示图片 */
if(!window.smartclick_product_images) { var smartclick_product_images = 'show'; }
/* 默认颜色 */
if(!window.smartclick_color_border) { var smartclick_color_border = '000000'; }
if(!window.smartclick_color_background) { var smartclick_color_background = 'FFFFFF'; }
if(!window.smartclick_color_text) { var smartclick_color_text = '000000'; }
if(!window.smartclick_color_link) { var smartclick_color_link = '3399FF'; }
if(!window.smartclick_color_price) { var smartclick_color_price = '990000'; }

/* from id */
if(!window.smartclick_from_id) { var smartclick_from_id = ''; }

/* host type */
if(!window.smartclick_host_type) { var smartclick_host_type = ''; }

/* smartclick_test_url */
if(!window.smartclick_test_url) { var smartclick_test_url = ''; }

/* smartclick_from_id */
if(!window.smartclick_from_id) { var smartclick_from_id = ''; }

/* smartclick_user_check */
if(!window.smartclick_user_check) { var smartclick_user_check = ''; }

/* smartclick_ad_lianmeng */
if(!window.smartclick_ad_lianmeng) { var smartclick_ad_lianmeng = ''; }
/* smartclick_ad_owner */
if(!window.smartclick_ad_owner) { var smartclick_ad_owner = ''; }

/* 广告框架类 */
var sk_iframe = {
	/* 高度 */
	height : (smartclick_height + 'px'),
	/* 宽度 */
	width : (smartclick_width + 'px'),
	/* src class */
	src : {
		/* 传递到ad_iframe.php的变量options */
		o : {
			/* 尺寸ID */
			/*
			p: (function(w, h)	{
				var p={'120x240':1, '120x600':2, '160x600':3, '180x150':4, '300x250':5, '468x60':6, '728x90':7, '600x520':8, '685x232':9};
				return p[w + "x" + h];
			})(smartclick_width, smartclick_height) ,
			*/
			width : smartclick_width,
			height : smartclick_height,
			img : smartclick_product_images ,/* 是否显示产品图片 */
			border : smartclick_border,
			c_border : smartclick_color_border,/* 边框色 */
			c_bg : smartclick_color_background,/* 背景色 */
			c_text : smartclick_color_text,/* 文字色 */
			c_link : smartclick_color_link,/* 链接色 */
			c_price : smartclick_color_price,/* 价格色 */
			from_id : smartclick_from_id, /* 网站标识 */
			hosttype : smartclick_host_type, /* 网站类型,discuz,phpbb... */
            
            uuid: (smartclick_uuid || ""), // UUID
            history_urls: (smartclick_historyurls_sets.join(';') || ""), // 历史浏览URL
			
			/* 当前页面的url */
			url : (function() {
				if( smartclick_test_url && smartclick_test_url != '') return smartclick_test_url;
				if(document.location){
					return document.location;
				}else{
					return window.parent.document.location;
				}
				return '';
			})(),
			referrer : (function(){
				if( window.parent.document.referrer )
					return window.parent.document.referrer;
				else
					return '';
			})(),
			user : smartclick_user_check,/* 用户的字符串 */
			lmid : smartclick_ad_lianmeng, /* 联盟号+ID */
			owner : smartclick_ad_owner /* 广告厂商 */
		},
		/* 取得url值 */
		getsrc : function() {
			var name, v=[];
			var IFRAME_URL = 'http://page.adsmartclick.com/ad_iframe.php?';
			for( name in this.o ) {
				v.push( encodeURIComponent(name) + '=' + encodeURIComponent(this.o[name]) );
			}
			return IFRAME_URL + v.join("&").replace(/%20/g, "+");
		}
	}
};

document.write( '<iframe src="'+sk_iframe.src.getsrc()+'" width="'+sk_iframe.width+'" height="'+sk_iframe.height+'" border="0" frameborder="0" style="border:0px;margin:0px;padding:0px;" scrolling="no"></iframe>');

}catch(e){}