function move_to_center(window_handle, body_width, body_height)
{
	var x = 0;
	var y = 0;
	var screen_width = screen.availWidth;
	var screen_height = screen.availHeight;
	if (screen_width > body_width)
		x = ((screen_width / 2) - (body_width / 2));
	if ( screen_height > body_height )
		y = ((screen_height / 2) - (body_height / 2));
	
	window_handle.moveTo(x, y - 50);
}

function isValidEmail(email)
{
    return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email);
}

//modified version of http://www.webmasterworld.com/forum91/4686.htm
//myField accepts an object reference, myValue accepts the text string to add
function insertAtCursor(myField, myValue) {
  //IE support
  if (document.selection) {
	  myField.focus();

	  //in effect we are creating a text range with zero
	  //length at the cursor location and replacing it
	  //with myValue
	  sel = document.selection.createRange();
	  sel.text = myValue;

  //Mozilla/Firefox/Netscape 7+ support
  } else if (myField.selectionStart || myField.selectionStart == '0') {

	 myField.focus();
	  //Here we get the start and end points of the
	  //selection. Then we create substrings up to the
	  //start of the selection and from the end point
	  //of the selection to the end of the field value.
	  //Then we concatenate the first substring, myValue,
	  //and the second substring to get the new value.
	  var startPos = myField.selectionStart;
	  var endPos = myField.selectionEnd;
	  myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
	  myField.setSelectionRange(endPos+myValue.length, endPos+myValue.length);
  } else {
	  myField.value += myValue;
  }
}

function trim(stringToTrim) {
    return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function strpos( haystack, needle, offset){
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: strpos('Kevin van Zonneveld', 'e', 5);
    // *     returns 1: 14
 
    var i = haystack.indexOf( needle, offset ); // returns -1
    return i >= 0 ? i : false;
}

function is_array( mixed_var ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Legaev Andrey
    // +   bugfixed by: Cord
    // *     example 1: is_array(['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: true
    // *     example 2: is_array('Kevin van Zonneveld');
    // *     returns 2: false
 
    return ( mixed_var instanceof Array );
}

function str_replace(search, replace, subject) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni
    // +   improved by: Philip Peterson
    // +   improved by: Simon Willison (http://simonwillison.net)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // -    depends on: is_array
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'
    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    // *     returns 2: 'hemmo, mars'    
    
    var f = search, r = replace, s = subject;
    var ra = is_array(r), sa = is_array(s), f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
 
    while (j = 0, i--) {
        while (s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
    };
     
    return sa ? s : s[0];
}

Array.prototype.in_array = function(needle)
{
	var i = this.length;
	if (i > 0) {
		do {
			if (this[i] === needle) {
				return true;
			}
		} while (i--);
	}
	return false;
}

function get_base_url(values, exclude)
{
	var url = new String(window.location);
	var url_array = url.split(/\?/);
	var get = url_array[1] ? url_array[1] : "";
	var base_get = "";
	var amp = "";
	
	get_array = get.split(/&/);
	for (i = 0; i < get_array.length; i++) {
		if (values.in_array(get_array[i].split(/=/)[0])) {
			if (!exclude) {1
				base_get += amp + get_array[i];
				amp = "&";
			}
		} else {
			if (exclude) {
				base_get += amp + get_array[i];
				amp = "&";
			}
		}
	}
	
	if (base_get == "") {
		return url_array[0];
	} else {
		return url_array[0] + "?" + base_get;
	}
}

function shadow()
{
    var nav = document.getElementById('navigation');
    var items = nav.getElementsByTagName('li').length;
    var i;
    for (i = 0; i < items; i++) {
	var itemName = nav.getElementsByTagName('li')[i].getElementsByTagName('a')[0].innerHTML;
	nav.getElementsByTagName('li')[i].getElementsByTagName('a')[0].innerHTML = '<span>' + itemName + '</' + 'span>' + itemName;
    }
}

