function printLoading(div)
{
	document.getElementById(div).innerHTML = '<div class="loading"><img src="/images/print_loading.gif" width="200" height="150" alt="Processing, please wait" /></div>';
}


   var httpRequest = false;
   
   function postForm(url, parameters, div) {
	printLoading(div);
		
      httpRequest = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         httpRequest = new XMLHttpRequest();
         if (httpRequest.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //httpRequest.overrideMimeType('text/xml');
            httpRequest.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!httpRequest) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }

	  httpRequest.onreadystatechange = function() { 
		document.getElementById(div).innerHTML = httpRequest.responseText;
  	  };
	  
      httpRequest.open("POST", url, true);
	  httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	  httpRequest.send(parameters);
   }

   function alertContents(div) {
      if (httpRequest.readyState == 4) {
         if (httpRequest.status == 200) {
            //alert(httpRequest.responseText);
            result = httpRequest.responseText;
            document.getElementById(div).innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   function processForm(obj,  div , url) {

	  printLoading(div);
	  
	  var getstr = "";
		var i=0;
 		var j=0;
		
      for (i=0; i<obj.length; i++) {
         if (obj[i].tagName == "INPUT") {
		 	//alert(obj[i].type);

            if (obj[i].type == "text") {
               getstr += obj[i].name + "=" + obj[i].value + "&";
            }
			
            if (obj[i].type == "checkbox") {
               if (obj[i].checked) {
                  getstr += obj[i].name + "=" + obj[i].value + "&";
               } else {
                  getstr += obj[i].name + "=&";
               }
            }
			
            if (obj[i].type == "radio") {
               if (obj[i].checked) {
                  getstr += obj[i].name + "=" + obj[i].value + "&";
               }
            }
         }   
		 
         if (obj[i].tagName == "SELECT") {
            var sel = obj[i];
            getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
         }
		 
		 
		 if (obj[i].type == "hidden") {
             getstr += obj[i].name + "=" + obj[i].value + "&";
         }
		 
      }
		
		
		postForm(url, getstr, div);
}
		
		/** THE DIFFERNECE APPEARS TO EB THAT THIS ONE PROCESS FORMS IN TABLES **/
	function processTableForm(obj,  div , url) {
		
		printLoading(div);
		
		var getstr = "";
  		
		for (i=0; i<obj.getElementsByTagName("input").length; i++) 
		{
        
			if (obj.getElementsByTagName("input")[i].type == "text") 
			{
           		getstr += obj.getElementsByTagName("input")[i].name + "=" + 
                obj.getElementsByTagName("input")[i].value + "&";
        	}
			
        	if (obj.getElementsByTagName("input")[i].type == "checkbox") 
			{
           		if (obj.getElementsByTagName("input")[i].checked) 
				{
              		getstr += obj.getElementsByTagName("input")[i].name + "=" + 
                   	obj.getElementsByTagName("input")[i].value + "&";
           		} else {
              		getstr += obj.getElementsByTagName("input")[i].name + "=&";
           		}
       		}
        
			if (obj.getElementsByTagName("input")[i].type == "radio") 
			{
           		if (obj.getElementsByTagName("input")[i].checked) 
				{
              	getstr += obj.getElementsByTagName("input")[i].name + "=" + 
                obj.getElementsByTagName("input")[i].value + "&";
           		}
     		}  
     		
			if (obj.getElementsByTagName("input")[i].tagName == "SELECT") 
			{
        		var sel = obj.getElementsByTagName("input")[i];
        		getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
     		}
     
  		}
		
		postForm(url, getstr, div);
		return;
	}
	

function removeObject(video_path, div, button_div){
    var obj = document.getElementById('shadowbox_content');

    // stop the movie
    if(window.ActiveXObject){
        shadowbox_content.controls.stop();
        shadowbox_content.URL = 'non-existent.wmv'; // set URL to non-existent movie
        window.shadowbox_content = function(){};
        //window.shadowbox_content = {};
    }

    obj.parentNode.removeChild(obj);
	
	var button = '<div id="'+button_div+'"><button onclick="addObject(\''+video_path+'\',\''+div+'\',\''+button_div+'\');">Watch Video</button></div>';
	document.getElementById(button_div).innerHTML = button;
};

function addObject(video_path, div, button_div){
    var url = video_path;
    var height = 240;
    var width = 320;
    var autostart = true;
    var showcontrols = true;

    if(window.ActiveXObject){
        // showcontrols must be a string in IE
        if(showcontrols){
            showcontrols = 'full';
            height += 70; // height of WMP controller in IE
        }else{
            showcontrols = 'none';
        }
        var autostart = autostart ? 1 : 0;
        var html = '<object standby="Loading your movie ..."  id="shadowbox_content" name="shadowbox_content"'
            + 'height="' + height + '" width="' + width + '" '
            // + 'type="application/x-oleobject" '
            + 'classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6">'
                + '<param name="url" value="' + url + '" />'
                + '<param name="autostart" value="' + autostart + '" />'
                + '<param name="uimode" value="' + showcontrols + '" />'
            + '</object>';
    }else{
        // showcontrols and autostart must be an integer in browsers other than IE
        if(showcontrols){
            showcontrols = 1;
            height += 45; // height of WMP controller in non-IE
        }else{
            showcontrols = 0;
        }
        var autostart = autostart ? 1 : 0;
        var html = '<object standby="Loading your movie ..." id="shadowbox_content" name="shadowbox_content" '
            + 'height="' + height + '" width="' + width + '" '
            + 'type="video/x-ms-wmv" '
            + 'data="' + url + '">'
                + '<param name="autostart" value="' + autostart + '" />'
                + '<param name="showcontrols" value="' + showcontrols + '" />'
            + '</object>';
    }

    document.getElementById(div).innerHTML = html;
	
	//video_button_show_{uid}
	//alert(button_div);
	//<div id="button_div"><button onclick="removeObject('video_path','div','button_div');">Hide Video Console</button></div>
	var button = '<div id="'+button_div+'"><button onclick="removeObject(\''+video_path+'\',\''+div+'\',\''+button_div+'\');">Close</button></div>';
	document.getElementById(button_div).innerHTML = button;
};
