function newRollover(imgName,imgFiles) {
  if (document.images) {
    imgFiles=imgFiles+",";
    imgNo=1;
    while(imgFiles.indexOf(',')!=-1) {
      imgFile=imgFiles.substring(0,imgFiles.indexOf(','));
      imgFiles=imgFiles.substring(imgFiles.indexOf(',')+1,imgFiles.length);
      eval(imgName+"_urc_"+imgNo+"=new Image();");
      eval(imgName+"_urc_"+imgNo+".src='"+imgFile+"'");
      imgNo++;
    }
  }
}

function roll(img,on,type) {
  type=type?type:img;
  if (document.images) 
    eval("document.images['"+img+"'].src="+type+"_urc_"+on+".src");
}

function openNewWindow(url,name,features) { 
  if (features && (navigator.appName=="Netscape" || document.body)) {
    width=height="";
    s=features.indexOf("width")+5; n=0;
    while (n!=2 && (ch=features.charAt(s++)))
      if (ch>="0" && ch<="9") { width+=ch; n=1; } else n<<=1;
    s=features.indexOf("height")+5; n=0;
    while (n!=2 && (ch=features.charAt(s++)))
      if (ch>="0" && ch<="9") { height+=ch; n=1; } else n<<=1;
    leftpos=(navigator.appName=="Netscape"?
	     window.outerWidth/2+window.screenX:document.body.offsetWidth/2+window.screenLeft)-width/2;
    toppos= (navigator.appName=="Netscape"?
	     window.outerHeight/2+window.screenY:screen.height/2.5)-height/2;
    features+=",left="+leftpos+",top="+toppos+",screenX="+leftpos+",screenY="+toppos;
  } 
  newWindow=features?window.open(url,name,features):window.open(url,name);
  newWindow.focus();
}

function registerLink() {
	openNewWindow('/launch_insider.php','reg','width=700,height=550,scrollbars=yes,resizable=yes,toolbar=yes,menubar=yes,directories=yes,location=yes,status=yes');
}

function forgotLink() {
	openNewWindow('/forgot.php','forgot','height=227,width=374,resizable=yes')
}

function logoutLink() {
	document.location.replace(document.location.pathname+document.location.search+(document.location.search.length?"&":"?")+"cmd=navLogout");
}

function trim(str) {
    str=str+'';
    if (str=='') return str;
    return str.replace(/(^\s+)|(\s+$)/g, "");
}

function countWord(str) {
    str=str+'';
    if (str=='') return 0;
    a=str.split(/\s+/);
    return a.length;
}

function toggleElement(elementId){
    var ele = document.getElementById(elementId);
    if (ele.style.display == "none") {
        ele.style.display = "block";
    } else {
        ele.style.display = "none";
    }
}

function downloadFile(filePath) {
	window.location = filePath;
}

function popWindow(URL,name,widgets) {
	popwin = window.open(URL,name,widgets);
	popwin.focus();	
	popwin.opener = self;
	popwin.name = name;			
}

function getHttpRequest() {
    var httpRequest;
    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
        httpRequest = new XMLHttpRequest();
        if (httpRequest.overrideMimeType) {
            httpRequest.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
            }
        }
    }
    if (!httpRequest) {
        alert('Browser too old. Cannot create an XMLHTTP instance.\nPlease update your web browser!');
        return false;
    }
    return httpRequest;
}
