﻿function MM_swapImgRestore() { //v3.0
	var i, x, a=document.MM_sr;
	for(i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) {
		x.src=x.oSrc;
	}
}

function MM_preloadImages() { //v3.0
	var d=document;
	if(d.images) {
		if(!d.MM_p) {
			d.MM_p=new Array();
		}
		var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
		for(i = 0; i < a.length; i++) {
			if(a[i].indexOf("#") != 0) {
				d.MM_p[j] = new Image;
				d.MM_p[j++].src = a[i];
			}
		}
	}
}

function MM_findObj(n, d) { //v4.01
	var p, i, x;
	if(!d) {
		d = document;
	}
	
	if((p = n.indexOf("?"))>0 && parent.frames.length) {
		d = parent.frames[n.substring(p+1)].document;
		n = n.substring(0,p);
	}

	
	if(!(x = d[n]) && d.all) {
		x = d.all[n];
	}
	
	for(i = 0; !x && i < d.forms.length; i++) {
		x=d.forms[i][n];
	}

	
	for(i = 0; !x && d.layers && i < d.layers.length; i++) {
		x = MM_findObj(n,d.layers[i].document);
	}
	
	if(!x && d.getElementById) {
		x = d.getElementById(n);

	}
	
	return x;
}

function MM_swapImage() { //v3.0
	var i, j = 0, x, a = MM_swapImage.arguments;
	document.MM_sr = new Array;
	for(i = 0; i < (a.length - 2); i += 3) {
		if((x = MM_findObj(a[i])) != null) {
			document.MM_sr[j++] = x;
			if(!x.oSrc) {
				x.oSrc = x.src;
			}
			x.src = a[i+2];
		}
	}
}

// To enable/disable the background:
function backgroundFilter(divId) {
	var divObj = false;
	if(document.getElementById) {
		// Standard way to get element
		divObj = document.getElementById(divId);
	}
	else if(document.all) {
		// Get the element in old IE's
		divObj = document.all[divId];
	}
	if(!divObj) {
		divObj = document.createElement('div');
		divObj.id = divId;
		document.body.appendChild(divObj);
	}
	// if the style.display value is blank we try to check it out here
	if(divObj.style.display == '' && divObj.offsetWidth != undefined && divObj.offsetHeight != undefined) {
		divObj.style.display = (divObj.offsetWidth != 0 && divObj.offsetHeight != 0) ? 'block' : 'none';
	}
	// If the background is hidden ('none') then it will display it ('block').
	// If the background is displayed ('block') then it will hide it ('none').
	divObj.style.display = (divObj.style.display == '' || divObj.style.display == 'block') ? 'none' : 'block';
	
	return false;
}

// To display/hide the popup:
function popUpDiv(divId) {
	var divObj = false;
	if(document.getElementById) {
		// Standard way to get element
		divObj = document.getElementById(divId);
	}
	else if(document.all) {
		// Get the element in old IE's
		divObj = document.all[divId];
	}
	
	if(!divObj) {
		divObj = document.createElement('div');
		divObj.id = divId;
		document.body.appendChild(divObj);
	}
	
	// if the style.display value is blank we try to check it out here
	if(divObj.style.display == '' && divObj.offsetWidth != undefined && divObj.offsetHeight != undefined) {
		divObj.style.display = (divObj.offsetWidth != 0 && divObj.offsetHeight != 0) ? 'block' : 'none';
	}
	// If the PopUp is hidden ('none') then it will display it ('block').
	// If the PopUp is displayed ('block') then it will hide it ('none').
	divObj.style.display = (divObj.style.display == '' || divObj.style.display == 'block') ? 'none' : 'block';
	
	return false;
}

function loading(objId, loadText) {
	if(loadText == undefined) {
		loadText = 'Loading';
	}
	obj = document.getElementById(objId);
	obj.style.display = 'block';
	oldHTML = obj.innerHTML;
	//alert(oldHTML);
	obj.innerHTML = loadText + oldHTML;

	t1 = setTimeout("addDot('"+objId+"')",800);
}

var numDots = 0;
function addDot(objId) {
	elemObj = document.getElementById(objId);
	//alert('testing ' + elemObj);
	if(elemObj) {
		//alert('testing ' + numDots);
		oldHTML = elemObj.innerHTML;
		if(numDots < 3) {
			elemObj.innerHTML = oldHTML + ".";
			numDots++;
		}
		else {
			elemObj.innerHTML = oldHTML.substr(0,(oldHTML.length - 3));
			numDots = 0;
		}
		var tempElem = elemObj;
		t = setTimeout("addDot('"+objId+"')",800);
	}
}

// This function will show and hide elements based on the id you pass into the function
function showhide(objid) {
	var obj = document.getElementById(objid);
	var s = obj.style.display;
	if(s == "block") {
		hideobj(objid);
	}
	else {
		showobj(objid);
	}
}

// This function will show or hide an element based on the id you pass in and whether it is currently visible or not
function toggleObj(objId) {
	var obj = document.getElementById(objId);
	if(obj.style.display != 'none') {
		obj.style.display = 'none';
	}
	else {
		obj.style.display = 'block';
	}
}

// THIS FUNCTION TOGGGLES A CHECKBOX
function toggleCheckbox(objId) {
	var obj = document.getElementById(objId);
	if(obj.checked) {
		obj.checked = false;
	} else {
		obj.checked = true;
	}
	
	return obj.checked;
}

// This function will show an element based on the id you pass in
function showobj(objid) {
	var obj = document.getElementById(objid);
	obj.style.display = "block";
}

// This function will hide an element based on the id you pass in
function hideobj(objid) {
	var obj = document.getElementById(objid);
	obj.style.display = "none";
}

// This function will check/uncheck all checkboxes based on the id you pass into the function
function checkChildBoxes(objId, childCount) {
	var i;
	
	var parentObj = document.getElementById(objId);
	if(parentObj) {
		isChecked = parentObj.checked;
	}
	else {
		isChecked = false;
	}
	
	for(i = 0; i <= childCount; i++) {
		var childObjId = objId + i;
		
		var childObj = document.getElementById(childObjId);
		if(childObj) {
			if(isChecked == true) {
				childObj.checked = true;
			}
			else {
				childObj.checked = false;
			}
		}
	}
}

// This function autofills shipping address with the fields from the rest of the form if the checkbox is checked
function populateShippingAddress(ischecked) {
	var address = document.getElementById('address');
	var city = document.getElementById('city');
	var state = document.getElementById('state');
	var zip = document.getElementById('zip');
	
	var shipaddress = document.getElementById('shipaddress');
	var shipcity = document.getElementById('shipcity');
	var shipstate = document.getElementById('shipstate');
	var shipzip = document.getElementById('shipzip');
	
	if(ischecked) {
		if(address && shipaddress) {
			shipaddress.value = address.value;
		}
		if(city && shipcity) {
			shipcity.value = city.value;
		}
		if(state && shipstate) {
			shipstate.value = state.value;
		}
		if(zip && shipzip) {
			shipzip.value = zip.value;
		}
	} else {
		if(shipaddress) {
			shipaddress.value = "";
		}
		if(shipcity) {
			shipcity.value = "";
		}
		if(shipstate) {
			shipstate.value = "";
		}
		if(shipzip) {
			shipzip.value = "";
		}
	}
}


// This function will check to see if the value of a form is equal to the condition you supplied
// If it is, it will show the objid you passed in, otherwise it will hide the element
function getSelectedValue(value,condition,objid) {
	if(value == condition) {
		showobj(objid);
	}
	else {
		hideobj(objid);
	}
}

function doSomething(value, condition, ifTrue, ifFalse) {
	if(value == condition) {
		eval(ifTrue);
	} else {
		eval(ifFalse);
	}
}

function addToHiddenList(objId, value) {
	var obj = document.getElementById(objId);
	
	stringList = obj.value;
	
	arrayList = stringList.split(',');
	
	var inArray = false;
	
	if(arrayList.length > 0) {
		for(var i = 0; i < arrayList.length; i++) {
			if(arrayList[i] == value) {
				inArray = true;
				break; // BREAK OUT OF THE LOOP NOW THAT WE FOUND OUT IT EXISTS
			}
		}
	}
	
	if(!inArray) {
		// IF THIS IS THE FIRST ITEM IN THE LIST, DON'T ADD A COMMA
		if(obj.value == '') {
			obj.value = value;
		} else {
			obj.value += ',' + value;
		}
	}
}

function removeFromHiddenList(objId, value) {
	var obj = document.getElementById(objId);
	
	stringList = obj.value;
	
	arrayList = stringList.split(',');
	
	var inArray = false;
	
	if(arrayList.length > 0) {
		for(var i = 0; i < arrayList.length; i++) {
			if(arrayList[i] == value) {
				arrayList.splice(i, 1);
				inArray = true;
				break; // BREAK OUT OF THE LOOP NOW THAT WE FOUND OUT IT EXISTS
			}
		}
	}
	
	if(inArray) {
		obj.value = arrayList.join(',');
	}
}

// This function will ask for delete confirmation of item id
// If they confirm it will send them to url, where if they have the correct permissions, the item will be deleted
function deletefromdb(id,url) {
	input_box=confirm("Are you sure you want to delete this?");
	
	if(input_box) {
		str1 = url.concat("task=delete&id=");
		str2 = str1.concat(id);
		window.location = str2;
	}
}

// This function sets the max length for the textarea object
function ismaxlength(obj) {
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}

function checkext(upload_field, formats, alertText) {
	if(formats == undefined) {
		formatRegex = /(\.jpeg|\.jpg|\.gif|\.png)$/i;
	}
	else if(formats.constructor == Array) {
		formatRegex = new RegExp('(\.' + formats.join('|\.') + ')$', 'i');
	} else if(formats.constructor == String) {
		formatsArr = formats.split(',');
		formatRegex = new RegExp('(\.' + formatsArr.join('|\.') + ')$', 'i');
	} else {
		formatRegex = /(\.jpeg|\.jpg|\.gif|\.png)$/i;
	}
	
	if(alertText == undefined) {
		alertText = "Please select a JPEG, GIF or PNG file.";
	}
	
	var filename = upload_field.value;
	/* Checking file type */
	if(filename.search(formatRegex) == -1) {
		alert(alertText);
		upload_field.value = '';
	}
	return true;
}

function remove(url, id, alertText) {
	if(alertText == undefined) {
		alertText = "Are you sure you want to remove this?";
	}
	
	input_box=confirm(alertText);
	
	if(input_box) {
		str1 = url.concat("task=remove&id=");
		str2 = str1.concat(id);
		window.location = str2;
	}
}

function confirm_action(url, action, id, alertText) {
	if(alertText == undefined) {
		alertText = "Are you sure you want to remove this?";
	}
	
	input_box=confirm(alertText);
	
	if(input_box) {
		str1 = url.concat("task=");
		str2 = str1.concat(action);
		str3 = str2.concat("&id=");
		str4 = str3.concat(id);
		window.location = str4;
	}
}

// This function will send a value from the child window to it's parent
function sendValue(fieldObjId, sendValue, closeWin) {
	fieldObj = window.opener.document.getElementById(fieldObjId);
	fieldObj.value = sendValue;
	if(closeWin == undefined || closeWin == true) {
		window.close();
	}
}

function showSubNav(parentObj) {
	childNodeLength = parentObj.childNodes.length;
	for(i = 0; i < childNodeLength; i++) {
		if(parentObj.childNodes[i].className == 'subNav') {
			parentObj.childNodes[i].style.display = 'block';
		}
	}
}

function hideSubNav(parentObj) {
	childNodeLength = parentObj.childNodes.length;
	for(i = 0; i < childNodeLength; i++) {
		if(parentObj.childNodes[i].className == 'subNav') {
			parentObj.childNodes[i].style.display = 'none';
		}
	}
}

function sendValueAndSwapImage(fieldObjId, sendValue, imageObjId, imagePath, closeWin) {
	fieldObj = window.opener.document.getElementById(fieldObjId);
	fieldObj.value = sendValue;
	imageObj = window.opener.document.getElementById(imageObjId);
	
	if(imageObj) {
		imageObj.src = imagePath + sendValue;
		if(sendValue == null) {
			imageObj.parentNode.removeChild(imageObj);
		}
	}
	else {
		if(sendValue != null) {
			imageObj = window.opener.document.createElement('img');
			fieldObj.parentNode.appendChild(imageObj);
			imageObj.src = imagePath + sendValue;
			imageObj.id = imageObjId;
		}
	}
	if(closeWin == undefined || closeWin == true) {
		window.close();
	}
}

function swapImage(imageObjId, imagePath) {
	imageObj = document.getElementById(imageObjId);
	if(imageObj) {
		imageObj.src = imagePath;
	}
	
	return false;
}

function populateAddressFields(objIdPrefix, selectObj, addressArray) {
	var selectedAddress = '';
	// DON'T PUT QUOTES AROUND THE CONSTRUCTOR VALUE BECAUSE IT WON'T WORK!
	if(addressArray.constructor == Array && selectObj.nodeName == 'SELECT') {
		addressNameFieldId = objIdPrefix + '_AddressName';
		emailFieldId = objIdPrefix + '_Email';
		titleFieldId = objIdPrefix + '_Title';
		firstnameFieldId = objIdPrefix + '_FirstName';
		miFieldId = objIdPrefix + '_MI';
		lastnameFieldId = objIdPrefix + '_LastName';
		fullnameFieldId = objIdPrefix + '_FullName';
		companyFieldId = objIdPrefix + '_Company';
		address1FieldId = objIdPrefix + '_AddressLine1';
		address2FieldId = objIdPrefix + '_AddressLine2';
		cityFieldId = objIdPrefix + '_City';
		stateFieldId = objIdPrefix + '_State';
		zipFieldId = objIdPrefix + '_Zip';
		countryFieldId = objIdPrefix + '_Country';
		phoneFieldId = objIdPrefix + '_Phone';
		faxFieldId = objIdPrefix + '_Fax';
		extrafield1FieldId = objIdPrefix + '_ExtraField1';
		extrafield2FieldId = objIdPrefix + '_ExtraField2';
		extrafield3FieldId = objIdPrefix + '_ExtraField3';
		extrafield4FieldId = objIdPrefix + '_ExtraField4';
		extrafield5FieldId = objIdPrefix + '_ExtraField5';
		
		// GET THE CORRECT ADDRESS FOR THE ONE SELECTED
		tempIndex = selectObj.selectedIndex;
		// IF AN ADDRESS IS SELECTED, AND NOT JUST THE FIRST OPTION
		if(tempIndex > 0) {
			addressId = selectObj.options[tempIndex].value;
			
			for(i = 0; i < addressArray.length; i++) {
				if(addressArray[i]['id'] == addressId) {
					selectedAddress = addressArray[i];
					break;
				}
			}
		}
		
		addressNameObj = document.getElementById(addressNameFieldId);
		if(addressNameObj) {
			addressNameObj.value = selectedAddress['name'];
		}
		
		emailObj = document.getElementById(emailFieldId);
		if(emailObj) {
			emailObj.value = selectedAddress['email'];
		}
		
		titleObj = document.getElementById(titleFieldId);
		if(titleObj) {
			titleObj.value = selectedAddress['title'];
		}
		
		firstnameObj = document.getElementById(firstnameFieldId);
		if(firstnameObj) {
			firstnameObj.value = selectedAddress['firstname'];
		}
		
		miObj = document.getElementById(miFieldId);
		if(miObj) {
			miObj.value = selectedAddress['mi'];
		}
		
		lastnameObj = document.getElementById(lastnameFieldId);
		if(lastnameObj) {
			lastnameObj.value = selectedAddress['lastname'];
		}
		
		fullnameObj = document.getElementById(fullnameFieldId);
		if(fullnameObj) {
			fullnameObj.value = selectedAddress['firstname'] + ' ' + selectedAddress['lastname'];
		}
		
		companyObj = document.getElementById(companyFieldId);
		if(companyObj) {
			companyObj.value = selectedAddress['company'];
		}
		address1Obj = document.getElementById(address1FieldId);
		if(address1Obj) {
			address1Obj.value = selectedAddress['address'];
		}
		
		address2Obj = document.getElementById(address2FieldId);
		if(address2Obj) {
			address2Obj.value = selectedAddress['address2'];
		}
		
		cityObj = document.getElementById(cityFieldId);
		if(cityObj) {
			cityObj.value = selectedAddress['city'];
		}
		
		stateObj = document.getElementById(stateFieldId);
		if(stateObj) {
			stateObj.value = selectedAddress['state'];
		}
		
		zipObj = document.getElementById(zipFieldId);
		if(zipObj) {
			zipObj.value = selectedAddress['zip'];
		}
		
		countryObj = document.getElementById(countryFieldId);
		if(countryObj) {
			countryObj.value = selectedAddress['country'];
		}
		
		phoneObj = document.getElementById(phoneFieldId);
		if(phoneObj) {
			phoneObj.value = selectedAddress['phone'];
		}
		
		faxObj = document.getElementById(faxFieldId);
		if(faxObj) {
			faxObj.value = selectedAddress['fax'];
		}
		
		extrafield1Obj = document.getElementById(extrafield1FieldId);
		if(extrafield1Obj) {
			extrafield1Obj.value = selectedAddress['extrafield1'];
		}
		
		extrafield2Obj = document.getElementById(extrafield2FieldId);
		if(extrafield2Obj) {
			extrafield2Obj.value = selectedAddress['extrafield2'];
		}
		
		extrafield3Obj = document.getElementById(extrafield3FieldId);
		if(extrafield3Obj) {
			extrafield3Obj.value = selectedAddress['extrafield3'];
		}
		
		extrafield4Obj = document.getElementById(extrafield4FieldId);
		if(extrafield4Obj) {
			extrafield4Obj.value = selectedAddress['extrafield4'];
		}
		
		extrafield5Obj = document.getElementById(extrafield5FieldId);
		if(extrafield5Obj) {
			extrafield5Obj.value = selectedAddress['extrafield5'];
		}
	} else {
		if(addressArray.constructor != Array) {
			alert('Third parameter was not an array. ' + addressArray.constructor + ' provided instead.');
		} else {
			alert('Second parameter was not an instanceof a select html object. ' + selectObj.nodeName + ' provided instead.');
		}
	}
}


/*
   Creates an html attribute.
   @param name the name of the attribute.
   @param value the (string) value of the attribute.
   @return the newly created html attribute
*/
function createHTMLAttribute(name, value) {
   var attribute = document.createAttribute(name);
   attribute.nodeValue = value;
   return attribute;
}

// BEHAVES SIMILARLY TO PHP'S PRINT_R FUNCTION
function print_r(theObj){
	var output = "";
	if(theObj.constructor == Array || theObj.constructor == Object) {
		output = "<ul>";
		for(var p in theObj) {
			if(theObj[p].constructor == Array || theObj[p].constructor == Object) {
				output += "<li>["+p+"] => "+typeof(theObj)+"</li>";
				output += "<ul>";
				output += print_r(theObj[p]);
				output += "</ul>";
			} else {
				output += "<li>["+p+"] => "+theObj[p]+"</li>";
			}
		}
		output += "</ul>";
	}
	else {
		output += theObj;
	}
	
	return output;
}

function nl2br (str, is_xhtml) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Philip Peterson
    // +   improved by: Onno Marsman
    // +   improved by: Atli Þór
    // +   bugfixed by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: Maximusya
    // *     example 1: nl2br('Kevin\nvan\nZonneveld');
    // *     returns 1: 'Kevin<br />\nvan<br />\nZonneveld'
    // *     example 2: nl2br("\nOne\nTwo\n\nThree\n", false);
    // *     returns 2: '<br>\nOne<br>\nTwo<br>\n<br>\nThree<br>\n'
    // *     example 3: nl2br("\nOne\nTwo\n\nThree\n", true);
    // *     returns 3: '<br />\nOne<br />\nTwo<br />\n<br />\nThree<br />\n'

    var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';

    return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
}

function urlencode(str) {
    // URL-encodes string  
    // 
    // version: 911.718
    // discuss at: http://phpjs.org/functions/urlencode    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: travc
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Lars Fischer    // +      input by: Ratheous
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Joris
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // %          note 1: This reflects PHP 5.3/6.0+ behavior    // %        note 2: Please be aware that this function expects to encode into UTF-8 encoded strings, as found on
    // %        note 2: pages served as UTF-8
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
    str = (str+'').toString();
        // Tilde should be allowed unescaped in future versions of PHP (as reflected below), but if you want to reflect current
    // PHP behavior, you would need to add ".replace(/~/g, '%7E');" to the following.
    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
                                                                    replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}

function urldecode(str) {
    // Decodes URL-encoded string  
    // 
    // version: 911.718
    // discuss at: http://phpjs.org/functions/urldecode    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)    // +      input by: travc
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Lars Fischer
    // +      input by: Ratheous    // +   improved by: Orlando
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // %        note 1: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // %        note 2: Please be aware that this function expects to decode from UTF-8 encoded strings, as found on
    // %        note 2: pages served as UTF-8    // *     example 1: urldecode('Kevin+van+Zonneveld%21');
    // *     returns 1: 'Kevin van Zonneveld!'
    // *     example 2: urldecode('http%3A%2F%2Fkevin.vanzonneveld.net%2F');
    // *     returns 2: 'http://kevin.vanzonneveld.net/'
    // *     example 3: urldecode('http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a');    // *     returns 3: 'http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a'
    
    return decodeURIComponent(str).replace(/\+/g, ' ');
}

function removeOption(selectObjId, callbackFunc) {
	// GET THE SELECT OBJECT
	selectObj = document.getElementById(selectObjId);
	
	if(selectObj) {
		tempIndex = selectObj.selectedIndex;
		// IF AN OPTION IS SELECTED
		if(tempIndex >= 0) {
			selectObj.remove(tempIndex);
		}
	}
	
	if(callbackFunc != undefined) {
		eval(callbackFunc);
	}
}

function moveOptionUp(selectObjId, callbackFunc) {
	// GET THE SELECT OBJECT
	selectObj = document.getElementById(selectObjId);
	
	if(selectObj) {
		tempIndex = selectObj.selectedIndex;
		// IF AN OPTION IS SELECTED
		if(tempIndex > 0) {
			movedownOptionObj = selectObj.options[(tempIndex - 1)];
			moveupOptionObj = selectObj.options[tempIndex];
			// IF BOTH ARE REGULAR OPTIONS AND NOT IN AN OPTION GROUP
			if(moveupOptionObj.parentNode.nodeName == 'SELECT' && movedownOptionObj.parentNode.nodeName == 'SELECT') {
				try {
					selectObj.add(moveupOptionObj,movedownOptionObj);
				}
				catch(e) { // IE ONLY
					selectObj.remove(moveupOptionObj.index);
					selectObj.add(moveupOptionObj,movedownOptionObj.index);
				}
			}
			else {
				// IF THE ONE THAT IS MOVING UP IS A REGULAR OPTION
				if(moveupOptionObj.parentNode.nodeName == 'SELECT') {
					// GET THE OPTION GROUP FOR THE ONE THAT IS MOVING DOWN
					optGroupId = movedownOptionObj.parentNode.attributes.name.nodeValue;
					optGroupObj = document.getElementById(optGroupId);
					// THEN FIGURE OUT WHICH OPTION IS FIRST IN THAT GROUP
					tempOptionsArr = optGroupObj.childNodes;
					for(i = 0; i < tempOptionsArr.length; i++) {
						if(tempOptionsArr[i].nodeName == 'OPTION') {
							tempFirstOptionObj = tempOptionsArr[i];
							// THEN ADD IT ABOVE THAT OPTION
							//selectObj.add(moveupOptionObj,tempFirstOptionObj); // was putting in optgroup
							break;
						}
					}
				}
				// ELSE IF THE ONE THAT IS MOVING DOWN IS A REGULAR OPTION
				else if(movedownOptionObj.parentNode.nodeName == 'SELECT') {
					// GET THE OPTION GROUP FOR THE ONE THAT IS MOVING UP
					optGroupId = moveupOptionObj.parentNode.attributes.name.nodeValue;
					optGroupObj = document.getElementById(optGroupId);
					// THEN FIGURE OUT WHICH OPTION IS LAST IN THAT GROUP
					tempOptionsArr = optGroupObj.childNodes;
					for(i = 0; i < tempOptionsArr.length; i++) {
						if(tempOptionsArr[i].nodeName == 'OPTION') {
							tempFirstOptionObj = tempOptionsArr[i];
							// THEN ADD THAT OPTION ABOVE IT
							//selectObj.add(tempFirstOptionObj, movedownOptionObj); // was putting in optgroup
							break;
						}
					}
				}
				// ELSE BOTH ARE IN OPTION GROUPS
				else {
					moveupOptGroupId = moveupOptionObj.parentNode.attributes.name.nodeValue;
					movedownOptGroupId = movedownOptionObj.parentNode.attributes.name.nodeValue;
					// IF THEY ARE IN THE SAME OPTION GROUP JUST MOVE THEM
					if(moveupOptGroupId == movedownOptGroupId) {
						try {
							selectObj.add(moveupOptionObj,movedownOptionObj);
						}
						catch(e) { // IE ONLY
							selectObj.remove(moveupOptionObj.index);
							selectObj.add(moveupOptionObj,movedownOptionObj.index);
						}
					}
					// ELSE THEY ARE IN DIFFERENT OPTION GROUPS LEAVE THEM ALONE
				}
			}
		}
	}
	
	if(callbackFunc != undefined) {
		eval(callbackFunc);
	}
}

function moveOptionDown(selectObjId, callbackFunc) {
	selectObj = document.getElementById(selectObjId);
	
	if(selectObj) {
		tempIndex = selectObj.selectedIndex;
		if(tempIndex < (selectObj.options.length - 1)) {
			moveupOptionObj = selectObj.options[(tempIndex + 1)];
			movedownOptionObj = selectObj.options[tempIndex];
			// IF BOTH ARE REGULAR OPTIONS AND NOT IN AN OPTION GROUP
			if(moveupOptionObj.parentNode.nodeName == 'SELECT' && movedownOptionObj.parentNode.nodeName == 'SELECT') {
				try {
					selectObj.add(moveupOptionObj,movedownOptionObj);
				}
				catch(e) { // IE ONLY
					selectObj.remove(moveupOptionObj.index);
					selectObj.add(moveupOptionObj,movedownOptionObj.index);
				}
			}
			else {
				// IF THE ONE THAT IS MOVING UP IS A REGULAR OPTION
				if(moveupOptionObj.parentNode.nodeName == 'SELECT') {
					// GET THE OPTION GROUP FOR THE ONE THAT IS MOVING DOWN
					optGroupId = movedownOptionObj.parentNode.attributes.name.nodeValue;
					optGroupObj = document.getElementById(optGroupId);
					// THEN FIGURE OUT WHICH OPTION IS FIRST IN THAT GROUP
					tempOptionsArr = optGroupObj.childNodes;
					for(i = 0; i < tempOptionsArr.length; i++) {
						if(tempOptionsArr[i].nodeName == 'OPTION') {
							tempFirstOptionObj = tempOptionsArr[i];
							// THEN ADD IT ABOVE THAT OPTION
							//selectObj.add(moveupOptionObj,tempFirstOptionObj); // was putting in optgroup
							break;
						}
					}
				}
				// ELSE IF THE ONE THAT IS MOVING DOWN IS A REGULAR OPTOIN
				else if(movedownOptionObj.parentNode.nodeName == 'SELECT') {
					// GET THE OPTION GROUP FOR THE ONE THAT IS MOVING UP
					optGroupId = moveupOptionObj.parentNode.attributes.name.nodeValue;
					optGroupObj = document.getElementById(optGroupId);
					// THEN FIGURE OUT WHICH OPTION IS LAST IN THAT GROUP
					tempOptionsArr = optGroupObj.childNodes;
					for(i = 0; i < tempOptionsArr.length; i++) {
						if(tempOptionsArr[i].nodeName == 'OPTION') {
							tempFirstOptionObj = tempOptionsArr[i];
							// THEN ADD THAT OPTION ABOVE IT
							//selectObj.add(tempFirstOptionObj, movedownOptionObj); // was putting in optgroup
							break;
						}
					}
				}
				// ELSE BOTH ARE IN OPTION GROUPS
				else {
					moveupOptGroupId = moveupOptionObj.parentNode.attributes.name.nodeValue;
					movedownOptGroupId = movedownOptionObj.parentNode.attributes.name.nodeValue;
					// IF THEY ARE IN THE SAME OPTION GROUP JUST MOVE THEM
					if(moveupOptGroupId == movedownOptGroupId) {
						try {
							selectObj.add(moveupOptionObj,movedownOptionObj);
						}
						catch(e) { // IE ONLY
							selectObj.remove(moveupOptionObj.index);
							selectObj.add(moveupOptionObj,movedownOptionObj.index);
						}
					}
					// ELSE THEY ARE IN DIFFERENT OPTION GROUPS LEAVE THEM ALONE
				}
			}
		}
	}
	
	if(callbackFunc != undefined) {
		eval(callbackFunc);
	}
}


// This function will open the specified url in a new window
function popup(winLink, winName, winWidth, winHeight, winResize, winScroll, winMenu) {
	if(winWidth == undefined || winWidth == NaN) {
		winWidth = 400;
	}
	if(winHeight == undefined || winHeight == NaN) {
		winHeight = 400;
	}
	if(winResize == undefined || (winResize != "yes" && winResize != "no" && winResize.constructor != Boolean)) {
		winResize = "yes";
	}
	if(winScroll == undefined || (winScroll != "yes" && winScroll != "no" && winScroll.constructor != Boolean)) {
		winScroll = "yes";
	}
	if(winMenu == undefined || (winMenu != "yes" && winMenu != "no" && winMenu.constructor != Boolean)) {
		winMenu = "no";
	}
	if(!window.focus) {
		return true;
	}
	var winURL;
	if(typeof(winLink) == 'string') {
		winURL=winLink;
	}
	else {
		winURL=winLink.href;
	}
	var winStyle;
	winStyle = 'width=' + winWidth + ',height=' + winHeight + ',scrollbars=' + winScroll + ',menubar=' + winMenu + ',location=' + winMenu + ',toolbar=' + winMenu + ',resizeable=' + winResize;
	window.open(winURL, winName, winStyle);
	
	return false;
}

function getHTTPObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}


