function addLoadEvent(func) {   
   var oldonload = window.onload;   
   if (typeof window.onload != 'function') {   
     window.onload = func;   
   } else {   
     window.onload = function() {   
       if (oldonload) {   
         oldonload();   
       }   
       func();   
     }   
   }   
}   

function callAHAH(url, pageElement, callMessage, errorMessage) {
     document.getElementById(pageElement).innerHTML = callMessage;
     try {
     req = new XMLHttpRequest(); /* e.g. Firefox */
     } catch(e) {
       try {
       req = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */
       } catch (e) {
         try {
         req = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */
         } catch (E) {
          req = false;
         } 
       } 
     }
     if (req != undefined) {
	     req.onreadystatechange = function() {responseAHAH(pageElement, errorMessage);};
	     req.open("GET",url,true);
	     req.send(null);
	}
}

function responseAHAH(pageElement, errorMessage) {
   var output = '';
   if(req.readyState == 4) {
      if(req.status == 200) {
         output = req.responseText;
         document.getElementById(pageElement).innerHTML = output;
         } else {
         document.getElementById(pageElement).innerHTML = errorMessage+"\n"+output;
         }
}
}

function startCallback() {
	// make something useful before submit (onStart)
	return true;
}

function completeCallback(response) {
	//document.getElementById('nr').innerHTML = parseInt(document.getElementById('nr').innerHTML) + 1;
	document.getElementById('r').innerHTML = response;
	//setTimeout(listFiles(),2000);
	document.getElementById('uploadform').reset();
}

//CREATE ELEMENTS
var arrInput = new Array(0);
var arrInputValue = new Array(0);

function addInput() {
  arrInput.push(arrInput.length);
  arrInputValue.push("");
  display();
}

function display() {
  document.getElementById('parah').innerHTML="";
  for (intI=0;intI<arrInput.length;intI++) {
    document.getElementById('parah').innerHTML+=createInput(arrInput[intI], arrInputValue[intI]);
  }
}

function saveValue(intId,strValue) {
  arrInputValue[intId]=strValue;
}  

function createInput(id,value) {
  return "<input type='text' id='caption "+ id +"' onChange='javascript:saveValue("+ id +",this.value)' value='"+ value +"'><br>";
}

function deleteInput() {
  if (arrInput.length > 0) { 
     arrInput.pop(); 
     arrInputValue.pop();
  }
  display(); 
}

//BG CELL CHANGER
var oncell = "0"

function overm(celno) { 
	var chgcell
	if (document.layers) { // browser is NN
		chgcell = "window.document."+ celno + ".bgColor='#c0d2ec'";
	} else { //assume IE
		chgcell = "document.getElementById('"+ celno + "').bgColor='#c0d2ec'";
	}
 	eval(chgcell);
}

function outm(celno) { 
	var chgcell
	if (document.layers) { // browser is NN
		chgcell = "window.document."+ celno + ".bgColor='white'";
	} else { //assume IE
		chgcell = "document.getElementById('"+ celno + "').bgColor='white'";
	}
	eval(chgcell);
}

//SELECT AND DISSELECT CHECK BOXES
function checkAll(mynum) {
	var mynum;
	for (var j = 1; j <= mynum; j++) {
		box = eval("document.listform.chkbox_" + j);
		if (box.checked == false) box.checked = true;
	}
}
function uncheckAll(mynum) {
	var mynum;
	for (var j = 1; j <= mynum; j++) {
		box = eval("document.listform.chkbox_" + j);
		if (box.checked == true) box.checked = false;
   }
}
function switchAll(mynum) {
	var mynum;
	for (var j = 1; j <= mynum; j++) {
		box = eval("document.listform.chkbox_" + j);
		box.checked = !box.checked;
   }
}

//ACTION COMFIRMATION
function confirmaction(myURL,myMES){
	var res = confirm(myMES);
	if(res){
		location.href=myURL;
	}
}

/*AJAX CALLS*/
function removeFile(ddd,fff) {
	callAHAH('ajax-call.php?do=removefile&d='+ddd+'&f='+fff,'existingfile','<span class=\"ajaxmessage\">Loading please wait</span>', 'Error');
}
function showPropertyImage(qqqq,ffff) {
	callAHAH('ajax-call.php?do=showfile&d='+qqqq+'&f='+ffff,'largeimage','<span class=\"ajaxmessage\">Loading please wait</span>', 'Error');
}
function sendQCODE() {
	var eee = document.getElementById('manageemail').value;
	if (eee == "") {
		alert("Please enter your email address.");
	} else {
		callAHAH('ajax-call.php?do=sendqcode&d='+eee,'homemanage-remember','<span class=\"ajaxmessage\">Sending please wait</span>', 'Error');
	}
}

function listFiles() {
	callAHAH('ajax_file_list.php?listview=thumb&only=img','albumdiv','<span class=\"ajaxmessage\">Loading please wait</span>', 'Error');
}
function listFilesList() {
	callAHAH('ajax_file_list.php?listview=list&only=img','albumdiv','<span class=\"ajaxmessage\">Loading please wait</span>', 'Error');
}
function listFilesListLibrary() {
	callAHAH('ajax_file_list.php?listview=list','albumdiv','<span class=\"ajaxmessage\">Loading please wait</span>', 'Error');
}
function listFilesListSQL() {
	callAHAH('ajax_file_list_sql.php?listview=list&only=imgx','albumdiv','<span class=\"ajaxmessage\">Loading please wait</span>', 'Error');
}
function listFilesListThumbSQL() {
	callAHAH('ajax_file_list_sql.php?listview=thumb&only=imgx','albumdiv','<span class=\"ajaxmessage\">Loading please wait</span>', 'Error');
}
function deleteFileSQL(fid) {
	callAHAH('ajax_file_list_sql.php?listview=del&only=img&f='+fid,'albumdiv','<span class=\"ajaxmessage\">Loading please wait</span>', 'Error');
}