function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" + 
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function Trim(strText) { 
	while (strText.substring(0,1) == ' ') 
	strText = strText.substring(1, strText.length);
	while (strText.substring(strText.length-1,strText.length) == ' ')
	strText = strText.substring(0, strText.length-1);
	return strText;
}

function getQuerystringValue(name){
	if (location.search != ""){
		var querystringStr = location.search;
		var querystring = querystringStr.replace("?","");
		var pair = querystring.split("&");
		var value = ""
		for (i=0,j=1;i<pair.length;i++,j++){
			value = pair[i].split("=");
			if (value[0] == name){
				return value[1];
				break;
			}	
		}
	}
}



var isIE = window.ActiveXObject?true:false;
var xmlhttp;

function createRequest() {
  try {
    xmlhttp = new XMLHttpRequest();
  } catch (trymicrosoft) {
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (othermicrosoft) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (failed) {
        xmlhttp = false;
      }
    }
  }
	return xmlhttp;
  if (!request)
    alert("Error initializing XMLHttpRequest!");
}

function loadXMLDoc(url,func,override){
	if(url.indexOf('?')==-1){
		qsStart = '?';
	}else{
		qsStart = '&';
	}
	url = url;//+qsStart+'rnd='+Math.floor(Math.random()*(1000000000+1));if(getQuerystringValue('debug')){alert(url);}
	if(!override){
		createRequest();
		xmlhttp.onreadystatechange=eval(func);
		xmlhttp.open("GET",url,true)
		xmlhttp.send(null);
	}
}

function getElementTextNS(prefix, local, parentElem, index, attr) {
    var result = "";
    if (prefix && isIE) {
		
        result = parentElem.getElementsByTagName(prefix + ":" + local)[index];
    } else {
		
        result = parentElem.getElementsByTagName(local)[index];
    }
    if (result) {
		
        if (result.childNodes.length > 1) {
            return result.childNodes[1].nodeValue;
        } else {
			return result.getAttribute(attr)
            //return result.firstChild.nodeValue;//problem here		
        }
    } else {
        return "n/a";
    }
}


/*function getNodeValue(obj,tag,attr,index)
{
	index = index?index:0;
	if(attr){
		return obj.getElementsByTagName(tag)[index].getAttribute(attr);
	}else{
		return obj.getElementsByTagName(tag)[index].firstChild.nodeValue;
	}
}*/
function getNodeValue(obj,tag,attr,index){
	if(obj != null){
		index = index?index:0;
		var elems = obj.getElementsByTagName(tag);
		if(elems.length >= index){
			if(attr){
				return elems[index].getAttribute(attr);
			}
			else{
				if(elems[index].firstChild !=null ){
					return elems[index].firstChild.nodeValue;
				}
			}
		}
	}
	return null;
}

function regex(str,target,subwith){
	re = eval('/'+target+'+/g')
	regexstr = str.replace(re,subwith);
	escq = /\"+/g
	regexstr = regexstr.replace(escq,"'");
	return regexstr;
}

function eObj(id,attribute,value){
	if (document.all){
		lb = "[";rb = "]";idType = "document.all";
	}else{
		lb = "(";rb = ")";idType = "document.getElementById";
	}
	var object = idType+lb+"'"+id+"'"+rb+"."+attribute+"\=\""+value+"\"";
	eval(object);
}

function eObjVal(id,attribute){
	if (document.all){
		lb = "[";rb = "]";idType = "document.all";
	}else{
		lb = "(";rb = ")";idType = "document.getElementById";
	}
	var object = idType+lb+"'"+id+"'"+rb+"."+attribute;
	return eval(object);
}


function jsRequest(fullUrl) {
    this.fullUrl = fullUrl;
    this.noCacheIE = '?noCacheIE=' + (new Date()).getTime();
    this.headLoc = document.getElementsByTagName("head").item(0);
    this.scriptId = 'jsID' + jsRequest.scriptCounter++;
}

jsRequest.scriptCounter = 1;

jsRequest.prototype.buildScriptTag = function () {
    this.scriptObj = document.createElement("script");
    this.scriptObj.setAttribute("type", "text/javascript");
    this.scriptObj.setAttribute("charset", "utf-8");
    this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
    this.scriptObj.setAttribute("id", this.scriptId);
}

jsRequest.prototype.removeScriptTag = function () {
    this.headLoc.removeChild(this.scriptObj);  
}

jsRequest.prototype.addScriptTag = function () {
    this.headLoc.appendChild(this.scriptObj);
}

function docjslib_getRealLeft(imgElem) {
	if(document.all){
		xPos = eval(imgElem).offsetLeft;
		tempEl = eval(imgElem).offsetParent;
		while (tempEl != null) {
			xPos += tempEl.offsetLeft;
			tempEl = tempEl.offsetParent;
		}
		return xPos;
	}else{
		xPos = document.getElementById(imgElem).offsetLeft;
		tempEl = document.getElementById(imgElem).offsetParent;
		while (tempEl != null) {
			xPos += tempEl.offsetLeft;
			tempEl = tempEl.offsetParent;
		}
		return xPos+5;
	}
}

function docjslib_getRealTop(imgElem) {
	if(document.all){
		yPos = eval(imgElem).offsetTop;
		tempEl = eval(imgElem).offsetParent;
		while (tempEl != null) {
			yPos += tempEl.offsetTop;
			tempEl = tempEl.offsetParent;
		}
		return yPos;
	}else{
		yPos = document.getElementById(imgElem).offsetTop;
		tempEl = document.getElementById(imgElem).offsetParent;
		while (tempEl != null) {
			yPos += tempEl.offsetTop;
			tempEl = tempEl.offsetParent;
		}
		return yPos+5;
	}
}

