//@author:HuangChaoHong

//判断用户的浏览器是不是IE，是则返回true，否则返回false
var agent = navigator.userAgent;

String.prototype.trim = function()
	{
		return this.replace(/(^[\s]*)|([\s]*$)/g, "");
	};

String.prototype.inc = function(k1, k2)
	{
		return k2 == null ? this.indexOf(k1) > -1 ? true : false : (k2 + this + k2) .indexOf(k2 + k1 + k2) > -1 ? true : false;
	};

String.prototype.toArray=function(key)
	{
		var l = this, v;
		if(key == null) key = "|";
		v = key;
		if(key == "n")
		{
			l = l.replace(/\r/g,"");
			v = "\n";
		}
		l = l.replace(new RegExp("(\\"+key+")+","g"), v).replace(new RegExp("^[\\" + key + "]*|[\\" + key + "]+$","g"), "");
		return l == "" ? new Array() : l.split(v);		
	};

Array.prototype.add = function(key)
{
	this[this.length] = key;
};



var is_Opr = agent.inc("Opera");
var is_IE = agent.inc("IE") && !is_Opr;
var is_IE4 = agent.inc("IE 4");
var is_IE5 = agent.inc("IE 5") || agent.inc("IE 4");
var is_IE5_5 = agent.inc("IE 5.5");
var is_IE6 = is_IE && !is_IE5;
var is_Moz = agent.inc("Mozilla") && !is_Opr && !is_IE;

//根据ID取对象
function oo(obj)
{
	return typeof(obj) != "string" ? obj : (is_IE5 ? document.all(obj) : document.getElementById(obj));
}

//创建对象
function co(elm)
{
	return document.createElement(elm);
}

if(is_IE4)
{
	oo=function(key){return document.all[key]}
	document.getElementsByName=function(key){var a=new Array(),ol=document.all;for(i=0;i<ol.length;i++){if(ol[i].name==key)a[a.length]=ol[i];}return a;}
	document.getElementsByTagName=function(key){var a=new Array(),ol=document.all;for(i=0;i<ol.length;i++){if(ol[i].tagName.toLowerCase()==key)a[a.length]=ol[i];}return a;}
}

if(is_Moz)
{
	Event.prototype.__defineGetter__("srcElement",function(){var node=this.target;while(node.nodeType!=1){node=node.parentNode;}return node;});
	HTMLElement.prototype.__defineGetter__("children",function(){return this.childNodes});
	HTMLElement.prototype.__defineGetter__("parentElement",function(){return this.parentNode});
}

function isIE()
{	
	return is_IE;
}

//is firefox
function isFF()
{
	return is_Moz;
}


//打印
function prtf(s)
{
	document.write(s);
}

//check type for js
function isAlien(a) 
{
	return isObject(a) && typeof a.constructor != 'function';
} 
 

function isArray(a) 
{
	return isObject(a) && a.constructor == Array;
}

function isBoolean(a)
{
	return typeof a == 'boolean';
}

function isEmpty(o) 
{
	var i, v;
	if (isObject(o)) 
	{
		for(i in o) 
		{
			v = o[i];
			if (isUndefined(v) && isFunction(v)) 
			{
				return false;
			}
		}
	}
	return true;
}

function isFunction(a) 
{
	return typeof a == 'function';
}

function isNull(a) 
{
	return typeof a == 'object' && !a;
}

function isNumber(a) 
{
	return typeof a == 'number' && isFinite(a);
}

function isObject(a) 
{
	return (a && typeof a == 'object') || isFunction(a);
}

function isString(a) 
{
	return typeof a == 'string';
}

function isUndefined(a) 
{
	return typeof a == 'undefined';
}


//convert a decimal into hex digit
function enHex(aDigit)
{
    return("0123456789ABCDEF".substring(aDigit, aDigit+1));
}

//convert a hex digit into decimal
function deHex(aDigit)
{
    return("0123456789ABCDEF".indexOf(aDigit));
}

//Convert a 24bit number to hex
function toHex(n)
{
    return (((0xf00000 & n) > 0 ? enHex((0xf00000 & n) >> 20) : "") +

            ((0x0f0000 & n) > 0 ? enHex((0x0f0000 & n) >> 16) : "") + 

            ((0x00f000 & n) > 0 ? enHex((0x00f000 & n) >> 12) : "") +

            ((0x000f00 & n) > 0 ? enHex((0x000f00 & n) >>  8) : "") +

            ((0x0000f0 & n) > 0 ? enHex((0x0000f0 & n) >>  4) : "") +

            enHex((0x00000f & n) >>  0));
}

//Convert a six character hex to decimal
function toDecimal(hexNum)
{

   	var tmp = "" + hexNum.toUpperCase();

    while (tmp.length < 6) tmp = "0" + tmp;
   
   	return ((deHex(tmp.substring(0,1)) << 20) +

       	    (deHex(tmp.substring(1,2)) << 16) + 

            (deHex(tmp.substring(2,3)) << 12) +

            (deHex(tmp.substring(3,4)) << 8) +

            (deHex(tmp.substring(4,5)) << 4) +

   	        (deHex(tmp.substring(5,6))));
}

//Send the data to server 
function XmlHttpSend(url, method, params, asyn)
{
	var headers = new Array(
					new Array("Content-Type", "application/x-www-form-urlencoded"), //multipart/form-data 
					new Array("Connection", "Keep-Alive"),
					new Array("Pragma", "no-cache"),
					new Array("Cache-Control", "no-cache")
				);
				
	return XmlHttpSendEx(url, method, params, asyn, headers);

}

function XmlHttpSendExAsyn(url, method, params, parseResults)
{
	var headers = new Array(
					new Array("Content-Type", "application/x-www-form-urlencoded"), //multipart/form-data 
					new Array("Connection", "Keep-Alive"),
					new Array("Pragma", "no-cache"),
					new Array("Cache-Control", "no-cache")
				);
	var objXMLHTTP = null;
	var i, result = null;
	
	if (window.XMLHttpRequest) 
	{  
		objXMLHTTP = new XMLHttpRequest(); 
	} 
	else 
	{  
		var MSXML = new Array('MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'); 
		for(var i = 0; i < MSXML.length; i ++) 
		{  
			try 
			{  
				objXMLHTTP = new ActiveXObject(MSXML[i]); 
				break; 
			} 
			catch(e) 
			{  
			} 
		} 
	} 

	//compose the parameters	
	var strparam = null;
	if(params != null)
	{
		for(i = 0; i < params.length; i++)
		{
			var tmp = params[i];
			if(typeof(tmp) == 'object' && (tmp instanceof Array) && tmp.length >= 2)
			{
				if(strparam == null)
				{
					strparam = tmp[0] + "=" + tmp[1];
				}
				else
				{
					strparam += "&" + tmp[0] + "=" + tmp[1];
				}
			}
		}
	}	

	if(strparam != null)
	{
		if(method == "GET")
		{
			if(url.indexOf("?") == -1)
			{
				url += "?" + strparam;
			}
			else
			{
				url += "&" + strparam;
			}
		}
	}

    objXMLHTTP.open(method, url, true);
    
    objXMLHTTP.onreadystatechange=function() 
		{
			if (objXMLHTTP.readyState == 4) 
			{
				result = objXMLHTTP.responseText;
				eval(parseResults);
			}
		}
     
	if(headers != null && typeof(headers) == 'object' && (headers instanceof Array))
	{
		for(i = 0; i < headers.length; i++)
		{
			var tmp = headers[i];
			if(typeof(tmp) == 'object' && (tmp instanceof Array) && tmp.length >= 2)
			{
				objXMLHTTP.setRequestHeader(tmp[0], tmp[1]);
			}
		}
	}

	if(method == "POST")
	{
		objXMLHTTP.setRequestHeader("Content-length", strparam.length);
		objXMLHTTP.send(strparam); 
	}
	else
	{
		objXMLHTTP.send(null); 
	}
}

function XmlHttpSendEx(url, method, params, asyn, headers)
{
	var objXMLHTTP = null;
	var i, result = null, bie = true;;
	
	if (window.XMLHttpRequest) 
	{  
		bie = false;
		objXMLHTTP = new XMLHttpRequest(); 
	} 
	else 
	{  
		var MSXML = new Array('MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'); 
		for(var i = 0; i < MSXML.length; i ++) 
		{  
			try 
			{  
				objXMLHTTP = new ActiveXObject(MSXML[i]); 
				break; 
			} 
			catch(e) 
			{  
			} 
		} 
	} 

	//compose the parameters	
	var strparam = null;
	if(params != null)
	{
		for(i = 0; i < params.length; i++)
		{
			var tmp = params[i];
			if(typeof(tmp) == 'object' && (tmp instanceof Array) && tmp.length >= 2)
			{
				if(strparam == null)
				{
					strparam = tmp[0] + "=" + tmp[1];
				}
				else
				{
					strparam += "&" + tmp[0] + "=" + tmp[1];
				}
			}
		}
	}	

	if(strparam != null)
	{
		if(method == "GET")
		{
			if(url.indexOf("?") == -1)
			{
				url += "?" + strparam;
			}
			else
			{
				url += "&" + strparam;
			}
		}
	}

	objXMLHTTP.open(method, url, false);

	if(headers != null && typeof(headers) == 'object' && (headers instanceof Array))
	{
		for(i = 0; i < headers.length; i++)
		{
			var tmp = headers[i];
			if(typeof(tmp) == 'object' && (tmp instanceof Array) && tmp.length >= 2)
			{
				objXMLHTTP.setRequestHeader(tmp[0], tmp[1]);
			}
		}
	}

	if(bie)
	{
		objXMLHTTP.onreadystatechange=function() 
		{
			if (objXMLHTTP.readyState == 4) 
			{
				result = objXMLHTTP.responseText;
			}
		}
	}

	if(method == "POST")
	{
		objXMLHTTP.setRequestHeader("Content-length", strparam.length);
		objXMLHTTP.send(strparam); 
	}
	else
	{
		objXMLHTTP.send(null); 
	}

	if(!bie)
	{
		result = objXMLHTTP.responseText;
	}
	
	return result;
}


//Send form's data to server 
function postFormData(thefrm)
{
	var params = new Array();
	var j = 0;
	var result = "";
	for (var i = 0; i < thefrm.elements.length; i++) 
	{
		var e = thefrm.elements[i];
		if (e.type == 'text' || e.type == 'hidden' || e.type == 'password'||e.type =='textarea' ||e.type == 'select-one')
		{						
			params[j] = new Array(e.name, e.value);
			j++;
		}
		else if(e.type == 'checkbox' && e.checked)
		{
			params[j] = new Array(e.name, e.value);
			j++;
		}
	}

	if(j > 0)
	{
		result = XmlHttpSend(thefrm.action, thefrm.method.toUpperCase(), params, true);
	}
	return result;
}	

//Send form's data to server 
function postFormDataAsyn(thefrm, parseResults)
{
	var params = new Array();
	var j = 0;
	var result = "";
	for (var i = 0; i < thefrm.elements.length; i++) 
	{
		var e = thefrm.elements[i];
		if (e.type == 'text' || e.type == 'hidden' || e.type == 'password'||e.type =='textarea' ||e.type == 'select-one')
		{						
			params[j] = new Array(e.name, e.value);
			j++;
		}
		else if(e.type == 'checkbox' && e.checked)
		{
			params[j] = new Array(e.name, e.value);
			j++;
		}
	}

	if(j > 0)
	{
//		result = XmlHttpSend(thefrm.action, thefrm.method.toUpperCase(), params, true);
		result = XmlHttpSendExAsyn(thefrm.action, thefrm.method.toUpperCase(), params, parseResults)
	}
	return result;
}	

//Get the point of control
function getPos(el,sProp)
{
	var iPos = 0; 
    while (el != null)
　　{
		iPos += el["offset" + sProp];
		el = el.offsetParent;
	} 
    return iPos;
}  


//Show layer
//var cmlayer=null; 
//document.onclick = new Function("showLayer(null, null)");
//function showLayer(el, m)  
//{
//	if(m) 
//	{			
//		m.style.left = getPos(el,"Left");
//		m.style.top = getPos(el,"Top") + el.offsetHeight;		
//		m.style.display = ''; 
//	}  
//    if((m != cmlayer) && (cmlayer)) cmlayer.style.display = 'none'; 
//
//	cmlayer = m;   
//}  





//the succussful code
var SUCC_COMPLETE = 200;

//Get the code of result
function getResultCode(result)
{
	var p = result.indexOf(' ');
	var ret = null;
	if(p > -1)
	{
		try
		{
			ret = parseInt(result.substr(0, p));
		}
		catch(e)
		{
			ret = null;
		}
	}

	return ret;
}

//Get the error message of result
function getResultErrMsg(result)
{
	var p = result.indexOf(' ');
	var ret = null;
	if(p > -1)
	{
		j = result.toLowerCase().indexOf("\r\n", p);
		ret = result.substr(p, j - p);
	}

	return ret;
}

//Get the specail parameter's value from result
function getResultParameter(result, param)
{
	var ret = null;
	param += ":";
	var p = result.indexOf(param);
	if(p > -1)
	{
		j = result.toLowerCase().indexOf("\r\n", p);
		ret = result.substr(p + param.length, j - p - param.length);
	}
	return ret;
}
//Get the specail parameter's values from result
//return array
function getResultParameters(result, param)
{
	var ret = new Array();
	param += ":";
	var p = result.indexOf(param);
	var i = 0;
	while(p > -1)
	{
		j = result.toLowerCase().indexOf("\r\n", p);
		ret[i] = result.substr(p + param.length, j - p - param.length);

		p = result.indexOf(param, j);
	}
	return ret;
}


//Add cell for table
function addTableCell(tblid, trid, tdInner)
{
	var tbl = oo(tblid);
	var newTr;
	var newTd;
	//if(window.navigator.appName == "Microsoft Internet Explorer")			
	//{
	//	newTr = tbl.insertRow(0);
	//	newTr.id = trid;
	//	for(var i = 0; i < tdInner.length; i ++)
	//	{
	//		newTd = newTr.insertCell();
	//		newTd.innerHTML = tdInner[i];
	//	}
	//}
	//else
	{
		newTr = co("tr");
		newTr.setAttribute("id", trid);
		for(var i = 0; i < tdInner.length; i ++)
		{
			newTd = co("td");
			newTr.appendChild(newTd);
			newTd.innerHTML = tdInner[i];
		}
			
		if(isIE())	
		{
			tbl.childNodes[0].appendChild(newTr);
		}
		else
		{
			tbl.appendChild(newTr);
		}
	}
}

//Remote cell from table
function remoteTableCell(tblid, trid)
{
	var tbl = oo(tblid);
	var trc = oo(trid);
	if(tbl == null || trc == null)
	{
		return false;
	}

	try
	{
		while(trc.hasChildNodes() == true)
		{
			trc.removeChild(trc.lastChild);
		}
		tbl.childNodes[0].removeChild(trc);
	}
	catch(e)
	{
		return false;
	}
	return true;
}

//start editing
function startEditText(obj, url, field_name, sid, page)
{
	var frm = "<form method=\"post\" action=\"" + url + "\" onSubmit=\"this.theobj.disabled=true;this.thetxt.disabled=true;return true;\">\r\n"
			+ "<input type=\"hidden\" name=\"sid\" value=\"" + sid + "\">\r\n"
			+ "<input type=\"hidden\" name=\"page\" value=\"" + page + "\">\r\n"
			+ "<input type=\"hidden\" name=\"theobj\" value=\"" + obj.id + "\">\r\n"				
			+ "<input type=\"hidden\" name=\"thetxt\" value=\"" + obj.innerHTML + "\">\r\n"
			+ "<input type=\"hidden\" name=\"field_name\" value=\"" + field_name + "\">\r\n"
			+ "<input type=\"text\" name=\"" + field_name + "\" value=\"" + obj.innerHTML + "\">\r\n"
			+ "<br><input type=\"submit\" value=\"提交\" onClick=\"submitEditText(this.form)\">\r\n"
			+ "<input type=\"button\" value=\"取消\" onClick=\"cancelEditText(this.form.theobj.value, this.form.thetxt.value)\">\r\n"
			+ "</form>";
	obj.innerHTML = frm;
}

//submit editing
function submitEditText(thefrm)
{
	result = postFormData(thefrm);
	
	var new_vl = "";
	if(getResultCode(result) == SUCC_COMPLETE)
	{
		for (var i = 0; i < thefrm.elements.length; i++) 
		{
			var e = thefrm.elements[i];
			if (e.type == 'text' && e.name == thefrm.field_name.value)
			{
				new_vl = e.value;
				break;
			}
		}
		
	}
	else
	{
		alert(result);
		new_vl = thefrm.thetxt.value;
	}

	cancelEditText(thefrm.theobj.value, new_vl);
}

//cancel editing
function cancelEditText(obj, txt)
{
	var dv = oo(obj);
	dv.innerHTML = txt;
}


//check moblie 
function isMobile(str)
{
	return (new RegExp("^13(\\d{9})+$").test(str)) || (new RegExp("^159(\\d{8})+$").test(str)) || (new RegExp("^158(\\d{8})+$").test(str));
}

//check moblie 
function isEmail(str)
{
	return (new RegExp("^[\\w._]+@\\w+\.(\\w+\.){0,3}\\w{2,4}$","g").test(str.replace(/-|\//g,"")));
}

// trim string
function trim(str)
{	
	return str.trim();
}

//取原图 如834343.jpg的原图是_834343.jpg，
function get_source_img(imgfile)
{
	if(imgfile.indexOf("http://img.xiaban.com/") == 0)
	{
		pos = imgfile.lastIndexOf("/");
		if(pos != -1)
		{
			return (imgfile.substr(0, pos + 1) + "_" + imgfile.substr(pos + 1));
		}
	}
	
	return imgfile;
}

//输入转为大写
function toUpperChrEvent()
{
//	if(event.keyCode >= 97 && event.keyCode <= 122)
//	{
//		event.keyCode = (event.keyCode - 32);
//	}
//	else if(! ((window.event.keyCode >= 65 && window.event.keyCode <= 90) 
//		|| window.event.keyCode == 8
//		|| (window.event.keyCode >= 48 && window.event.keyCode <= 57)))
//	{
//		event.returnValue = false;
//	}  

	var e = window.event.srcElement;
	e.value = e.value.toUpperCase();
}


//用户添加收藏，成功返回true,失败返回false。（须指明type!)
//function collect(type, title, aim_id, parseResults)
//{
//	var params = new Array();
//	params[0] = new Array("module", "add");
//	params[1] = new Array("type", type);
//	params[2] = new Array("title", title);
//	params[3] = new Array("aim_id", aim_id);
	
//	XmlHttpSendExAsyn("/services/xr_user_favorite.phtml", "POST", params, parseResults);	
//}



//错误提示
function show_err(f_input, hint_id, msg)
{
	if(f_input != null && f_input != 'undefined')
	{
		f_input.focus();
		f_input.className = "input_js";
	}
	var obj = oo(hint_id);
	if(obj != null)
	{
		//obj.style.display="";
		obj.innerHTML = msg;
	}
}

function show_msg(hint_id, msg)
{
	show_err(null, hint_id, msg);
}

//取消错误提示
function cancel_err(f_input, hint_id)
{
	cancel_err_ext(f_input, hint_id, "input");
}

function cancel_err_ext(f_input, hint_id, use_style)
{
	if(f_input != null && f_input != 'undefined')
	{
		f_input.className = use_style; 
	}
	var obj = oo(hint_id);
	if(obj != null)
	{
		//obj.style.display="none";
		obj.innerHTML = "";
	}
}


//检查Input
function chkInput(bool, f_input, hint_id, msg)
{
	if(bool)
	{
		show_err(f_input, hint_id, msg);
		return false;
	}
	else
	{
		cancel_err(f_input, hint_id);
		return true;
	}
}

//判断一个表单的input对象有没有存在
function isInputExists(theObj)
{
	return (theObj != null && theObj != "undefined");
}

//判断一个ID对象有没有存在
function isObj(theObj)
{
	return (oo(theObj) != null);
}

function getFileExtension(filename) 
{
	if (filename == null || filename == '')
		return "";

	var ext = null;

	var dot = filename.lastIndexOf(".");

	if (dot != -1) {
		ext = filename.substring(dot + 1); // includes "."
	} else {
		ext = "";
	}

	return ext;
}

//判断是否是图片
function isPic(filename)
{
	var image_file_ext = new Array("jpg", "jpeg", "gif", "png", "bmp");

	var ext = getFileExtension(filename);

	for (var i = 0; i < image_file_ext.length; i++) 
	{
		if (image_file_ext[i] == ext.toLowerCase()) 
		{
			return true;
		}
	}
	return false;
}

//取表单指定名字的对象
function getFormElements(thefrm, thename)
{
	for(i = 0; thefrm != 'undefined' && i < thefrm.elements.length; i++)
	{
		if(thefrm.elements[i].name == thename)
		{
			return thefrm.elements[i];
		}
	}

	return null;
}


function resetImage(theimg)
{
	var vimg = new Image(); 
	vimg.src = theimg.src;

	//if(defaultw == 'undefined') defaultw = 150;

	if(vimg.width < theimg.width)
	{
		theimg.width = vimg.width;
	}


	if(vimg.height < theimg.height)
	{
		theimg.height = vimg.height;
	}
}

///显示星星
//var STAR_IMG = new Array("star_00.gif", "star_11.gif", "star_10.gif", "star_01.gif", "star_20.gif", "star_02.gif");
var STAR_IMG = new Array("star_w_1.gif", "star_w_2.gif", "star_y_1.gif", "star_y_2.gif", "star_r_1.gif", "star_r_2.gif", "star_w.gif", "star_y.gif", "star_r.gif");
var K_IMG = new Array("k_w_1.gif", "k_w_2.gif", "k_y_1.gif", "k_y_2.gif", "k_r_1.gif", "k_r_2.gif", "k_w.gif", "k_y.gif", "k_r.gif");
var STAR_HINT = new Array("很糟糕", "需要改进", "马马虎虎", "还不错", "非常满意");
function returnStar(num)
{	
	var stars = "";
	for(var i = 0; i < parseInt(num / 2); i++)
	{
		stars = stars + '<img src="/images/' + STAR_IMG[4] + '" border="0"/>';
		stars = stars + '<img src="/images/' + STAR_IMG[5] + '" border="0"/>';
	}
	if(num < 10)
	{
		if(num % 2 != 0)
		{
			stars = stars + '<img src="/images/' + STAR_IMG[4] + '" border="0"/>';
			stars = stars + '<img src="/images/' + STAR_IMG[1] + '" border="0"/>';
		}

		for(var i = parseInt(num) + parseInt(num % 2); i < 10; i+=2)
		{
			stars = stars + '<img src="/images/' + STAR_IMG[0] + '" border="0"/>';
			stars = stars + '<img src="/images/' + STAR_IMG[1] + '" border="0"/>';
		}
	}
	return stars;
}

function shwStar(num)
{	
	var stars = returnStar(num);
	prtf(stars)
}

function returnK(num)
{	
	var k="";
	var num1 = parseInt(num / 2);
	for(var i = 0; i < num1; i++)
	{
		k = k+'<img src="/images/' + K_IMG[8] + '" border="0"/>';
	}
	for(i; i < 5; i++)
	{
		k = k+'<img src="/images/' + K_IMG[6] + '" border="0"/>';
	}
	return k;
}

function shwK(num)
{	
	var k = returnK(num);
	prtf(k);
}

function shwStarHint(num)
{
	num = parseInt(num / 2);
	num = num <= 0 ? 0 : num - 1;
	return STAR_HINT[num];
}

//选择星星(用来设置分的)
//ipt 是保存的分数(input)
//shw_id 是用来显示评分评语的
function chgStar(ipt, num, shw_id)
{
	var num1 = parseInt(num / 2);
	if(num1 <= 5)
	{
		for(var i=0;i<num1;i++)
		{
			oo('star_' + i + ipt).src = '/images/' + STAR_IMG[7] ;
		}
		for(i;i<5;i++)
		{
			oo('star_' + i + ipt).src = '/images/' + STAR_IMG[6] ;
		}
  }
	oo(shw_id).innerHTML = shwStarHint(num);
}

function choStar(ipt, num, shw_id)
{
	var num1 = parseInt(num / 2);
	if(num1 <= 5)
	{
		for(var i=0;i<num1;i++)
		{
			oo('star_' + i + ipt).src = '/images/' + STAR_IMG[8] ;
		}
		for(i;i<5;i++)
		{
			oo('star_' + i + ipt).src = '/images/' + STAR_IMG[6] ;
		}
  }
	oo(ipt).value = num;
	oo(shw_id).innerHTML = shwStarHint(num);
}

function clearStar(ipt, shw_id)
{
	var num = oo(ipt).value ;
	if(num == "") num = 0;
	var num1 = parseInt(num / 2);
	if(num1 <=5)
	{
		for(var i=0;i<num1;i++)
		{
			oo('star_' + i + ipt).src = '/images/' + STAR_IMG[8] ;
		}
		for(i;i<5;i++)
		{
			oo('star_' + i + ipt).src = '/images/' + STAR_IMG[6] ;
		}
  }
	if(num == 0) oo(shw_id).innerHTML = "";
	else oo(shw_id).innerHTML = shwStarHint(num);
}

function chgK(ipt, num, shw_id)
{
	var num1 = parseInt(num / 2);
	if(num1 <= 5)
	{
		for(var i=0;i<num1;i++)
		{
			oo('k_' + i + ipt).src = '/images/' + K_IMG[7] ;
		}
		for(i;i<5;i++)
		{
			oo('k_' + i + ipt).src = '/images/' + K_IMG[6] ;
		}
  }
	oo(shw_id).innerHTML = shwStarHint(num);
}

function choK(ipt, num, shw_id)
{
	var num1 = parseInt(num / 2);
	if(num1 <= 5)
	{
		for(var i=0;i<num1;i++)
		{
			oo('k_' + i + ipt).src = '/images/' + K_IMG[8] ;
		}
		for(i;i<5;i++)
		{
			oo('k_' + i + ipt).src = '/images/' + K_IMG[6] ;
		}
  }
	oo(ipt).value = num;
	oo(shw_id).innerHTML = shwStarHint(num);
}

function clearK(ipt, shw_id)
{
	num = oo(ipt).value ;
	if(num == "") num = 0;
	var num1 = parseInt(num / 2);
	if(num1 <= 5)
	{
		for(var i=0;i<num1;i++)
		{
			oo('k_' + i + ipt).src = '/images/' + K_IMG[8] ;
		}
		for(i;i<5;i++)
		{
			oo('k_' + i + ipt).src = '/images/' + K_IMG[6] ;
		}
  }
	if(num == 0) oo(shw_id).innerHTML = "";
	else oo(shw_id).innerHTML = shwStarHint(num);
}

function initChgStar(ipt, shw_id)
{
	//if(isObject(oo(ipt)))
	  prtf('<span onMouseOut="clearStar(\'' + ipt +'\', \'' + shw_id +'\')">');
		for(var i = 0; i < 5; i++)
		{
				prtf('<img src="/images/' + STAR_IMG[6] + '"  border="0" id="star_' + i + ipt+ '" onMouseOver="chgStar(\'' + ipt +'\', ' + (i + 1)*2 + ', \'' + shw_id +'\')" align="absmiddle" style="cursor:hand" onClick="choStar(\'' + ipt +'\', ' + (i + 1)*2 + ', \'' + shw_id +'\')"/>');
		}

	prtf('</span><br>&nbsp;&nbsp;<span id="'+shw_id +'"></span>');
}

function initChgK(ipt, shw_id)
{
	//if(isObject(oo(ipt)))
	prtf('<span onMouseOut="clearK(\'' + ipt +'\', \'' + shw_id +'\')">');
	for(var i = 0; i < 5; i++)
	{

			prtf('<img src="/images/' + K_IMG[6] + '" border="0" id="k_' + i + ipt+ '" onMouseOver="chgK(\'' + ipt +'\', ' + (i + 1)*2 + ', \'' + shw_id +'\')" align="absmiddle" style="cursor:hand" onClick="choK(\'' + ipt +'\', ' + (i + 1)*2 + ', \'' + shw_id +'\')"/>');
	}
	prtf('</span><br>&nbsp;&nbsp;<span id="'+shw_id +'"></span>');
}

function returnInitChgStar(ipt, shw_id, num)
{
	stars = '<span onMouseOut="clearStar(\'' + ipt +'\', \'' + shw_id +'\')">';
	var num1 = parseInt(num / 2);
	for(var i = 0; i < num1; i++)
	{
		stars = stars + '<img src="/images/' + STAR_IMG[8] + '" border="0" id="star_' + i + ipt+ '" onMouseOver="chgStar(\'' + ipt +'\', ' + (i + 1)*2 + ', \'' + shw_id +'\')" align="absmiddle" style="cursor:hand" onClick="choStar(\'' + ipt +'\', ' + (i + 1)*2 + ', \'' + shw_id +'\')"/>';
	}
	for(i; i < 5; i++)
	{
		stars = stars + '<img src="/images/' + STAR_IMG[6] + '" border="0" id="star_' + i + ipt+ '" onMouseOver="chgStar(\'' + ipt +'\', ' + (i + 1)*2 + ', \'' + shw_id +'\')" align="absmiddle" style="cursor:hand" onClick="choStar(\'' + ipt +'\', ' + (i + 1)*2 + ', \'' + shw_id +'\')"/>';
	}
  stars += '</span>&nbsp;&nbsp;<span id="'+shw_id +'"></span>';
	return stars;
}

function returnInitChgK(ipt, shw_id, num)
{
	stars = '<span onMouseOut="clearK(\'' + ipt +'\', \'' + shw_id +'\')">';
	var num1 = parseInt(num / 2);
	for(var i = 0; i < num1; i++)
	{
		stars = stars + '<img src="/images/' + K_IMG[8] + '" border="0" id="k_' + i + ipt+ '" onMouseOver="chgK(\'' + ipt +'\', ' + (i + 1)*2 + ', \'' + shw_id +'\')" align="absmiddle" style="cursor:hand" onClick="choK(\'' + ipt +'\', ' + (i + 1)*2 + ', \'' + shw_id +'\')"/>';
	}
	for(i; i < 5; i++)
	{
		stars = stars + '<img src="/images/' + K_IMG[6] + '" border="0" id="k_' + i + ipt+ '" onMouseOver="chgK(\'' + ipt +'\', ' + (i + 1)*2 + ', \'' + shw_id +'\')" align="absmiddle" style="cursor:hand" onClick="choK(\'' + ipt +'\', ' + (i + 1)*2 + ', \'' + shw_id +'\')"/>';
	}
  stars += '</span>&nbsp;&nbsp;<span id="'+shw_id +'"></span>';
	return stars;
}

//转换十进制到二十制
function dec2bin(dec){
bin = "";
while (dec > 0) {
if (dec%2 != 0) { bin = "1" + bin; }
else { bin = "0" + bin; }
dec = parseInt(dec/2);
}

return bin;
}
//弹出页面
function opens(url, width, height)
{
	if(width == null)width = 500;
	if(height == null)height = 400;
	var gt = unescape('%3e');
	var popup = null;
	var over = "Launch Pop-up Navigator";
	popup = window.open(url, 'popupnav', 'width='+width+',height=' + height + ',top=0,left=0,scrollbars=yes');
	if (popup != null) {
	if (popup.opener == null) {
	popup.opener = self; 
	}
	popup.location.href = url;
	}
}
function set_menu(menu_sec)
{
	menu_sec = oo("menu_sec_" + menu_sec)
	if(menu_sec)
	{
		menu_sec.className = "newsearchinsider";
	}
}


function getHostDomain(host)
{
	var strroot = new Array(			 
            ".ac.cn", ".bj.cn", ".sh.cn", ".tj.cn", ".cq.cn", ".he.cn", ".sx.cn",
            ".nm.cn", ".ln.cn", ".jl.cn", ".hl.cn", ".js.cn", ".zj.cn", ".ah.cn",
            ".fj.cn", ".jx.cn", ".sd.cn", ".ha.cn", ".hb.cn", ".hn.cn", ".gd.cn",
            ".gx.cn", ".hi.cn", ".sc.cn", ".gz.cn", ".yn.cn", ".xz.cn", ".sn.cn",
            ".gs.cn", ".qh.cn", ".nx.cn", ".xj.cn", ".tw.cn", ".hk.cn", ".mo.cn",
            ".edu.au", ".gov.au", ".ac.jp", ".ad.jp", ".co.jp", ".gr.jp", ".ne.jp",
            ".or.jp", ".co.tz", ".co.za", ".ac.kr", ".co.kr", ".ac.nz", ".co.nz",
            ".edu.tw", ".co.at", ".co.az", ".co.hu", ".co.il", ".ac.uk", ".co.uk",
            ".ltd.uk", ".plc.uk", ".co.uz", ".co.vi", ".idv.tw", ".game.tw", ".ebiz.tw",
            ".club.tw", ".ac.in", ".gov.in", ".res.in", ".co.in", ".firm.in", ".gen.in", ".ind.in",
			".com", ".net", ".org", ".edu", ".name", '.cc', '.tv', '.info', ".gov.cn", ".cn", ".us"
            );
	var p = -1;
	var strdomain = '';
	for(var i = 0; i < strroot.length; i++)
	{
		p = host.lastIndexOf(strroot[i]);
		if(p == (host.length - strroot[i].length))
		{			
			strdomain = strroot[i];
			break;
		}
	}

	if(strdomain != '')
	{
		host = host.substr(0, p);
		p = host.lastIndexOf('.');

		if(p != -1)
		{
			host = host.substr(p + 1);
		}
		strdomain = host + strdomain;
	}	
	else
	{
		strdomain = host;
	}

	return strdomain;
}

function getHostName()
{
    var name,i;
    var str=location.href;
    var num=str.indexOf("://");
    str=str.substr(num+3);
    num=str.indexOf("/");
    if(num>0)
    {
        name = str.substring(0,num);
    }
    else
    {
        name = str;
    }

    return name;
}

var add_cmlayer=null; 
var add_cmlayer_allow=false; 
function add_allow_show()
{
	add_cmlayer_allow = true;
}

function add_showLayer(el, m, mname, w , h )  
{
	if(m) 
	{
		if(m.style.visibility == "visible")
		{
			m.style.visibility = "hidden";
			add_cmlayer = null;
			add_cmlayer_allow = false;
			return;
		}
		
		var l = getPos(el,"Left");
		var t = getPos(el,"Top") ;
		if(w)
		{
            l += el.offsetWidth; 
		}
		if(h)
		{
		    t += el.offsetHeight;
		}
		
		if (document.layers)
		{
			oo(mname).left = l;
			oo(mname).top = t;
		}
		else if (document.all)
		{
			oo(mname).style.left=l;
			oo(mname).style.top=t;
		}
		else if (document.getElementById)
		{
			document.getElementById(mname).style.left=l + "px";
			document.getElementById(mname).style.top=t + "px";
		}
		m.style.visibility = "visible";
		add_allow_show();
	}
	
	if(add_cmlayer) 
	{
		if(! add_cmlayer_allow) return;
		add_cmlayer.style.visibility = "hidden"; 			
		add_cmlayer_allow = false;
	}

	add_cmlayer = m;
}

function substr(str, len) 
{
     if(!str || !len) { return ''; }      //预期计数：中文2字节，英文1字节     
     var a = 0;      //循环计数     
     var i = 0;      //临时字串     
     var temp = '';      
     for (i=0;i<str.length;i++)     
     {
     	if (str.charCodeAt(i)>255)          
     	{             
     		//按照预期计数增加2             
     		a+=2;         
     	}         
     	else        
     	{             
     		a++;         
     	}         
     	//如果增加计数后长度大于限定长度，就直接返回临时字符串         
     	if(a > len) { return temp+'..'; }          
     	//将当前内容加到临时字符串         
     	temp += str.charAt(i);     
     }
     
 	 //如果全部是单字节字符，就直接返回源字符串     
 	 return str; 
} 

var cc_cur 	= false;
var cc_isload = false;
var cc_fcs = new Array();
var cc_citys = new Array();
var cc_cur_host = "";
function cc()
{
	if(oo("changecity_opt").style.display == "")
	{
		oo("changecity_opt").style.display = "none";
		return;
	}
	else
	{
		oo("changecity_opt").style.display = "";
	}
}
function cc_p()
{
	if(!cc_cur_host && !cc_cur)
	{
		alert("请选择城市");return ;
	}
	if(cc_cur_host)
	{
		oo('cc_host').value = cc_cur_host;
	}
	else
	{
		oo('cc_host').value = cc_citys[cc_cur[0]][cc_cur[1]][1];
	}
	document.frm_cc.submit();
}
function ccParseResults(result)
{
	
	if(getResultCode(result) == SUCC_COMPLETE)
	{
		var resstr = getResultParameter(result, "resstr");
	
//		alert(resstr);
		var fccitys = resstr.split("<e>");
		var fc, fccity;
		var citys = new Array();
		
		for (var i = 0; i < fccitys.length; i++) 
		{
			if(fccitys[i])
			{
				fc = fccitys[i].substr(0, 1);
				cc_fcs[i] = fc;
				cc_citys[i] = new Array();
				fccity = fccitys[i].substr(2);
				citys = fccity.split("<c>");	
				var k = 0;			
				for (var j = 0; j < citys.length; j++)
				{
					if(citys[j])
					{
						cc_citys[i][k++] = citys[j].split(",");
					}
				}
			}
		}
		var str_fc = "城市拼音首字母<br/>";
		for (var i = 0; i < cc_fcs.length; i++) 
		{
			str_fc += "<a href=\"javascript:cc_show(" + i + ");\">" + cc_fcs[i] + "</a> ";
		}
		
		oo("cc_fc").innerHTML = str_fc;
		oo("cc_title").innerHTML = "选择你想去的城市";
		
		oo("cc_more").style.display = "";
		
		cc_isload = true;
	}
	else
	{
		oo("cc_title").innerHTML = "城市加载错误";
		return;
	}
}
function cc_more()
{
	if(cc_isload)return;
	
	var params = new Array();
	params[0] = new Array("module", "getcitys");
	params[1] = new Array("c", 0);

	oo("cc_title").innerHTML = "正在加载更多城市...";
	XmlHttpSendExAsyn("/services/xr_zone.phtml", "GET", params, "ccParseResults(result)");
}
function cc_hot(host)
{
	if(cc_cur)
	{
		oo("cc_" + cc_cur[0] + "_" + cc_cur[1]).className = "city_td1";
		cc_cur = false;
	}
	if(cc_cur_host)
	{
		oo("cc_span_" + cc_cur_host).className = "city_td1";
	}
	cc_cur_host = host;
	oo("cc_span_" + cc_cur_host).className = "city_td2";
}
function cc_sc()
{
//	if(!cc_cur)return;
//	oo("cc_" + cc_cur[0] + "_" + cc_cur[1]).className = "";
}
function cc_mouseout(idx, i)
{
	
	if(cc_cur && cc_cur[0] == idx && cc_cur[1] == i)
	{
		oo("cc_" + idx + "_" + i).className = "city_td2";
	}
	else
	{
		oo("cc_" + idx + "_" + i).className = "city_td1";
	}
}
function cc_onclick(idx, i)
{
	if(cc_cur)
	{
		oo("cc_" + cc_cur[0] + "_" + cc_cur[1]).className = "city_td1";
	}
	cc_cur = new Array(idx ,i);
	if(cc_cur_host)
	{
		oo("cc_span_" + cc_cur_host).className = "city_td1";
		cc_cur_host = "";
	}
}
function cc_show(idx)
{	
	cc_cur 	= false;
	
	var citys = cc_citys[idx];
	if(!isArray(citys))return;
	var str_citys = '<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ECECEC" onmouseout="cc_sc()">';
	for (var i = 0; i < citys.length; i++) 
	{
		if(i%5 == 0)
		{
			if(i > 0)str_citys += '</tr>';
			str_citys += '<tr>';
		}
		str_citys += '<td id="cc_' + idx + '_' + i + '" class="city_td1" onClick="cc_onclick(' + idx + ',' + i + ')" onmouseover="this.className=\'city_td2\';" onmouseout="cc_mouseout(' + idx + ',' + i + ');">'+ citys[i][2] + '</td>';
	}
	var k = (i-1)%5;
	if(k != 4)
	{
		k = 4 - k;
		for (var i = 0; i < k; i++) 
		{
			str_citys += '<td class="city_td1"></td>';
		}
	}
	
	str_citys += '</tr></table>';
	oo("cc_city").innerHTML = str_citys;	
}

//跨浏览器的XML DOM对象解决方案
function XmlDom() {
    //通过对象/属性检测法，判断是IE来是Mozilla
    if (window.ActiveXObject) {
        var arrSignatures = ["MSXML2.DOMDocument.5.0", "MSXML2.DOMDocument.4.0",
                             "MSXML2.DOMDocument.3.0", "MSXML2.DOMDocument",
                             "Microsoft.XmlDom"];
                         
        for (var i=0; i < arrSignatures.length; i++) {
            try {
        
                var oXmlDom = new ActiveXObject(arrSignatures[i]);
            
                return oXmlDom;
        
            } catch (oError) {
                //ignore
            }
        }          

        throw new Error("MSXML is not installed on your system."); 
                    
    } else if (document.implementation && document.implementation.createDocument) {
        
        var oXmlDom = document.implementation.createDocument("","",null);

        //创建Mozilla版本的parseError对象
        oXmlDom.parseError = {
            valueOf: function () { return this.errorCode; },
            toString: function () { return this.errorCode.toString() }
        };
        
        //初始化parseError对象
        oXmlDom.__initError__();
                
        
        oXmlDom.addEventListener("load", function () {
            this.__checkForErrors__();
            this.__changeReadyState__(4);
        }, false);

        return oXmlDom;        
        
    } else {
        throw new Error("Your browser doesn't support an XML DOM object.");
    }
}

//如果是Mozilla
if (isFF()) {

    Document.prototype.readyState = 0;
    Document.prototype.onreadystatechange = null;

    
    Document.prototype.__changeReadyState__ = function (iReadyState) {
        this.readyState = iReadyState;

        if (typeof this.onreadystatechange == "function") {
            this.onreadystatechange();
        }
    };
    //初始化parseError对象
    Document.prototype.__initError__ = function () {
        this.parseError.errorCode = 0;
        this.parseError.filepos = -1;
        this.parseError.line = -1;
        this.parseError.linepos = -1;
        this.parseError.reason = null;
        this.parseError.srcText = null;
        this.parseError.url = null;
    };
    
    Document.prototype.__checkForErrors__ = function () {

        if (this.documentElement.tagName == "parsererror") {

            var reError = />([\s\S]*?)Location:([\s\S]*?)Line Number (\d+), Column (\d+):<sourcetext>([\s\S]*?)(?:\-*\^)/;

            reError.test(this.xml);
            
            this.parseError.errorCode = -999999;
            this.parseError.reason = RegExp.$1;
            this.parseError.url = RegExp.$2;
            this.parseError.line = parseInt(RegExp.$3);
            this.parseError.linepos = parseInt(RegExp.$4);
            this.parseError.srcText = RegExp.$5;
        }
    };
    
     //定义Mozilla的loadXML方法   
    Document.prototype.loadXML = function (sXml) {
    
        this.__initError__();
    
        this.__changeReadyState__(1);
    
        var oParser = new DOMParser();
        var oXmlDom = oParser.parseFromString(sXml, "text/xml");
 
        while (this.firstChild) {
            this.removeChild(this.firstChild);
        }

        for (var i=0; i < oXmlDom.childNodes.length; i++) {
            var oNewNode = this.importNode(oXmlDom.childNodes[i], true);
            this.appendChild(oNewNode);
        }
        
        //载入后检查错误
        this.__checkForErrors__();
        
        //没有问题，设置readyState属性为4
        this.__changeReadyState__(4);

    };
    
    Document.prototype.__load__ = Document.prototype.load;

    Document.prototype.load = function (sURL) {
        this.__initError__();
        this.__changeReadyState__(1);
        this.__load__(sURL);
    };
    
    Node.prototype.__defineGetter__("xml", function () {
        var oSerializer = new XMLSerializer();
        return oSerializer.serializeToString(this, "text/xml");
    });

}