// Copyright Ma Bingyao <andot@ujn.edu.cn>  http://www.coolcode.cn/?p=126###pp=2
if (typeof(encodeURIComponent) == "undefined")
	window.encodeURIComponent = function(str) {
		var l = ['%00', '%01', '%02', '%03', '%04', '%05', '%06',
				 '%07', '%08', '%09', '%0A', '%0B', '%0C', '%0D',
				 '%0E', '%0F', '%10', '%11', '%12', '%13', '%14',
				 '%15', '%16', '%17', '%18', '%19', '%1A', '%1B',
				 '%1C', '%1D', '%1E', '%1F', '%20', '!', '%22',
				 '%23', '%24', '%25', '%26', "'", '(', ')', '*', '%2B', '%2C',
				 '-', '.', '%2F', '0', '1', '2', '3', '4', '5', '6',
				 '7', '8', '9', '%3A', '%3B', '%3C', '%3D', '%3E', '%3F',
				 '%40', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
				 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
				 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '%5B', '%5C',
				 '%5D', '%5E', '_', '%60', 'a', 'b', 'c', 'd', 'e',
				 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
				 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
				 'z', '%7B', '%7C', '%7D', '~', '%7F'];
		var out, i, len, c;

		out = [];
		len = str.length;
		for(i = 0; i < len; i++) {
			c = str.charCodeAt(i);
			if (c <= 0x007F) {
				out[out.length] = l[c];
			}
			else if (c > 0x07FF) {
				out[out.length] = '%' + (0xE0 | ((c >> 12) & 0x0F)).toString(16).toUpperCase();
				out[out.length] = '%' + (0x80 | ((c >>  6) & 0x3F)).toString(16).toUpperCase();
				out[out.length] = '%' + (0x80 | ((c >>  0) & 0x3F)).toString(16).toUpperCase();
			}
			else {
				out[out.length] = '%' + (0xC0 | ((c >>  6) & 0x1F)).toString(16).toUpperCase();
				out[out.length] = '%' + (0x80 | ((c >>  0) & 0x3F)).toString(16).toUpperCase();
			}
		}
		return out.join('');
	}


var CM8Agent= navigator.userAgent.toLowerCase();
var CM8IsIE= (navigator.appVersion.toLowerCase().indexOf('msie') != -1);
var CM8IsNav=
	((CM8Agent.indexOf('mozilla') != -1) &&
	(CM8Agent.indexOf('spoofer') == -1) &&
	(CM8Agent.indexOf('compatible') == -1) &&
	(CM8Agent.indexOf('opera') == -1) &&
	(CM8Agent.indexOf('webtv') == -1));

function CM8GetTime()
{
   	var theDate = new Date();
	var YYYY = new String(theDate.getYear());
	for(i=4-YYYY.length;i>0;i--)
		YYYY = "0" + YYYY;
	var MM = new String(theDate.getMonth()+1);
	if (MM < 1 || MM > 12)
		MM = 1;
	if (MM.length < 2)
		MM = "0" + MM;
	var DD = new String(theDate.getDate());
	if (DD < 1 || DD > 31)
		DD = 1;
	if (DD.length < 2)
		DD = "0" + DD;
	var HH = new String(theDate.getHours());
	if (HH < 0 || HH > 24)
		HH = 1;
	if (HH.length < 2)
		HH = "0" + HH;
    return "DATE=" + YYYY + MM + DD + "&HOUR=" + HH;
}

function CM8IsFrames()
{
	return (CM8Agent.indexOf("win") != -1) &&
	       window.parent &&
	       window.parent.frames &&
	       (window.parent.frames.length >= 2) &&
	       (typeof(window.parent.document) != 'unknown') &&
	       (typeof(window.parent.document.body.clientWidth) != 'undefined');
}

function CM8GetSize()
{
	var width  = 1024;
	var height = 768;
	if (CM8IsIE) {
		if (typeof(window.document.body.clientWidth) != 'undefined') {
			width  = window.document.body.clientWidth;
			height = window.document.body.clientHeight;
		}
		if (CM8IsFrames()) {
			width  = window.parent.document.body.clientWidth;
			height = window.parent.document.body.clientHeight;
		}
	}
	else if (CM8IsNav&& (typeof(window.innerWidth) != 'undefined')) {
		width  = window.innerWidth;
		height = window.innerHeight;
	}

	var width_group;
	if (width > 1200)
		width_group = "WR_E";
	else if (width > 1000)
		width_group = "WR_D";
	else if (width > 800)
		width_group = "WR_C";
	else if (width > 600)
		width_group = "WR_B";
	else
		width_group = "WR_A";

	return "WIDTH=" + width + "&HEIGHT=" + height + "&WIDTH_RANGE=" + width_group;
}

function CM8ConvertChar(source,charX)
{
	var d1=(charX.charCodeAt(0)/16)%16;
	var d2=charX.charCodeAt(0)%16
	var to="%"+
		String.fromCharCode((d1<10)?("0".charCodeAt(0)+d1):("a".charCodeAt(0)+d1-10))+
		String.fromCharCode((d2<10)?("0".charCodeAt(0)+d2):("a".charCodeAt(0)+d2-10));
	while (source.indexOf(charX)!=-1)
		source=source.slice(0,source.indexOf(charX))+to+source.slice(source.indexOf(charX)+1);
	return source;
}

function CM8GetLocation()
{
	var encoded = [];
	var loc = document.location.href;
	if (loc == "") loc="???";
	for (var i = 0; i < loc.length; i++) {
		var code = loc.charCodeAt(i);
		if ((code >= 128) || (code <= 32))
			encoded.push(encodeURIComponent(loc.substr(i, 1)));
		else if (code == 92)  // \
			encoded.push("\\\\");
		else if (code == 63)  // ?
			encoded.push("\\q");
		else if (code == 38)  // &
			encoded.push("\\a");
		else if (code == 37)  // %
			encoded.push("\\p");
		else
			encoded.push(loc.substr(i, 1));
	}
	return encoded.join("");
}

function CM8EncodeProfile(profile)
{
	var attrs = profile.split("&");
	for (var i = 0; i < attrs.length; i++) {
		var pair = attrs[i].split("=", 2);
		if (pair.length > 0) {
			var attr = pair[0];
			if (attr.toLowerCase().indexOf("encoded:") == 0)
{
	attr = attr.substring(8);
}
else
{
	attr = encodeURIComponent(attr);
}
			pair[0] = attr;
			var value = pair[1];
			if (value.toLowerCase().indexOf("encoded:") == 0)
{
	value = value.substring(8);
}
else
{
	value = encodeURIComponent(value);
}
			pair[1] = value.replace(/%2C/g, ",");
		}
		attrs[i] = pair.join("=");
	}
	return attrs.join("&");
}

if ((typeof(CM8Profile) == "undefined") || (CM8Profile== ""))
	var CM8Profile= "";
else
	CM8Profile= CM8EncodeProfile(CM8Profile) + "&";

CM8Profile+=
	"LOC=" + CM8GetLocation().substr(0,1000) + "&" +
	CM8GetSize() + "&" + 
	CM8GetTime() +
	"&ORD=" + String(Math.random()).slice(2);

if (CM8Cat.toLowerCase().indexOf("encoded:") == 0)
{
	CM8Cat = CM8Cat.substring(8);
}
else
{
	CM8Cat = encodeURIComponent(CM8Cat);
}

// Copyright Ma Bingyao <andot@ujn.edu.cn>  http://www.coolcode.cn/?p=126###pp=2
if (typeof(decodeURIComponent) == "undefined")
	window.decodeURIComponent = function(str) {
		function checkcode() { 
			var d1, d2; 
			d1 = str.charAt(i++); 
			d2 = str.charAt(i++); 
			if (isNaN(parseInt(d1, 16)) || isNaN(parseInt(d2, 16)))
				return null;
			return parseInt(d1 + d2, 16); 
		} 
		function checkutf8() { 
			var c = str.charCodeAt(i++); 
			if (c == 37) {
				if ((c = checkcode()) == null) return null; 
			} 
			if ((c >> 6) != 2)
				return null;
			return c;
		} 
		var out, i, len; 
		var c, c2, c3; 
  
		out = []; 
		len = str.length; 
		i = 0; 
		while(i < len) { 
			c = str.charCodeAt(i++); 
			if (c == 37) { 
				if ((c = checkcode()) == null) return ""; 
			} 
			else { 
				out[out.length] = String.fromCharCode(c); 
				continue; 
			} 
			switch(c >> 4) { 
				case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: { 
					// 0xxxxxxx 
					out[out.length] = String.fromCharCode(c); 
					break; 
				} 
				case 12: case 13: { 
					// 110x xxxx   10xx xxxx 
					if ((c2 = checkutf8()) == null) return ""; 
					out[out.length] = String.fromCharCode(((c & 0x1F) << 6) | (c2 & 0x3F)); 
					break; 
				} 
				case 14: { 
					// 1110 xxxx  10xx xxxx  10xx xxxx 
					if ((c2 = checkutf8()) == null) return ""; 
					if ((c3 = checkutf8()) == null) return ""; 
					out[out.length] = String.fromCharCode(((c & 0x0F) << 12) | 
						((c2 & 0x3F) << 6) | ((c3 & 0x3F) << 0)); 
					break; 
				} 
				default: { 
					return ""; 
				} 
			} 
		} 
		return out.join(''); 
	}


if ((typeof(CM8RichMedia) != "undefined") &&
    ((CM8RichMedia.toString().toLowerCase() == "no") ||
	 (CM8RichMedia.toString().toLowerCase() == "false")))
	CM8RichMedia = "";
else
	CM8RichMedia = "r";

var CM8ShowAd = function(F, I)
{
	if (F.toLowerCase().indexOf("encoded:") == 0)
{
	F = F.substring(8);
}
else
{
	F = encodeURIComponent(F);
}
	F = decodeURIComponent(F);
	if (document.getElementById('CM8_FORMAT_' + F) == null)
		document.write('<DIV ID="CM8_FORMAT_' + F + '" STYLE="display:inline"></DIV>');
	if (typeof(CM8MultiShow) != "undefined")
		CM8MultiShow(F, I);
};

var CM8DetectUrl = ((document.location.protocol=="https:")?"https:":"http:") +
	"//" + CM8Server + "/adam/detect?" +
	"req=f" + CM8RichMedia +
	"&cat=" + CM8Cat + "&" + CM8Profile;
document.write("<SCR" + "IPT LANGUAGE='JAVASCRIPT' SRC='" + CM8DetectUrl + "'></SCR" + "IPT>"); 

