function confirmDeleteSubmit(val)
{
highlight(val);
var agree=confirm("Do you wish to delete the selected record ?");
if (agree)
        return true ;
else
	{
	    unhighlight(val);
        return false ;
	}
}

function confirmInactiveSubmit(val)
{
highlight(val);
var agree=confirm("Do you wish to inactive the selected record ?");
if (agree)
        return true ;
else
	{
	    unhighlight(val);
        return false ;
	}
}

function confirmActiveSubmit(val)
{
highlight(val);
var agree=confirm("Do you wish to activate the selected record ?");
if (agree)
        return true ;
else
	{
	    unhighlight(val);
        return false ;
	}
}
function highlight(row)
{
document.getElementById("row"+row).className= "deleteRow";
}
function unhighlight(row)
{
document.getElementById("row"+row).className= "Row";
}

function isEmailAddr(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
        result = true;
  }
  return result;
}

function validRequired(formField,fieldLabel)
{
        var result = true;

        if (formField.value == "")
        {
                alert('Please enter a value for the "' + fieldLabel +'" field.');
                formField.focus();
                result = false;
        }

        return result;
}

function allDigits(str)
{
        return inValidCharSet(str,"0123456789");
}

function inValidCharSet(str,charset)
{
        var result = true;

        // Note: doesn't use regular expressions to avoid early Mac browser bugs
        for (var i=0;i<str.length;i++)
                if (charset.indexOf(str.substr(i,1))<0)
                {
                        result = false;
                        break;
                }

        return result;
}

function validEmail(formField,fieldLabel,required)
{
        var result = true;

    /*    if (required && !validRequired(formField,fieldLabel))
                result = false;  */

        if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
        {
                alert("Please enter a complete email address in the form: yourname@yourdomain.com");
                formField.focus();
                result = false;
        }

  return result;

}

function validNum(formField,fieldLabel,required)
{
        var result = true;

    /*    if (required && !validRequired(formField,fieldLabel))
                result = false;  */

         if (result)
         {
                 if (!allDigits(formField.value))
                 {
                         alert('Please enter a number for the "' + fieldLabel +'" field.');
                        formField.focus();
                        result = false;
                }
        }

        return result;
}


function validInt(formField,fieldLabel,required)
{
        var result = true;

        if (required && !validRequired(formField,fieldLabel))
                result = false;

         if (result)
         {
                 if (isNaN(formField.value))
                 {
                         alert('Please enter a number for the "' + fieldLabel +'" field.');
                        formField.focus();
                        result = false;
                }
        }

        return result;
}


function validDate(formField,fieldLabel,required)
{
        var result = true;

        if (required && !validRequired(formField,fieldLabel))
                result = false;

         if (result)
         {
                 var elems = formField.value.split("/");

                 result = (elems.length == 3); // should be three components

                 if (result)
                 {
                         var month = parseInt(elems[0],10);
                          var day = parseInt(elems[1],10);
                         var year = parseInt(elems[2],10);
                        result = allDigits(elems[0]) && (month > 0) && (month < 13) &&
                                         allDigits(elems[1]) && (day > 0) && (day < 32) &&
                                         allDigits(elems[2]) && ((elems[2].length == 2) || (elems[2].length == 4));
                 }

                  if (!result)
                 {
                         alert('Please enter a date in the format MM/DD/YYYY for the "' + fieldLabel +'" field.');
                        formField.focus();
                }
        }

        return result;
}

// Set status bar -------------------------------------
function setStatusBarMsg(msg) {
	window.status = msg;
}



// Display date --------------------------------------
function displayDate() {

	var months = new Array(12);
	months[1] = "January";
	months[2] = "February";
	months[3] = "March";
	months[4] = "April";
	months[5] = "May";
	months[6] = "June";
	months[7] = "July";
	months[8] = "August";
	months[9] = "September";
	months[10] = "October";
	months[11] = "November";
	months[12] = "December";

	var dateObj = new Date()
	var lmonth = months[dateObj.getMonth() + 1]
	var date = dateObj.getDate()
	var year = dateObj.getYear()
	var endYear = year.toString()

	if(document.all) {
		var endYear = endYear.substring(2,4)
	} else {
		var endYear = endYear.substring(1,3)
	}

	document.write(lmonth + " " + date + ", " + " 20" + endYear)

}

// end display date


// email validation -------------------------------------------------------

function emailCheck(emailStr) {
   var emailPat=/^(.+)@(.+)$/
   var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
   var validChars="\[^\\s" + specialChars + "\]"
   var quotedUser="(\"[^\"]*\")"
   var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
   var atom=validChars + '+'
   var word="(" + atom + "|" + quotedUser + ")"
   var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
   var matchArray=emailStr.match(emailPat)
   if (matchArray==null) {
		alert("The email address you have entered seems incorrect (check @, dots and spaces).");
		return false;
	}
   var user=matchArray[1]
   var domain=matchArray[2]

   if (user.match(userPat)==null) {
		alert("Check email address (no blank spaces).")
		return false
	}

	if(emailStr.indexOf("'")!=-1) {
		alert("Apostrophes are not permitted in email addresses.");
		return false;
	}

	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Destination IP address is invalid!")
				return false
	   	}
		}
      return true
	}

	//check for trailing chars on domain
	if ((domain.substring(domain.length-1,domain.length) == ' ') || (domain.substring(domain.length-1,domain.length) == '\n') || (domain.substring(domain.length-1,domain.length) == '\r'))
	{
		domain = domain.substring(0,domain.length-1);
	}
  	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("The email domain name doesn't seem to be valid.\n\nPlease make sure there are no spaces before or after the email address.")
    	return false
	}

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>6) {
		alert("Invalid domain name - please check the email address.")
		return false
	}

	if (len<2) {
		var errStr="This email address is missing a hostname!"
 		alert(errStr)
 		return false
	}

	return true;
}

// end email validation


// Open a Popup Window

function openWin(win_url, win_name, win_width, win_height, win_scroll) {

	win_attrib='toolbar=no,location=no,directories=no,menubar=no,resizable,scrollbars=' + win_scroll + ',width=' + win_width + ',height=' + win_height + ',';
	win_left=(screen.width-win_width)/2;
	win_top = ((screen.height-win_height)/2)-50;
    if (navigator.appName.indexOf("Microsoft")>=0) {
		win_attrib+='left=' + win_left + ',top=' + win_top;
    } else {
    	win_attrib+='screenX=' + win_left + ',screenY=' + win_top;
    }
    if(win_name=="send2box")
    {
    stb_processing_cookie = getCookie('stb_processing');
    if (stb_processing_cookie == 'processing') {
	alert("Files are currently being sent to the set top box. Please wait until this transfer is complete before sending another file.");
	return;
    }
    }

	if(win_name=="send2box")
	{
   	var newWin = window.open("",win_name,win_attrib);
    var current_url=newWin.location.href;
    if(countStr(current_url,"fssendtobox.html")>0)
	{
	alert("Files are currently being sent to the set top box. Please wait until this transfer is complete before sending another file.");
	return;
	}
	else
	{
	newWin.location.href=win_url;
	newWin.focus();
	}


	}
	else
	{
	var newWin = window.open("",win_name,win_attrib);
   	newWin.location.href=win_url;
	newWin.focus();

  }


//return true;
}


// check selection of a drop down list

function checkSelection(what,msg) {
	eval("var selected = document."+what+".options[document."+what+".selectedIndex].value");
	if ((selected == 0) || (selected == "")) {
		alert(msg);
		return false;
	}
}



// confirm delete of an item from archive / approval area
function confirmDeleteFile() {

	var message = "Are you sure you want to delete this item?\n";
	var return_value = confirm(message);
	if (return_value == true) {
		return true;
	} else {
		return false;
	}
}


// date validation functions ---------------------------------------------------

function checkDate(datein) {

	var inputStr = datein;
	while (inputStr.indexOf("-") != -1) {
		inputStr = replaceString("-","/", inputStr);
   }
   var delim1 = inputStr.indexOf("/");
   var delim2 = inputStr.lastIndexOf("/");
	if (delim1 != -1 && delim1 == delim2) {
		alert("A date entry is not in an acceptable format.\n\nYou can enter dates in the following format: dd-mm-yyyy.");
		return false;
	}
   if (delim1 != -1) {
		var dd = parseInt(inputStr.substring(0,delim1),10);
		var mm = parseInt(inputStr.substring(delim1 + 1,delim2),10);
		var yyyy = parseInt(inputStr.substring(delim2 + 1, inputStr.length),10);
	} else {
		var mm = parseInt(inputStr.substring(0,2),10);
		var dd = parseInt(inputStr.substring(2,4),10);
		var yyyy = parseInt(inputStr.substring(4,inputStr.length),10);
   }
   if (isNaN(mm) || isNaN(dd) || isNaN(yyyy)) {
		alert("A date entry is not in an acceptable format.\n\nYou can enter dates in the following format: dd-mm-yyyy.");
		return false;
   }
   if (mm < 1 || mm > 12) { // month value is not 1 thru 12
		alert("Months must be entered between the range of 01 (January) and 12 (December).");
		return false;
   }
   if (dd < 1 || dd > 31) {
		alert("Days must be entered between the range of 01 and a maximum of 31 (depending on the month and year).");
		return false;
   }
   if (yyyy < 100) { // entered value is two digits, which we allow for 1930-2029
		if (yyyy >= 30) {
	    	yyyy += 1900;
		} else {
	    	yyyy += 2000;
		}
   }
   if (!checkMonthLength(mm,dd)) {
		return false;
   }
   if (mm == 2) {
		if (!checkLeapMonth(mm,dd,yyyy)) {
	    	return false;
		}
   }
	return true;
}

// check the entered month for too high a value
function checkMonthLength(mm,dd) {
	var months = new Array("","January","February","March","April","May","June","July","August","September","October","November","December");
   if ((mm == 4 || mm == 6 || mm == 9 || mm == 11) && dd > 30) {
		alert(months[mm] + " has only 30 days.");
		return false;
	} else if (dd > 31) {
		alert(months[mm] + " has only 31 days.");
		return false;
	}
	return true;
}

// check the entered February date for too high a value
function checkLeapMonth(mm,dd,yyyy) {
   if (yyyy % 4 > 0 && dd > 28) {
		alert("February of " + yyyy + " has only 28 days.");
		return false;
	} else if (dd > 29) {
		alert("February of " + yyyy + " has only 29 days.");
		return false;
   }
   return true;
}

function replaceString(oldS,newS,fullS) {
// Replaces oldS with newS in the string fullS
	for (var i=0; i<fullS.length; i++) {
		if (fullS.substring(i,i+oldS.length) == oldS) {
	   	fullS = fullS.substring(0,i)+newS+fullS.substring(i+oldS.length,fullS.length)
	   }
   }
	return fullS
}


function compareDates(string1,string2) {
//first thing is to split them into dates again
	var sep = '-';
   var bitsofdate1;
   var bitsofdate2;
   bitsofdate1 = string1.split(sep);
   bitsofdate2 = string2.split(sep);
	date1obj = new Date(bitsofdate1[2], bitsofdate1[1], bitsofdate1[0]);
	date2obj = new Date(bitsofdate2[2], bitsofdate2[1], bitsofdate2[0]);

   if (date1obj > date2obj) {
		alert("Start Date greater than End Date");
      return false
   }
	return true;
}

function is_numeric(sText) {
	var ValidChars = "0123456789.";
	var Char;
	if(sText == null) return false;
	if(sText == "") return false;
	for(i=0; i<sText.length; i++) {
		Char = sText.charAt(i);
		if(ValidChars.indexOf(Char) == -1) return false;
	}
	return true;
}

var ns = (navigator.userAgent.indexOf("MSIE") < 0) ? true : false;



function show(e) {
	if (document.getElementById) {
		// this is the way the standards work
		if(document.getElementById(e) != null) {
			document.getElementById(e).style.visibility = "visible";
			document.getElementById(e).style.display = "";
		}
	} else if (document.all) {
		// this is the way old msie versions work
		if(document.all[e] != null ) {
			document.all[e].style.visibility = "visible";
			document.all[e].style.display = "";
		}
	} else if (document.layers) {
		// this is the way nn4 works
		if(document.layers[e] != null) document.layers[e].visibility = "visible";
	}
}

function enableControl(e) {

	if (document.getElementById) {
		// this is the way the standards work
		if(document.getElementById(e) != null) {
			document.getElementById(e).disabled = false;

		}
	} else if (document.all) {
		// this is the way old msie versions work
		if(document.all[e] != null ) {
			document.all[e].disabled = false;

		}
	} else if (document.layers) {
		// this is the way nn4 works
		if(document.layers[e] != null) document.layers[e].disabled = false;
	}

}


function disableControl(e) {
	if (document.getElementById) {
		// this is the way the standards work
		if(document.getElementById(e) != null) {
			document.getElementById(e).disabled = true;

		}
	} else if (document.all) {
		// this is the way old msie versions work
		if(document.all[e] != null ) {
			document.all[e].disabled = true;

		}
	} else if (document.layers) {
		// this is the way nn4 works
		if(document.layers[e] != null) document.layers[e].disabled = true;
	}
}

function hide(e) {

	if (document.getElementById) {
		if(document.getElementById(e) != null) {
			// this is the way the standards work
			document.getElementById(e).style.visibility = "hidden";
			document.getElementById(e).style.display = "none";
		}
	} else if (document.all) {
		// this is the way old msie versions work
		if(document.all[e] != null ) {
			document.all[e].style.visibility = "hidden";
			document.all[e].style.display = "none";
		}
	} else if (document.layers) {
		// this is the way nn4 works
		if(document.layers[e] != null) document.layers[e].visibility = "hidden";
	}
}

function toggle(e) {

	if (document.getElementById) {
		// this is the way the standards work
		if(document.getElementById(e) != null) {
			if(document.getElementById(e).style.visibility != "hidden") {
				document.getElementById(e).style.visibility = "hidden";
				document.getElementById(e).style.display = "none";
			} else {
				document.getElementById(e).style.visibility = "visible";
				document.getElementById(e).style.display = "";
			}
		}
	} else if (document.all) {
		// this is the way old msie versions work
		if(document.all[e] != null ) {
			if(document.all[e].style.visibility != "hidden") {
				document.all[e].style.visibility = "hidden";
				document.all[e].style.display = "none";
			} else {
				document.all[e].style.visibility = "visible";
				document.all[e].style.display = "";
			}
		}
	} else if (document.layers) {
		// this is the way nn4 works
		if(document.layers[e] != null) {
			if(document.layers[e].visibility != "hidden") {
				document.layers[e].visibility = "hidden";
			} else {
				document.layers[e].visibility = "visible";
			}
		}
	}
}

function getElement(e) { // Element id should be passed in as a string
	if(document.getElementById) return document.getElementById(e);
	else if(document.all) return document.all[e];
	else if(document.layers) return document.layers[e];
	return null; // couldn't find element
}

function getInnerHTML(e) {

	if (document.getElementById) {
		if(document.getElementById(e) != null) return document.getElementById(e).innerHTML;

	} else if (document.all) {
		// this is the way old msie versions work
		if(document.all[e] != null ) return document.all[e].innerHTML;

	} else if (document.layers) {
		// this is the way nn4 works
		if(document.layers[e] != null) return document.layers[e].innerHTML;
	}
	return "";
}

function setInnerHTML(e, newInnerHTML) {

	if (document.getElementById) {
		if(document.getElementById(e) != null) document.getElementById(e).innerHTML = newInnerHTML;

	} else if (document.all) {
		// this is the way old msie versions work
		if(document.all[e] != null ) document.all[e].innerHTML = newInnerHTML;

	} else if (document.layers) {
		// this is the way nn4 works
		if(document.layers[e] != null) document.layers[e].innerHTML = newInnerHTML;
	}
	return "";
}

function isVisible(e) {
	if (document.getElementById) {
		// this is the way the standards work
		if(document.getElementById(e) != null) return document.getElementById(e).style.visibility != "hidden" ? true : false;
	} else if (document.all) {
		// this is the way old msie versions work
		if(document.all[e] != null ) return document.all[e].style.visibility != "hidden" ? true : false;
	} else if (document.layers) {
		// this is the way nn4 works
		if(document.layers[e] != null) return document.layers[e].visibility != "hidden" ? true : false;
	}
}

// Strips HTML/XML tags from a string:
function stripTags(str) {
	var gettingChars = true;
	var output = "";
	for(var i=0; i<str.length; i++) {
		if(str.charAt(i) == "<") gettingChars = false;
		else if(str.charAt(i) == ">") gettingChars = true;
		else if(gettingChars) output += str.charAt(i);
	}
	return output;
}

// Strips everything except HTML/XML tags from a string:
function stripNonTags(str) {
	var gettingChars = true;
	var output = "";
	for(var i=0; i<str.length; i++) {
		if(str.charAt(i) == "<") gettingChars = false;
		else if(str.charAt(i) == ">") gettingChars = true;
		else if(gettingChars) output += str.charAt(i);
	}
	return output;
}

// Get's the array index of a value:
function getIndex(ar, value) {
	for(var i=0; i<ar.length; i++) if(ar[i] == value) return i;
	return -1;
}

// Count the number of occurrences of 'value' in 'str' (case insensitive):
function countStr(str, value) {
	str = str.toLowerCase();
	value = value.toLowerCase();
	var count = 0;
	var remaining = str;
	while(remaining.indexOf(value) != -1) {
		count++;
		remaining = remaining.substr(remaining.indexOf(value)+1);
	}
	return count;
}

// strstr()
//
// Example:
//
//	  var str = "apple apple apple pear";
//    alert(strPos(str, "apple ", 3)); // pops up "pear"
//
function strstr(str, value, value_count) {
	if(typeof(value_count) == "undefined") var value_count = 1;
	var orig = str;
	var index;
	str = str.toLowerCase();
	value = value.toLowerCase();
	for(var i=1; i<=value_count; i++) {
		if(i == value_count) return orig.substr(str.indexOf(value)+value.length);
		else {
			index = str.indexOf(value)+1;
			str = str.substr(index);
			orig = orig.substr(index);
			if(!str.indexOf(value)) return "";
		}
	}
}

// Check if value is in array:
function inArray(needle, haystack) {
	if(typeof(haystack) != "object") return false;
	for(var i=0; i<haystack.length; i++) if(haystack[i] == needle) return true;
	return false;
}

// Return an array as a string (for debugging):
function arText(ar) {
	if(typeof(ar)=="object") {
		var output = "";
		for(var i=0; i<ar.length; i++) {
			output += ar[i];
			if((i+1)<ar.length) output += "\n";
		}
	}
	return output;
}

// Remove 'value' from array 'a':
function arrayRemove(a, value) {

	if(typeof(a)=="object") {

		// Copy array without value we're removing:
		var i;
		var new_a = new Array();
		for(i=0; i<a.length; i++) if(a[i] != value) new_a[new_a.length] = a[i];

		// Remove all elements from original array:
		var length = a.length;
		for(i=0; i<length; i++) a.length = a.length-1;

		// Re-create array from copy:
		for(i=0; i<new_a.length; i++) a[a.length] = new_a[i];
	}
}

// Display each value in an array:
function showAr(ar) {
	for(var i=0; i<ar.length; i++) {
		if(!confirm(ar[i])) return false;
	}
}

function status(str) {	// Change status bar text
	top.window.status = str;
	return true;
}

// Get the outerHTML of an element by passing in an HTML string the position
// of a character within the element to get:
function getOuterHTML(str, pos) {

	var start, end, len, i, c;

	// Get opening "<" character:
	for(i=1; i<pos; i++) {
		c = str.charAt(pos-i);
	}
}

function cut(cut_from, cut_text) {
	//alert("Index of cut text: "+cut_from.indexOf(cut_text)+"\n\nSearching for:\n\n"+cut_text+"\n\nFrom:\n\n"+cut_from);
	var output = cut_from.substr(0, cut_from.indexOf(cut_text));
	output += cut_from.substr(cut_from.indexOf(cut_text)+cut_text.length);
	return output;
}

// Attempt to find the tree object in the tree frame and tell it to load certain folders.
function treeOpen(targets) {
	if(typeof(parent) == "object") {
		if(typeof(parent.tree) == "object") {
			if(typeof(parent.tree.t) == "object") {
				parent.tree.t.reloadTree(targets);
			}
		}
	}
}

function trim(str) { // Remove leading and trailing whitespace
	if(typeof(str) != "string") return str;
	while(str.charAt(0) == " ") str = str.substr(1);
	while(str.charAt(str.length-1) == " ") str = str.substr(0, str.length-1);
	return str;
}

var savePrompt;
function noframe_register_action_performed() {
	top.savePrompt=true;
}
function register_action_performed() {
	parent.display_frame.savePrompt=true;
	top.savePrompt=true;
}
function unregister_action_performed() {

	if(typeof(parent) != "undefined") {
		if(typeof(parent.display_frame) != "undefined") {
			if (typeof(parent.display_frame.savePrompt) != "undefined") {
				parent.display_frame.savePrompt=false;
			}
		}
	}

	if(typeof(top) != "undefined") {
		if(typeof(top.savePrompt) != "undefined") {
			top.savePrompt=false;
		}
	}
}



function prompt_for_save() {

	// If parent.display_frame doesn't exist, quit function here.
	if(typeof(parent.display_frame) == "undefined") return true;

	// If top.nav.display_frame.document.md_form doesn't exist, quit function here.
	if(typeof(top.nav.display_frame.document.md_form) == "undefined") return true

	if (parent.display_frame.savePrompt) {
		if (confirm('Save changes? Click Cancel to continue without saving.')) {
			top.nav.display_frame.document.md_form.submit();
			parent.display_frame.savePrompt=false;
			unregister_action_performed()
			return true;

		} else {
			unregister_action_performed()
			return false;
		}
	}
	unregister_action_performed()
}
function rtn_prompt_for_save() {

	// If parent.display_frame doesn't exist, quit function here.
	if(typeof(parent.display_frame) == "undefined") return true;

	// If parent.display_frame.savePrompt doesn't exist, quit function here.
	if(typeof(parent.display_frame.savePrompt) == "undefined") return true;

	// If top.nav.display_frame.document.md_form doesn't exist, quit function here.
	if(typeof(top.nav.display_frame.document.md_form) == "undefined") return true

	if (parent.display_frame.savePrompt) {

		if (confirm('Save changes? Click Cancel to continue without saving.')==true) {
			top.nav.display_frame.document.md_form.submit();
			parent.display_frame.savePrompt=false;
			unregister_action_performed()
			return false;
		} else {
			var savePrompt=false;
			parent.display_frame.savePrompt=false;
			unregister_action_performed()
			return true;
		}
	}
	unregister_action_performed()
}
function header_rtn_prompt_for_save() {

	// If parent.display_frame doesn't exist, quit function here.
	if(typeof(top) == "undefined") return true;

	// If parent.display_frame.savePrompt doesn't exist, quit function here.
	if(typeof(top.savePrompt) == "undefined") return true;

	// If top.nav.display_frame.document.md_form doesn't exist, quit function here.
	if(typeof(top.nav.display_frame.document.md_form) == "undefined") return true;

	hasChanged=top.savePrompt;
	unregister_action_performed()

	if (hasChanged==true) {
		if (confirm('Save changes? Click Cancel to continue without saving.')==true) {
			top.nav.display_frame.document.md_form.submit();
			return false;
		} else {
			return true;
		}
	}
}

function copyArrayByValue(a) {
	var b = new Array();
	for(var i=0; i<a.length; i++) b[b.length] = a[i];
	return b;
}

function ucfirst(str) {
	var first = str.substr(0, 1);
	return first.toUpperCase()+str.substr(1);
}

function ucwords(str) {
	var words = str.split(" ");
	var output = "";
	for(var i=0; i<words.length; i++) {
		output += ucfirst(words[i]);
		if((i+1)<words.length) output += " ";
	}
	return output;
}

/** Append function to list of functions fired on body onload. */
function addOnLoadEvent(onloadToAdd){

	var prevOnLoad = window.onload;
	if(typeof window.onload != 'function'){
		window.onload = onloadToAdd;
	} else {
		window.onload = function() {
			if(prevOnLoad){
				prevOnLoad();
			}
			onloadToAdd();
		}
	}
}
