document.write('<div id="loading" style="position:absolute; text-align:left; z-index:1000" class="thickbox"	>Loading Page - please wait...<img src="./images/ajax_indicator.gif" border="0" alt=""><br/></div>');

// Created by: Simon Willison | http://simon.incutio.com/
function addLoadEvent(func) {
  var oldonload = window.onload;		
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
  document.getElementById("loading").style.display="none";

});

	function removeElement(divNum) {
 
  var d = document.getElementById('test3');
  var olddiv = document.getElementById('product_'+divNum);
  d.removeChild(olddiv);
  
}
	function removeElement2(divNum) {
  var d2= document.getElementById('test2');
  var olddiv2 = document.getElementById('category_'+divNum);
  d2.removeChild(olddiv2);
  
}
function sendRequest(productid) {
			 new Ajax.Request('process_remove.php?removeproduct='+productid);
				removeElement(productid);
				}
function sendRequest2(categoryid) {
			new Ajax.Request('process_removecat.php?removecategory='+categoryid);
				removeElement2(categoryid);
				}
function sendSetsession(status,searchid) {
			 new Ajax.Request('setsession.php?session_status='+status,{ onSuccess: submitsession(searchid,status)  });
				
				}
function submitsession(searchid,status) {
document.getElementById('browsingmanager').value = status;
document.getElementById('browsingmanager2').value = status;
document.forms[searchid].submit();
}

function newText(text){
	document.getElementById('status').innerHTML = text;
}
function newText2(text){
	document.getElementById('offer').innerHTML = text;
}			

function CopyDIV(IDS) {
  document.getElementById('search').value=document.getElementById(IDS).innerHTML;
}
function CopyDIV2(IDS) {
	
  document.getElementById('search2').value=document.getElementById(IDS).innerHTML;

}
/*
function Set_Cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
/*
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}
*/
sections = ['test1','test2','test3'];

	function createNewSection(name) {
		var name = $F('sectionName');
		if (name != '') {
			var newDiv = Builder.node('div', {id: 'test' + (sections.length + 1), className: 'section', style: 'display:none;' }, [
				Builder.node('h3', {className: 'handle'}, name)
			]);

			sections.push(newDiv.id);
			$('page').appendChild(newDiv);
			Effect.Appear(newDiv.id);
			destroyLineItemSortables();
			createLineItemSortables();
			createGroupSortable();
		}
	}

	function createLineItemSortables() {
		for(var i = 0; i < sections.length; i++) {
			Sortable.create(sections[i],{tag:'div',dropOnEmpty: true, containment: sections,only:'lineitem'});
		}
	}

	function destroyLineItemSortables() {
		for(var i = 0; i < sections.length; i++) {
			Sortable.destroy(sections[i]);
		}
	}

	function createGroupSortable() {
		Sortable.create('page',{tag:'div',only:'section',handle:'handle'});
	}

	/*
	Debug Functions for checking the group and item order
	*/
function getGroupOrder() {
var sections = document.getElementsByClassName('floatingWindowContent');
var alerttext = '';
var urltext = '';
var details ='';
		sections.each(function(section) {
			
			var sectionID = section.id;
			var order = Sortable.serialize(sectionID);
			alerttext += sectionID + ': ' + Sortable.sequence(section) + '\n';
					if (sectionID == 'test2') {
						var form = document.createElement("form");
                    	form.setAttribute("method", "get");
                    	form.setAttribute("action", "search_cats.php");

                        var hiddenField = document.createElement("input");              
                        hiddenField.setAttribute("name", 'test2');
                        hiddenField.setAttribute("value", '');
                        form.appendChild(hiddenField);
                        document.body.appendChild(form);    // Not entirely sure if this is necessary                   
                        form.submit();

						return false;
		
						}
						if (sectionID == 'test3') {
						var form = document.createElement("form");
                    	form.setAttribute("method", "get");
                    	form.setAttribute("action", "search_prods.php");

                        var hiddenField = document.createElement("input");              
                        hiddenField.setAttribute("name", 'test3');
                        hiddenField.setAttribute("value", '');
                        form.appendChild(hiddenField);
                        document.body.appendChild(form);    // Not entirely sure if this is necessary                   
                        form.submit();

						return false;
		
						}



			});
}
	
function populateHiddenVars() {
document.getElementById('categoriesListOrder').value = Sortable.serialize('test2');
return true;

}
function populateHiddenVars3() {
document.getElementById('categoriesListOrder').value = Sortable.serialize('test3');
return true;
}
			//-->
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
