/*********** PRO7i CODE *******************/

function searchProducts(hint)
{
	pars = 'type=product&hint='+ hint;
	
	var myAjax = new Ajax.Updater
	(	
		{success: 'productList'},
		'ajax.php', 
		{
			method: 'get', 
			parameters: pars,
			onFailure: productSearchResponse
		}
	);
}

function searchCustomers(hint)
{
	pars = 'type=customers&hint='+ hint;
	
	var myAjax = new Ajax.Updater
	(	
		{success: 'productList'},
		'ajax.php', 
		{
			method: 'get', 
			parameters: pars,
			onFailure: customerSearchResponse
		}
	);
}


function customerSearchResponse(request)
{
}


function productSearchResponse(request)
{

	/*
	//alert('TEST' + res.responseXML.documentElement.firstChild.innerText);

	while($('productList').hasChildNodes())
		$('productList').removeChild($('productList').firstChild);
		
	var tbody = document.createElement('tbody');
	alert("START");	
	for(i = 0; i < res.responseXML.documentElement.childNodes.length; i++)
	{ 
		tr = document.createElement('tr');
		td = document.createElement('td');
	//alert(res.responseXML.firstChild.childNodes[i].text);	
		td.appendChild = res.responseXML.documentElement.childNodes[i];
		tr.appendChild(td);
		tbody.appendChild(tr);
	}
	
	$('productList').appendChild(tbody);
	
	alert('END');
	*/
}








/********** END PRO7i CODE *****************/




function PopAddImage(toWhat,ID) {
  popup("/admin/add-image.php?to="+toWhat+"&id="+ID,800,600,'foo');
}

/**
 * Displays the specified URL in a new window with all menus, tools, and scrollbars
 *
 * @author  Dan Delaney     http://fluidmind.org/
 * @param   url             URL to display in the popup window
 * @param   width           (Optional) The width of the new popup window
 * @param   height          (Optional) The height of the new popup window
 * @param   windowName      (Optional) The name of the window
 */
function popup(url, width, height, windowName)
{
    // Default to a 700 x 500 window
    width = (!isNaN(width) ? width + '' : '700');
    height = (!isNaN(height) ? height + '' : '500');
    windowName = (windowName == undefined || windowName == '' ? 'popup' : windowName);

    // Create it
    var popUp = window.open(url, windowName, 'width=' + width + ',height=' + height + ',scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes,location=yes');

    // Bring it to the front
    if (typeof popUp == 'object') { popUp.focus(); }

    return false;
}  // popup()


function offsitePopup(url) {
    var popUp = window.open(url, 'offsiteWindow', 'width=800,height=500,scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes,location=yes');
    if (typeof popUp == 'object') {
        popUp.focus();
    }
}

function imagePopup(url, title) {
    var popUp = window.open(url, 'enlargementWindow', 'width=630,height=600,scrollbars=yes,resizable=yes,menubar=no,toolbar=no,location=no');
    if (typeof popUp == 'object') {
        popUp.focus();
    }
}

function popup(url, width, height) {
    var popUp = window.open(url, 'popupWindow', 'width=' + width + ',height=' + height + ',scrollbars=yes,resizable=yes,menubar=no,toolbar=no');
    if (typeof popUp == 'object') {
        popUp.focus();
    }
}


// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}


function globalOnLoad() {

    // Assign link events
    for (var i = 0; i < document.links.length; i++) {
        if (document.links[i].className.match('External')) {
            document.links[i].onclick = function() { offsitePopup(this.href); return false; }
        }
        if (document.links[i].className.match('Image')) {
            document.links[i].onclick = function() { imagePopup(this.href, this.title); return false; }
        }

	if (document.links[i].className.match('Popup')) {
            document.links[i].onclick = function() { popup(this.href, 400,400); return false; }
        }
    }

    // Run page onLoad function, if it exists
    if (typeof onLoad != 'undefined') {
        onLoad();
    }

}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}


addLoadEvent(globalOnLoad);
// Every page should assign events
//window.onload = globalOnLoad;
