/*******************************************************************
 Zenith Picture Gallery
 Written by and copyright (c) Ali Almossawi
 http://www.cyberiapc.com

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License, a copy of 
 which is made available to you with this package.
 This program is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A  PARTICULAR PURPOSE.
 
 File: j_global.php
 Description: -
 Random quote: "It is easy to be brave from a safe distance." -Aesop
 *******************************************************************/

  function validate(check_item)
  {
	  return true;
  }
  
  function submit_form(form,strURL,id) 
  { 
	 var str = getFormValues(form); 
     xmlReq = xmlhttpFormPost(strURL,id,str); 
  } 
  
 function getFormValues(fobj) 
 { 

   var str = ""; 

   for(var i = 0;i < fobj.elements.length;i++) 
   { 
		 if(fobj.elements[i]!=null)
		 {
			 str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&"; 
		 }
   } 
   str = str.substr(0,(str.length - 1)); 
   return str; 
}


/*
	function xmlhttpFormPost(strURL,id,str) {
		
	    document.getElementById(id).innerHTML = '<img src="http://www.liveleak.com/images/processing.gif" width="16" height="16"> <strong>Processing request..please hold on...</strong>';
		
		var xmlHttpReq = false;
	    var self = this;
	    // Mozilla/Safari
	    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
	    }
	    // IE
	    else if (window.ActiveXObject) {
	        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
 	   }

		self.xmlHttpReq.open('GET', strURL, true);
	    //self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
 	    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
				document.getElementById(id).innerHTML = self.xmlHttpReq.responseText;
			}
		}
		self.xmlHttpReq.send(str);
		return false;
	}
	*/
	
	function xmlhttpPost(strURL, id, id_for_loading_msg, msg_to_show) {
		document.getElementById(id_for_loading_msg).innerHTML = msg_to_show;

		var request = null;
		try
		{
		   request = new XMLHttpRequest(); //Mozilla, Safari
		}
		catch (trymicrosoft) //Microsoft
		{
		   try
		   {
			 request = new ActiveXObject("Msxml2.XMLHTTP");
		   }
		   catch (othermicrosoft)
		   {
			 try
			 {
			   request = new ActiveXObject("Microsoft.XMLHTTP");
			 }
			 catch (failed)
			 {
			   request = null;
			 }
		   }
		}//end catch
		
		 request.open("GET", strURL, true);
		 request.onreadystatechange =  function() {
			 if (request.readyState == 4)
			{
					document.getElementById(id).innerHTML = request.responseText;
			}
		 }
		 
		 request.send(null);

		return false;
	}
	
	/*
	function xmlhttpPost(strURL,id) {
		
		document.getElementById(id).innerHTML = '<p><img src="skins/default/images/loading_small.gif"> <strong>Processing request..please hold on...</strong></p>';
		
	    var xmlHttpReq = false;
	    var self = this;
	    // Mozilla/Safari
	    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
	    }
	    // IE
	    else if (window.ActiveXObject) {
	        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
 	   }

		self.xmlHttpReq.open('GET', strURL, true);
	    //self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
 	    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
				document.getElementById(id).innerHTML = self.xmlHttpReq.responseText;
			}
		}
		self.xmlHttpReq.send('i=1');
		return false;
	}
	*/
	
	
	function replaceText(el, text) {
  if (el != null) {
    clearText(el);
    var newNode = document.createTextNode(text);
    el.appendChild(newNode);
  }
}

function clearText(el) {
  if (el != null) {
    if (el.childNodes) {
      for (var i = 0; i < el.childNodes.length; i++) {
        var childNode = el.childNodes[i];
        el.removeChild(childNode);
      }
    }
  }
}

function getText(el) {
  var text = "";
  if (el != null) {
    if (el.childNodes) {
      for (var i = 0; i < el.childNodes.length; i++) {
        var childNode = el.childNodes[i];
        if (childNode.nodeValue != null) {
          text = text + childNode.nodeValue;
        }
      }
    }
  }
  return text;
}
