/*	global variable	*/
var SITE_URL;
var SITE_NAME;
/*	common functions	*/
function originAddEvent(obj, evType, fn) {
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, false);
		return true;
	} else if (obj.attachEvent) {
		var r = obj.attachEvent("on" + evType, fn);
		return r;
	} else {
		return false;
	}
}
function getElementChildNodes(obj) {
	var divs = obj.childNodes;
	var children = new Array();
	for ( var i = 0; i < divs.length; i++) {
		// fix ff
		if (divs[i].nodeType == 1) {
			children.push(divs[i]);
		}
	}
	return children;
}
/*	tab functions	*/
function showTab(obj) {
	var norClass = obj.getAttribute('norclass');
	var overClass = obj.getAttribute('overclass');
	var index = 0, count = 0;
	var divs = getElementChildNodes(obj.parentNode);
	for ( var i = 0; i < divs.length; i++) {
		if (divs[i] == obj) {
			divs[i].className = overClass;
			index = count;
		} else if (divs[i].getAttribute("tab")) {
			divs[i].className = norClass;
			count++;
		}
	}
	var targetId = obj.getAttribute("tab");
	var ids = targetId.split(",");
	for(var j=0;j<ids.length;j++){
		var o = document.getElementById(ids[j]);
		var targets = getElementChildNodes(o);
		// close all targets
		for ( var i = 0; i < targets.length; i++) {
			targets[i].style.display = "none";
		}
		// show the speicfy
		targets[index].style.display = "";		
	}
}
/* footer functions */
function addCookie() {
	if(!SITE_URL || !SITE_NAME){
		return;
	}
	if (document.all) {
		window.external.addFavorite(SITE_URL, SITE_NAME);
	} else if (window.sidebar) {
		window.sidebar.addPanel(SITE_NAME, SITE_URL, "");
	}
}
function SendMail() {
	document.location = "mailto:syoriginsoft@163.com;?subject=Feedback";
}
/* nav functions */
function showSubMenu(obj) {
	var children = getElementChildNodes(obj);
	children[0].style.display = "";
}
function hideSubMenu(obj) {
	var children = getElementChildNodes(obj);
	children[0].style.display = "none";
}


/*
	Request class for requestting
*/
function Request( uri, params )
{
	this.uri = uri;
	this.params = params;
}

Request.prototype.onload=function(result)
{
	// do nothing
}

Request.prototype.send=function(asynchronous)
{
	var me = this;
	// default is synch
	if(!asynchronous)
		asynchronous = false;
	var xmlHttp ;
	if (window.ActiveXObject)
	{ // IE
	    try {
	            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	        } catch (e) {
	            try {
	                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	            } catch (e) {}
	        }
	}
	else if (window.XMLHttpRequest)
	{ // Mozilla, Safari,...
	    xmlHttp = new XMLHttpRequest();
	    if (xmlHttp.overrideMimeType)
	    {
	        xmlHttp.overrideMimeType('text/xml');
	    }
	}
	var sResult;
    if(this.params)
	    xmlHttp.open("POST", this.uri, asynchronous);	// sync
    else
	    xmlHttp.open("GET", this.uri, asynchronous);	// sync
	if(this.params){
	    var sContent="";
	    if(this.params.length>1){
            for(var i=1; i<this.params.length; i+=2){
                if(i>1)
                    sContent += "&";
                sContent += encodeURIComponent(this.params[i-1]) + "=" + encodeURIComponent(this.params[i]);
            }
        }
        else
            sContent = this.params;
        xmlHttp.setRequestHeader("Content-Length",sContent.length);
	    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
        if(asynchronous)
	    	xmlHttp.onreadystatechange = function()
	    	{
	    		me.handleResponse(xmlHttp);
	    	};
	    xmlHttp.send(sContent);
		if(!asynchronous)
			return xmlHttp.responseText;
	}
	else
	{
        xmlHttp.setRequestHeader("Content-Type","text/html; charset=UTF-8");
        xmlHttp.send(null);

    }
}

Request.prototype.handleResponse=function(xmlHttp)
{
	if (xmlHttp.readyState == 4)
   	{
		if (xmlHttp.status == 200)
		{
			this.onload(xmlHttp.responseText);
		}
	}
}
