//
//	this function emulates the getelementbyid by using any supported methods by the browser
//
function emulate_getelementbyid(id){
	var obj = null;
    if(document.getElementById){
        /* Prefer the widely supported W3C DOM method, if
           available:-
        */
        obj = document.getElementById(id);
    }else if(document.all){
        /* Branch to use document.all on document.all only
           browsers. Requires that IDs are unique to the page
           and do not coincide with NAME attributes on other
           elements:-
        */
        obj = document.all[id];
    }
    /* If no appropriate element retrieval mechanism exists on
       this browser this function always returns null:-
    */
    return obj;

}

//
//	create xml http request regardless of the browser
//
function createXHR(){
	try {
		//	ie
		return new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	try {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e) {
	try {
		//	others
		return new XMLHttpRequest();
	}catch(e){
	//	consume exceptions
	}
	}
	}
	alert("Dynamic content not supported by the browser!");
	return 0;
}

//
//	calls the server for new gallery information
//
function postAjaxRequest(filename, parameters, func,errorfunc, xml){
	var mypostrequest=new createXHR();
	if (xml && mypostrequest.overrideMimeType) {
		mypostrequest.overrideMimeType('text/xml');
	}

	
	
	
	mypostrequest.onreadystatechange=function(){
	 if (mypostrequest.readyState==4){
	  if (mypostrequest.status==200 || window.location.href.indexOf("http")==-1){
	   //document.getElementById("result").innerHTML=mypostrequest.responseText
	   		func(mypostrequest.responseText, mypostrequest.responseXML);
	  }
	  else{
	   		errorfunc();
	  }
	 }
	};
	
	mypostrequest.open("POST", filename, true);
	mypostrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	mypostrequest.send(parameters);
}

function formpoststring(obj){
      var getstr = "";
      for (i=0; i<obj.childNodes.length; i++) {
         if (obj.childNodes[i].tagName == "INPUT") {
            if (obj.childNodes[i].type == "text") {
               getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
            }
            if (obj.childNodes[i].type == "checkbox") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               } else {
                  getstr += obj.childNodes[i].name + "=&";
               }
            }
            if (obj.childNodes[i].type == "radio") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               }
            }
         }   
         if (obj.childNodes[i].tagName == "SELECT") {
            var sel = obj.childNodes[i];
            getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
         }
         getstr += formpoststring(obj.childNodes[i]);
      }
	  
	return getstr;
}

function togglecollapse(id){
	element = emulate_getelementbyid(id);
	if(element.style.display != 'none'){
		element.style.display = 'none'; 
		
	} else {
		element.style.display = 'block'; 
	}
	
}

function fill(id, html){
	element = emulate_getelementbyid(id);
	element.innerHTML = html;
}