function getXMLHttp(){
    var XMLHttp = null;
    if (window.XMLHttpRequest) {
	try {
    	    XMLHttp = new XMLHttpRequest();
	} catch (e) { }
    }
    else{
        if (window.ActiveXObject) {
            try {
                XMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
    		try {
		    XMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) { }
            }
        }
    }
    return XMLHttp;
}

var XMLHttpS = getXMLHttp();


function getbanner_async(domid){
    var XMLHttpA = getXMLHttp();
    XMLHttpA.open("GET","/banners.php?domid="+domid,true);
    XMLHttpA.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    XMLHttpA.onreadystatechange = function(){
	if (XMLHttpA.readyState == 4){
	    textarray = XMLHttpA.responseText.split('\n');
	    domid = textarray[0];
	    text = XMLHttpA.responseText.replace(/^.*\n/,'');
    	    document.getElementById(domid).innerHTML = text;
	}
    }
    XMLHttpA.send(null);
}    

function getbanner_sync(domid){
    XMLHttpS.open("GET","/banners.php?domid="+domid,false);
    XMLHttpS.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    XMLHttpS.send(null);
    if (XMLHttpS.status == 200) {
	document.write(XMLHttpS.responseText);
    }
    else{
	document.write("Error:" + XMLHttpS.statusText);
    }
}    

function rotate_banner(domid){
    getbanner_async(domid);
    jscript = "rotate_banner('" + domid + "')";
    window.setTimeout(jscript,3000);
}

function getbanner(rotate,domid){
    if (! rotate){
	getbanner_sync(domid);
    }
    else{
	rotate_banner(domid);
    }
    return false;
}


function makeactive1(atab) 
{ 
  document.getElementById("tab01").className = "v";
  document.getElementById("tab02").className = "v"; 
  document.getElementById("tab03").className = "v";
  document.getElementById("tab04").className = "v";
  document.getElementById('tab01_data').style.display = "none";
  document.getElementById('tab02_data').style.display = "none";
  document.getElementById('tab03_data').style.display = "none";
  document.getElementById('tab04_data').style.display = "none";

  document.getElementById(atab).className = "current";
  document.getElementById(atab + '_data').style.display = "block";
} 

function makeactive2(atab) 
{ 
  document.getElementById("tab11").className = "v";
  document.getElementById("tab12").className = "v"; 

  document.getElementById('tab11_data').style.display = "none";
  document.getElementById('tab12_data').style.display = "none";

  document.getElementById(atab).className = "current";
  document.getElementById(atab + '_data').style.display = "block";
} 


function OpenImagePopup(imgPath, title, alt) {
    var win = window.open('','preview',
    'width=50,height=50,left=0,top=0,screenX=0,screenY=0,resizable=1,scrollbar=0,status=0');
    
    var winDoc = win.document;
    if (title == undefined) title = 'My Image, Click to Close';
    if (alt   == undefined) alt   = 'My Image, Click to Close';
    var content = '<html><head><title>' + title + '</title>' +
    			  '<style>body{overflow: hidden;margin:0;}img{border:0;}</style>' +
    			  '</head><body><a href="javascript:self.close()">' +
    			  '<img alt="' + alt + '" id="image" src="' + imgPath + '" /></a></body></html>'
    win.document.write(content);
    
    winDoc.body.onload = function() {
    	var obj = winDoc.getElementById('image');
    	var w = obj.width, h = obj.height;
    	var iHeight= document.body.clientHeight, iWidth = self.innerWidth;
    	
    	var left = (self.opera ? iWidth : screen.availWidth)/2 - w/2;
    	var top =  (self.opera ? iHeight : screen.availHeight)/2 - h/2;
    	win.resizeTo(w+10, h+26);
    	win.moveTo(left, top);
    }
    
    win.onload = winDoc.body.onload; // special for Mozilla
    
    // !!! Very important statement: popup onload won't execute without it!
    win.document.close();
    win.focus();
}    

