﻿/*
*	VeryIDE 系统运行基础：VeryIDE_Function.js
*	VeryIDE Framework
*	程序作者：磊磊 ( Leilei E-mail:VeryIDE@Gmail.Com )
*	当前版本：v1.0 ( 基础版本 )
*/

if(navigator.appName.indexOf("Microsoft")!=-1){
	ie=true;
}else{
	ie=false;
}
function $(obj){return document.getElementById(obj)}
function $$(obj){return document.getElementsByName(obj)}
function $$$(obj){return document.getElementsByTagName(obj)}

function ThisHref(obj){this.blur();obj.href="javascript:void(0);"}

function LoadJS(Src,Target){
	if(Target=='HEAD'){
		var Obj = $$$('HEAD').item(0);
	}else{
		var Obj = $(Target);
	}
	var script = document.createElement('SCRIPT');
	script.src = Src;
	script.type = "text/javascript";
	Obj.appendChild(script);
}

function LoadFunction(Fun,Time,Load){
	if(Load){
		var id="load_"+Math.random()*10
		document.write("<p id='"+id+"' align='center'><img src='../../images/animated_loading.gif' /></p>")
		window.setTimeout("deleteElement('"+id+"');",Time);
	}
	window.setTimeout(Fun,Time);
}

function getPlace(obj){	//获取对象绝对位置
	if(typeof(obj)!="object"){var obj=$(obj);}
	this.width=obj.offsetWidth; 
	this.height=obj.offsetHeight;  
	this.top=obj.offsetTop;  
	this.left=obj.offsetLeft;  
	while(obj=obj.offsetParent){  
		this.top+=obj.offsetTop;  
		this.left+=obj.offsetLeft;
	}
}

function deleteElement(id){	//删除对象
	var P=$(id).parentNode;
	P.removeChild($(id));
}

function getSelect(obj){
	var objName=$(obj);
	this.value="";
	this.text="";
	this.index="";
	if(objName.length>0){
		this.value=objName[objName.selectedIndex].value;
		this.text=objName[objName.selectedIndex].text;
		this.index=objName.selectedIndex;
	}
}

function getRadio(obj){
	var obj=$$(obj);
	this.value="";
	for(var i=0;i<obj.length;i++){
		if(obj[i].checked==true){
			this.value=obj[i].value;
			break;
		}
	}
}

function GetHref(obj,Info){
	if(obj.title==""){obj.title=obj.href;};
	if(!confirm(Info)){obj.href="javascript:void(0);"}else{obj.href=obj.title;}
}

function ShowHidden(obj){
	var obj=$(obj);
	if(obj){
		if(obj.offsetHeight==0||obj.style.display== "none") {obj.style.display = "block";}else{obj.style.display = "none";}
	}
}

function _blank() {
	var anchors = document.getElementsByTagName("A");
	var s=0
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "_blank"){
			anchor.target = "_blank";
		}
	}
}

function getLocal(){
	if(!ie){LocalLanguage=navigator.language;}else{LocalLanguage=navigator.browserLanguage;}
	return LocalLanguage.toLowerCase();
}

function setCheckBox(obj,v){
	var obj=$$(obj);
	if(obj[0]){
		for(var i=0;i<obj.length;i++){
			if(obj[i].value==v){
				obj[i].checked=true;
			}
		}
	}else{
		obj=$(obj);
		if(obj.value==v){
			obj.checked=true;
		}
	}
}

function setSelect(obj,v){		//通过值选择列表项
	var obj=$(obj);
	for(var i=0;i<obj.length;i++){
		if(obj[i].value == v){
			obj.selectedIndex=i;
			break;
		}
	}
}

function setRadio(o,v){		//通过值选择单选项
	var obj=$$(o);
	for(var i=0;i<obj.length;i++){
		if(obj[i].value == v){
			obj[i].checked=true;
			break;
		}
	}
}

function setDisabled(Obj,b){	//禁用对象
	var Obj=$(Obj)
	if (Obj){Obj.disabled=b;}
}

function setClass(id,Class,Type){
	if(!typeof(id)=="object" || typeof(id)=="string"){var obj=$(id);}else{var obj=id;}
	if(obj){if(Type=="+"){obj.className+=" "+Class;}else{obj.className=Class;}}
}

function createNumOption(obj,s,e,t){
	var obj=$(obj);
	if(t=="new"){obj.length=0;}
	for(var i=s;i<(e+1);i++){
		obj.options[obj.length] = new Option(i,i); 
	}
}

function getCookie(CookieName){	/*读取全局Cookies*/
	var cookieString = new String(document.cookie)
	cookieString=cookieString.split(";")
	s_str=CookieName+"="
	var beginPosition;
	var v='';
	for(i=0;i<cookieString.length;i++){
		beginPosition = cookieString[i].indexOf(s_str)
		if(beginPosition > -1){
			v=cookieString[i].substring(beginPosition + s_str.length);
			v=decodeURIComponent(v);
			break;
		}
	}
	return v;
}

function setCookie(name,value){
	var date = new Date();
    date.setTime(date.getTime() + (365 * 24 * 60 * 60 * 1000));
    var expires = "; expires=" + date.toGMTString();
	document.cookie =name +"="+ encodeURIComponent(value) + expires + "domain="+location.host+"; path=/";
}