var isIe=(document.all)?true:false;

function externallinks() { 
	if (!document.getElementsByTagName) return; 
	var anchors = document.getElementsByTagName("a"); 
	for (var i=0; i<anchors.length; i++) { 
		var anchor = anchors[i]; 
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "topwin") {
			anchor.setAttribute('target', '_top'); 
		}
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "main") {
			anchor.setAttribute('target', 'main'); 
		}
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "left") {
			anchor.setAttribute('target', 'left'); 
		}
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "newwin") {
			anchor.setAttribute('target', '_blank'); 
		}
	}
} 
if (isIe){
	window.attachEvent('onload',externallinks);
}else{
	window.addEventListener('load',externallinks,false);
}

function getStrLength(str) {
	var l = 0; 
	var a = str.split(""); 
	for (var i=0;i<a.length;i++) { 
		if (a[i].charCodeAt(0)<299) { l++; } else { l+=2; } 
	} 
	return l; 
}

function OpenWin(url,width,height) {
	var x = parseInt(document.documentElement.clientWidth / 2.0) - (width / 2.0);  
	var y = parseInt(document.documentElement.clientHeight / 2.0) - (height / 2.0); 
	var win = window.open(url, "mcePopup", "top=" + y + ",left=" + x + ",scrollbars=no,status=no,width=" + width + ",height=" + height + ",location=no" ); 
	win.focus();
}

function go_to(ao,fid,stit){
	var h=document.getElementById(fid).getElementsByTagName(stit);
	for(var i=0;i<h.length;i++){
		if(ao-1==i){
			h[i].className+=" up";
		} else {
			h[i].className="";
		}
	}
}

function Ajax_CallBack(FormName,ID,geturl,myObj){
	var xmlHttp = false;
	try {
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e2) {
			xmlHttp = false;
		}
	}

	if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
		xmlHttp = new XMLHttpRequest();
	}
	arrID = ID.split("||");
	xmlHttp.open("POST", geturl, true);
	xmlHttp.setRequestHeader("REFERER", location.href);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	xmlHttp.onreadystatechange = function() {
		for (var i=0; i<arrID.length; i++) { 
			var ID2 = document.getElementById(arrID[i]);
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200 && ID2){
				var response = xmlHttp.responseText;
				var response2 = response.split("||");
				ID2.innerHTML = response2[i];
				if (myObj) {
					if(response.indexOf("check_error")!=-1) {
						myObj.disabled = true;
						return false;
					}else{
						myObj.disabled = false;
					}
				}
			}
		}
	}
	var encodedData="";
	if (document.forms.length > 0 && FormName) {
		var form = document.forms[FormName];
		for (var i = 0; i < form.length; ++i) {
			var element = form.elements[i];
			if (element.name) {
				var elementValue = null;
				if (element.nodeName == "INPUT") {
					var inputType = element.getAttribute("TYPE").toUpperCase();
					if (inputType == "TEXT" || inputType == "PASSWORD" || inputType == "HIDDEN") {
						elementValue = element.value;
					} else if (inputType == "CHECKBOX" || inputType == "RADIO") {
						if (element.checked) {
							elementValue = element.value;
						}
					}
				} else if (element.nodeName == "SELECT" || element.nodeName == "TEXTAREA") {
					elementValue = element.value;
				} 
				if (elementValue) {
					if(encodedData==""){
						encodedData = element.name + "=" + encodeURIComponent(elementValue);
					}else{
						encodedData += "&" + element.name + "=" + encodeURIComponent(elementValue);
					}
				}
			}
		}

	}
	xmlHttp.send(encodedData);
}

function initAutoFormStyle() {        
    var inputArry;
    inputArry = document.getElementsByTagName("input");
    textArry = document.getElementsByTagName("textarea");
    for(var i=0;i<inputArry.length+textArry.length;i++) {
        var tmpInput = null;
        if(i< inputArry.length) {
            tmpInput = inputArry[i];
            if(tmpInput.type == 'text' || tmpInput.type == 'password' || tmpInput.type == 'file') {
                if (!tmpInput.onblur)
					setEvent(tmpInput);
            }
        } else {
            tmpInput = textArry[i - inputArry.length];
            if (!tmpInput.onblur)
				setEvent(tmpInput);
        }
    }
}
function setEvent(obj) {
	if (!obj.onblur) {
		obj.onblur = function(){
		this.style.border = "#cccccc 1px solid";
		}
	}
	if (!obj.onfocus) {
		obj.onfocus =function(){
		this.style.border = "#666666 1px solid";
		}
	}
}
if (isIe){
	window.attachEvent('onload',initAutoFormStyle);
}else{
	window.addEventListener('load',initAutoFormStyle,false);
}

function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

function ChangeBack(objid,scolor,dcolor,ocolor,ccolor){
	var t=document.getElementById(objid).getElementsByTagName("tr");
	for(var i=0;i<t.length;i++){
		t[i].style.backgroundColor=(t[i].sectionRowIndex%2==0)?scolor:dcolor;
		t[i].onclick=function(){
			if(this.x!="1"){
				this.x="1";
				this.style.backgroundColor=ccolor;
			}else{
				this.x="0";
				this.style.backgroundColor=(this.sectionRowIndex%2==0)?scolor:dcolor;
			}
		}
		t[i].onmouseover=function(){
			if(this.x!="1")this.style.backgroundColor=ocolor;
		}
		t[i].onmouseout=function(){
			if(this.x!="1")this.style.backgroundColor=(this.sectionRowIndex%2==0)?scolor:dcolor;
		}
	}
}

function imgLoad(obj,pw,ph){
	var w=document.getElementById(obj).width;
	var h=document.getElementById(obj).height;
	var l=w/h;
	var pl=pw/ph;
	if(l>=pl){
		if(w>pw){
			w=pw;
			h=w/l
		}
	}else{
		if(h>ph){
			h=ph;
			w=h*l;
		}
	} 
	document.getElementById(obj).style.width=Math.round(w)+"px";
	document.getElementById(obj).style.height=Math.round(h)+"px";
}

function addLoadEvent(func){
	var oldonload=window.onload;
	if(typeof window.onload!='function'){
		window.onload=func
	}else{
		window.onload=function(){
			oldonload();
			func();
		}
	}
}

var postContent; 
function ajaxSubmitForm(form) {
	form=document.getElementById(form);
	var elements = form.elements;
	var element;
	var i;
	postContent = "";
	for(i=0;i<elements.length;++i) {        
		var element=elements[i];
		if(element.type=="text" || element.type=="textarea" || element.type=="hidden") {
			postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value) + "&";
		} else if(element.type=="select-one"||element.type=="select-multiple") {
			var options=element.options,j,item;
			for(j=0;j<options.length;++j){
				item=options[j];
				if(item.selected) {        
					postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(item.value) + "&";    
				}
			}
		} else if(element.type=="checkbox"||element.type=="radio") {
			if(element.checked) {    
				postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value) + "&"; 
			}      
		} else if(element.type=="file") {  
			if(element.value != "") {          
				postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value) + "&"; 
			}      
		} else if(element.type != "button"||element.type != "reset") {          
			postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value) + "&";    
		}
	}
}

function getPosition() {
      var top    = document.documentElement.scrollTop;
      var left   = document.documentElement.scrollLeft;
      var height = document.documentElement.clientHeight;
      var width  = document.documentElement.clientWidth;
      return {top:top,left:left,height:height,width:width};
}

function showPop(Ist){
	if (document.getElementById('MessageShow')) {
		var obj = document.getElementById('MessageShow')
		if (Ist == 1){
			obj.style.display  = "block";
			obj.style.position = "absolute";
			obj.style.zindex   = "999";
				
			var Position = getPosition();
			obj.style.top  = (Position.top  + 200)  + "px";
			obj.style.left = (Position.left + 300) + "px";
				
			window.onscroll = function (){
				var Position   = getPosition();
				obj.style.top  = (Position.top  + 200)  +"px";
				obj.style.left = (Position.left + 300) +"px";
			}
		}else{
			obj.style.display  = "none";
		}
	}
}
function showMessage() {setTimeout("showPop(1)",3000)}
if (isIe){
	window.attachEvent('onload',showMessage);
}else{
	window.addEventListener('load',showMessage,false);
}
function nextPag(obj) {
	document.getElementById('Message'+obj).style.display  = "none";
	if (obj==1) {document.getElementById('MessageShow').style.display  = "none";}
}
