var Navigation={
	isIE:(navigator.appVersion.indexOf("MSIE")!=-1),
	isIE6:(navigator.appVersion.indexOf("MSIE")!=-1&&navigator.appVersion.substr(navigator.appVersion.indexOf("MSIE"),10).replace(/[^\d.]/g,"").indexOf("6.")!=-1),
	isIE7:(navigator.appVersion.indexOf("MSIE")!=-1&&navigator.appVersion.substr(navigator.appVersion.indexOf("MSIE"),10).replace(/[^\d.]/g,"").indexOf("7.")!=-1),
	isOpera:navigator.userAgent.indexOf("Opera")!=-1,
	isSafari:navigator.appVersion.indexOf("KHTML")!=-1
}
//===================================================================================================================== Prototype
String.prototype.toNum=function(){
	var n=this.match(/\d+/,"")
	if(n) return parseInt(n)
	else return 0
}
String.prototype.toDate=function(){
	var d=this.split(/\D+/)
	--d[1]
	return new Date(d[0],d[1],d[2],d[3],d[4],d[5])
}
String.prototype.toHTML=function(){
	return this.replace(/&/g,"&amp;").replace(/\</g,"&lt;").replace(/\>/g,"&gt;").replace(/"/g,"&quot;").replace(/\r\n|\r|\n/g,"<br/>").replace(/[\s\xa0]/g,"&nbsp;")
}
String.prototype.toAttribute=function(){
	return this.replace(/&/g,"&amp;").replace(/\</g,"&lt;").replace(/\>/g,"&gt;").replace(/"/g,"&quot;").replace(/\r\n|\r|\n/g,"&#13;&#10;").replace(/[\s\xa0]/g,"&nbsp;")
}
String.prototype.toURL=function(){
	return encodeURIComponent(this)
}
String.prototype.fromURL=function(){
	return decodeURIComponent(this)
}
String.prototype.toFix=function(length, esp){
	if(this.replace(/[^\x00-\xff]/g,"dd").length<=length)return this
	if(esp!="")esp=esp||"..."
	if(length<esp.length)esp=""
	length-=esp.length
	var text = this.substr(0,length)
	while(text.replace(/[^\x00-\xff]/g,"dd").length>length){
		text=text.substr(0,text.length-1)
	}
	return text+esp
}
String.prototype.toGB2312=function(){
	return $GB2312.encodeURIComponent(this)
}
Date.prototype.toString=function(){
	return String(this.getFullYear()+"-0"+(this.getMonth()+1)+"-0"+this.getDate()+" 0"+this.getHours()+":0"+this.getMinutes()+":0"+this.getSeconds()).replace(/(\D)0(\d{2})/g,"$1$2")
}
Date.prototype.addYear=function(year){
	return new Date(this.setFullYear(this.getFullYear()+parseInt(year)))
}
Date.prototype.addMonth=function(month){
	return new Date(this.setMonth(this.getMonth()+parseInt(month)))
}
Date.prototype.addDate=function(date){
	return new Date(this.setDate(this.getDate()+parseInt(date)))
}
Date.prototype.addHours=function(hour){
	return new Date(this.setHours(this.getHours()+parseInt(hour)))
}
Date.prototype.addMinutes=function(minute){
	return new Date(this.setMinutes(this.getMinutes()+parseInt(minute)))
}
Date.prototype.addSeconds=function(second){
	return new Date(this.setSeconds(this.getSeconds()+parseInt(second)))
}
//===================================================================================================================== Cookie
var Cookie={}
Cookie.set=function(key, value, expires){
	var root = ""
	var base = ""
	var newCookie=""
	if(value==undefined){
		value = ""
		expires = "1986-7-21 00:00:00"
	}
	if(key.indexOf(".")!=-1){
		var rootName=key.substr(0,key.indexOf("."))
		var subName =key.substr(key.indexOf(".")+1)
		root = Cookie.__getRecursion(document.cookie, rootName, 0)
		if(root){
			root = String(root).split("&")
			for(i=0;i <root.length; i++){
				var cName = root[i].substr(0, root[i].indexOf("="))
				var cValue = root[i].substr(root[i].indexOf("=")+1)
				if (cName != subName){
					base += cName + "=" + encodeURIComponent(cValue) + "&"
				}
			}
		}else{
			base = ""	
		}
		newCookie = rootName + "=" + base + subName + "=" + encodeURIComponent(value)
	}else{
		newCookie = key + "=" + encodeURIComponent(value)
	}
 	if(typeof expires == "string")expires=expires.toDate()
	if(expires)expires = "; expires=" + expires.toGMTString()
	else expires=""
	document.cookie = newCookie + expires + "; domain=.huodu.com; path=/"
}
Cookie.get=function(key){
	return Cookie.__getRecursion(document.cookie, key, 0)
}
Cookie.__getRecursion=function(string, key, level){ //获取Cookie递归函数
	key = key.split(".")
	if(level==0){
		string = string.split(";")
	}else{
		string = string.split("&")
	}
	for(var i=0;i<string.length;i++){
		var cName = string[i].substr(0, string[i].indexOf("=")).replace(/\s/,"")
		var cValue = string[i].substr(string[i].indexOf("=") + 1)
		if(cName == key[level]){
			if(!key[level+1]){
				return String(decodeURIComponent(cValue.replace(/\+/g," ")))
			}else{
				return Cookie.__getRecursion(cValue, key.join("."), level+1)
			}
		}
	}
	return
}
Cookie.alert=function(){alert(document.cookie)}
var Client={}
Client.isLogin=function(redirect){
	if(Cookie.get("ddLogin.id")) return true
	else{
		Cookie.set("ddLogin")
		if(redirect)window.addEventListener("load",Client.toLogin,true)
		return false
	}
}
Client.toLogin=function(){
	var form=newElement("form", {action:"/login.htm", method:"get"})
	document.body.appendChild(form)
	form.submit()
}
//===================================================================================================================== DOM
$=function(objName){
	if(typeof objName == "string") return instanceObject(document.getElementById(objName))
	else return instanceObject(document.getElementById(objName)||objName)
}
$$=function(className, parentNode){
	parentNode=parentNode||document
	var result=[]
	var element=parentNode.getElementsByTagName("*")
	for(var i=0; i<element.length; i++){
		if((" "+element[i].className+" ").indexOf(" "+className+" ")!=-1)result.push(instanceObject(element[i]))
	}
	return result
}
function newElement(tagName, attributes){
	var object=document.createElement(tagName)
	if(attributes){
		for(var i in attributes){
			object[i]=attributes[i]
			object.setAttribute(i, attributes[i])
		}
	}
	return instanceObject(object)
}
function instanceObject(){
	for(var i=0; i<arguments.length; i++){
		if(arguments[i]){
			if(!arguments[i].addEventListener)		arguments[i].addEventListener=addEvent
			if(!arguments[i].removeEventListener)	arguments[i].removeEventListener=removeEvent
			if(!arguments[i].show)					arguments[i].show=objectShow
			if(!arguments[i].hide)					arguments[i].hide=objectHide
			if(!arguments[i].getAbsPosition)		arguments[i].getAbsPosition=getAbsPosition
			if(!arguments[i].getInnerText)			arguments[i].getInnerText=getInnerText
			if(!arguments[i].hideFocus && arguments[i].tagName=="A")				arguments[i].hideFocus=true
		}
	}
	return arguments[0]
}
function getInnerText(){
	return this.innerText||this.textContent
}
function addEvent(sEvent,func){
	return this.attachEvent("on"+sEvent,func)
}
function removeEvent(sEvent, func){
	return this.detachEvent("on"+sEvent,func);
}
function objectShow(){
	this.style.display=""
}
function objectHide(){
	this.style.display="none"
}

function eventTarget(evt){ // 根据事件返回源对象
	return evt.target||evt.srcElement
}

function insertAfter(newElement,targetElement){
	var parent=targetElement.parentNode;
	if (parent.lastChild==targetElement){
		parent.appendChild(newElement);
	} else {
		parent.insertBefore(newElement,targetElement.nextSibling);
	}
}
function getAbsPosition(){
	var object=this
	var x=0, y=0
	do{
		x+=object.offsetLeft
		y+=object.offsetTop
	}while(object=object.offsetParent);
	return {x:x, y:y}
}

instanceObject(window)
instanceObject(document)
if(Navigation.isIE6)document.execCommand("BackgroundImageCache", false, true)
//==================================================================================================================== Debug
function debug(obj){
	var o=""
	for(var i in obj)o += i + "=" + obj[i] + "<br>" 
	if(!$("debugBox"))document.body.appendChild(newElement("DIV", {id:"debugBox"}))
	$("debugBox").innerHTML = o
}
function ajaxDebug(){
	var iframe=document.getElementsByTagName("IFRAME")
	for(var i=0; i<iframe.length; i++){
		iframe[i].style.display=""
	}
}
//window.addEventListener("load", function(){if($("spanCopy"))$("spanCopy").addEventListener("click",ajaxDebug,true)}, true)



function usePostProxy(action, values, charset){
	return "/postProxy.htm#"+action.toURL()+"&"+values.toURL()+(charset?("&"+charset):"")
}

