// ***********************************************************
// **
// ** This is Worrior`s lib of basic functions usually used 
// **
// ***********************************************************

var nav = navigator.userAgent.toLowerCase();
var db = (document.compatMode && document.compatMode.toLowerCase() != "backcompat") ? document.documentElement : (document.body || null);
var op = !!(window.opera && document.getElementById);
var isIE = !!(nav.indexOf("msie") >= 0 && document.all && db && !op);

function getObjectProperties (object, options) {
	var result = '';
	for (var property in object) {
		if (options) {
			if (options.listAll) {result += property + ': ' + object[property];} else {result += property;}
			if (options.newLine) {result += '\r\n'} else {result += ", ";}
		} else {
			result += property + ", ";	
		}
	}
	return result;
}

checkControl = function(cntrl, msg) {
	if (cntrl == null || cntrl.name == null || cntrl.name == "") return true;
	if ((cntrl.type == "text") || (cntrl.type.indexOf("select") > -1)) {
		if (cntrl.value == "") {
			if (!msg) {
				msg = cntrl.title;
			}
			alert(msg);
			cntrl.focus();
			return false;
		}
	}
	return true;
}


// ***************
// * Date methods
// ***************


Date.prototype.copy = function () {
  return new Date(this.getTime());
};
Date.prototype.addDays = function(days) {
	this.setDate(this.getDate()+days);
} 
Date.prototype.addMinutes = function(minutes) {
	this.setTime(this.getTime()+(minutes*60*1000));
}
Date.prototype.addSpecDays = function(weekdays, t_left) {
	if (t_left == 0) return;
	//for (var i = 0; i < weekdays.length; i++) {alert(weekdays[i]);}	
	while (t_left > 0) {
		for (var i = 0; i < weekdays.length; i++) {
			if (this.getDay() == weekdays[i]) {
//				alert('Day: ' + this.getDay()); 
				t_left--;
				break;
			}
		}
		if (t_left > 0) this.addDays(1);					
	}
}
Date.prototype.msPERDAY = 1000 * 60 * 60 * 24;
Date.prototype.getDaysBetween = function(d) {
  d = d.copy();

  d.setHours(this.getHours(), this.getMinutes(), this.getSeconds(), this.getMilliseconds());

  var diff = d.getTime() - this.getTime();
  return Math.floor((diff)/this.msPERDAY);
};

Date.prototype.getDayName = function(shortName) {
   var Days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
   if (shortName) {
      return Days[this.getDay()].substr(0,3);
   } else {
      return Days[this.getDay()];
   }
}

Date.prototype.getMonthName = function() {
   return ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][this.getMonth()]; 
}

// *******
// * end of Date methods
// ************************


// ***************
// * Array methods
// ***************


//This prototype is provided by the Mozilla foundation and
//is distributed under the MIT license.
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license

if (!Array.prototype.lastIndexOf)
{
  Array.prototype.lastIndexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]);
    if (isNaN(from))
    {
      from = len - 1;
    }
    else
    {
      from = (from < 0)
           ? Math.ceil(from)
           : Math.floor(from);
      if (from < 0)
        from += len;
      else if (from >= len)
        from = len - 1;
    }

    for (; from > -1; from--)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}

//This prototype is provided by the Mozilla foundation and
//is distributed under the MIT license.
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license

if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}

/**
	Array.forEach(function)
	
	This is an odd little method. All it does is pass each element of the Array to the passed function. It ignores any results from the function and it returns nothing itself. It will pass all the Array contents through the function of your choice but the Array itself will not be affected and it will return nothing by itself.
	
	This method will pass the current value, the current index, and a pointer to the array to your function. myfunction(curValue, curIndex, curArray)
	
	var printArray = function (x, idx) {
	   document.writeln('['+idx+'] = '+x);
	}
	
	var myArray = [1,'two',3,'four',5];
	
	myArray.forEach(printArray); // outputs: [0] = 1 [1] = two [2] = 3 [3] = four [4] = 5
	
	This method can be prototyped to allow Internet Explorer and older browsers to use this method. Simply copy the following code into your Javascript toolbox and the .forEach() method will be available regardless of your browser version. 
**/

if (!Array.prototype.forEach)
{
  Array.prototype.forEach = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this)
        fun.call(thisp, this[i], i, this);
    }
  };
}

/**
	Array.filter(function)
	
	Filter creates a new Array of items which evaluate to true in the supplied function. In the Array.every() method, we tested if the entire Array was composed of Numbers. In Array.filter() we can extract all the numbers, creating a new Array in the process.
	
	This method will pass the current value, the current index, and a pointer to the array to your function. myfunction(curValue, curIndex, curArray)
	
	Here we pass the array through the same function as .every() -- isNumeric -- and if the element is a number it's placed in the new "oddArray" Array.
	
	var isNumeric = function(x) {
	   // returns true if x is numeric and false if it is not.
	   var RegExp = /^(-)?(\d*)(\.?)(\d*)$/; 
	   return String(x).match(RegExp);
	}
	var myArray = [1,'two',3,'four',5,'six',7,'eight',9,'ten'];
	var oddArray=myArray.filter(isNumeric);
	
	document.writeln(oddArray);   // outputs: 1,3,5,7,9

**/

if (!Array.prototype.filter)
{
  Array.prototype.filter = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var res = new Array();
    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this)
      {
        var val = this[i]; // in case fun mutates this
        if (fun.call(thisp, val, i, this))
          res.push(val);
      }
    }

    return res;
  };
}

/**
	Array.every(function)
	
	The every method is a Firefox method which accepts a function as an argument. Every value of the array is passed to that function until the function returns false. If no elements return false then every will return true, if an element returned false then every will return false. It's a convenient way to test an Array and see if every element is a number for instance.
	
	This method will pass the current value, the current index, and a pointer to the array to your function. myfunction(curValue, curIndex, curArray)
	
	var isNumeric = function(x) {
	   // returns true if x is numeric and false if it is not.
	   var RegExp = /^(-)?(\d*)(\.?)(\d*)$/; 
	   return String(x).match(RegExp);
	}
	var myArray = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
	
	document.writeln(myArray.every(isNumeric));   // outputs: true
	
	var myArray = [1,2,3,4,5,6,7,8,9,'ten',11,12,13,14,15];
	
	document.writeln(myArray.every(isNumeric));   // outputs: false
**/

if (!Array.prototype.every)
{
  Array.prototype.every = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this &&
          !fun.call(thisp, this[i], i, this))
        return false;
    }

    return true;
  };
}

/**
	Array.map(function)
	
	The map method will call the provided function for each value of the array and it will return an array containing the results of those function calls.
	The callback function is called with three arguments: the value, the index, and a pointer to the array being used respectively.
	In the following example each element of the array is tested to see if it is numeric, if it is, it's passed into the new array, otherwise a zero is inserted.
	
	var isNumeric = function(x) {
	   // returns true if x is numeric and false if it is not.
	   var RegExp = /^(-)?(\d*)(\.?)(\d*)$/; 
	   return String(x).match(RegExp);
	}
	var testElement = function(x) {
	   if (isNumeric(x)) {
		  return x;
	   } else {
		  return 0;
	   }
	}
	
	var myArray = [1,'two',3,'four',5,'six',7,'eight',9,'ten'];
	var newArray= myArray.map(testElement);
	document.writeln(newArray); // outputs: 1,0,3,0,5,0,7,0,9,0
**/

if (!Array.prototype.map)
{
  Array.prototype.map = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var res = new Array(len);
    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this)
        res[i] = fun.call(thisp, this[i], i, this);
    }

    return res;
  };
}

/**
	Array.some(function)
	
	The some() method will pass each element of the Array through the supplied function until true has been returned. If the function returns true some will in turn return true. If the entire array has been traversed and no true condition was found then some() will return false.
	
	var isNumeric = function(x) {
	   // returns true if x is numeric and false if it is not.
	   var RegExp = /^(-)?(\d*)(\.?)(\d*)$/; 
	   return String(x).match(RegExp);
	}
	var myArray = ['one', 'two', 'three', 'four', 'five'];
	
	document.writeln(myArray.some(isNumeric));   // outputs: false
	
	var myArray = ['one', 'two', 3, 'four', 'five'];
	
	document.writeln(myArray.some(isNumeric));   // outputs: true
**/


if (!Array.prototype.some)
{
  Array.prototype.some = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this &&
          fun.call(thisp, this[i], i, this))
        return true;
    }

    return false;
  };
}

/**
	Howto Tell The Difference Between An Array And An Object
	
	Because Javascript's Array is just a modified Javascript object, it's actually not that easy to differentiate an Array and an Object, even when you absolutely need to. So here's a little function that will let you ask the array itself what it is. isArray() will return true if it's an array and false if it is not an Array. 
**/

function isArray(testObject) {   
    return testObject && !(testObject.propertyIsEnumerable('length')) && typeof testObject === 'object' && typeof testObject.length === 'number';
}

/**
The Array.sort() method sorts alphabetically by default but adding a numerical sort is as simple as including the following snippet of code in your toolbox.

All this does is make sortNum a method of Array just like sort and splice and join and all the other default methods. Any array can access it, even arrays that haven't been assigned to variables…

document.writeln([5,8,12,50,25,80,93].sortNum()); // outputs 5,8,12,25,50,80,93
**/

Array.prototype.sortNum = function() {
   return this.sort( function (a,b) { return a-b; } );
}

/**
	Array.find(searchStr)
	
	Array.indexOf() is a nice method but this extension is a little more powerful and flexible. First it will return an array of all the indexes it found (it will return false if it doesn't find anything). Second in addition to passing the usual string or number to look for you can actually pass a regular expression, which makes this the ultimate Array prototype in my book. 
	
	Usage…
	
	var tmp = [5,9,12,18,56,1,10,42,'blue',30, 7,97,53,33,30,35,27,30,'35','Ball', 'bubble'];
	//         0/1/2 /3 /4/5 /6 /7     /8  /9/10/11/12/13/14/15/16/17/  18/    19/      20
	var thirty=tmp.find(30);             // Returns 9, 14, 17
	var thirtyfive=tmp.find('35');       // Returns 18
	var thirtyfive=tmp.find(35);         // Returns 15
	var haveBlue=tmp.find('blue');       // Returns 8
	var notFound=tmp.find('not there!'); // Returns false
	var regexp1=tmp.find(/^b/);          // returns 8,20    (first letter starts with b)
	var regexp1=tmp.find(/^b/i);         // returns 8,19,20 (same as above but ignore case)
**/

Array.prototype.find = function(searchStr) {
  var returnArray = false;
  for (i=0; i<this.length; i++) {
    if (typeof(searchStr) == 'function') {
      if (searchStr.test(this[i])) {
        if (!returnArray) { returnArray = [] }
        returnArray.push(i);
      }
    } else {
      if (this[i]===searchStr) {
        if (!returnArray) { returnArray = [] }
        returnArray.push(i);
      }
    }
  }
  return returnArray;
}

/**
	Array.shuffle()
	
	The anti-sort, this shuffle() method will take the contents of the array and randomize them. This method is surprisingly useful and not just for shuffling an array of virtual cards. 
	
	Usage…
	
	var myArray = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
	myArray.shuffle();
	document.writeln(myArray); // outputs~: 8,1,13,11,2,3,4,12,6,14,5,7,10,15,9
**/

Array.prototype.shuffle = function (){ 
        for(var rnd, tmp, i=this.length; i; rnd=parseInt(Math.random()*i), tmp=this[--i], this[i]=this[rnd], this[rnd]=tmp);
};

/**
	Array.compare(array)
	
	If you need to be able to compare Arrays this is the prototype to do it. Pass an Array you want to compare and if they are identical the method will return true. If there's a difference it will return false. The match must be identical so '80' is not the same as 80.
	
	Usage…
	
	var myArray = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
	var yourArray = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
	document.writeln(myArray.compare(yourArray)); // outputs: true;
	
	yourArray[0]='1';
	document.writeln(myArray.compare(yourArray)); // outputs: false;
	yourArray[0]='one';
	document.writeln(myArray.compare(yourArray)); // outputs: false;
	yourArray[0]=1;
	document.writeln(myArray.compare(yourArray)); // outputs: true;
**/

Array.prototype.compare = function(testArr) {
    if (this.length != testArr.length) return false;
    for (var i = 0; i < testArr.length; i++) {
        if (this[i].compare) { 
            if (!this[i].compare(testArr[i])) return false;
        }
        if (this[i] !== testArr[i]) return false;
    }
    return true;
}


/**********************
* end of Array methods
***********************/



//--------------------------------------------------------------------------------------------------------------


/************************************
* String methods
************************************/


/**
trim()
	
	Removing leading and trailing whitespace is something which should have shipped with Javascript from the start, but it's easy enough to make up for the designer's oversight. 
	
Usage…
	
	var test = "   Test   ";
	var test1 = test.ltrim();   // returns "Test   "
	var test2 = test.rtrim();   // returns "   Test"
	var test3 = test.trim();    // returns "Test"
**/


String.prototype.trim = function() {
   return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
   return this.replace(/^\s+/g,"");
}
String.prototype.rtrim = function() {
   return this.replace(/\s+$/g,"");
}

/**
htmlEntities()
	
	This method escapes all &, <, and > symbols in the string, making it safe to display the string on a web page without fear that it will be treated as HTML.
	
Usage…
	
	var tmp = '<html><head></head>';
	var safe= tmp.htmlEntities(); // Returns &lt;html&gt;&lt;head&gt;&lt;/head&gt;
**/

String.prototype.htmlEntities = function () {
   return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
};

/**
stripTags()
	
	This method will remove all < > tags (and everything in between), ensuring that the string contains no HTML.
	
Usage…
	
	var tmp = '<a href="http://somespammer.com">Some Link</a>';
	var safe= tmp.stripTags(); // Returns: Some Link;
**/

String.prototype.stripTags = function () {
   return this.replace(/<([^>]+)>/g,'');
}

/**
toArray()
	
	This method explodes the string out into an array of characters.
	
Usage…
	
	var str='AbCdEfGhIjKlMnOpQrStUvWxYz';
	var arr=str.toArray();
	
	for (var i=0; i<arr.length; i++) {
	   document.write(arr[i]+', ');
	}
	//Outputs:
	//A, b, C, d, E, f, G, h, I, j, K, l, M, n, O, p, Q, r, S, t, U, v, W, x, Y, z,
**/

String.prototype.toArray = function() {
   return this.split('');
}



/**
toIntArray()

	This method explodes the string out into an array of integers representing the character's unicode.
	
Usage…

	var str='AbCdEfGhIjKlMnOpQrStUvWxYz';
	var arr=str.toIntArray();
	
	for (var i=0; i<arr.length; i++) {
	   document.write(arr[i]+', ');
	}
	// Outputs:
	// 65, 98, 67, 100, 69, 102, 71, 104, 73, 106, 75, 108, 77, 
	// 110, 79, 112, 81, 114, 83, 116, 85, 118, 87, 120, 89, 122,
**/

String.prototype.toIntArray = function() {
   var returnArray = [];
   for (var i=0; i<this.length; i++) {
      returnArray.push(this.charCodeAt(i));
   }
   return returnArray;
}

/******************************
* end of string methods
*******************************/


/******************************
* input methods
******************************/

function setSelectionRange(input, selectionStart, selectionEnd) {
	if ((input == "") || (input == null)) return;
	if (typeof(input) != 'object'){
		input = document.getElementById(input);
	}
	
	if (input.createTextRange) {
		var range = input.createTextRange();
		
		range.collapse(true);
		range.moveEnd('character', selectionEnd);
		range.moveStart('character', selectionStart);
		range.select();
	}
	else if (input.setSelectionRange) {
		input.focus();
		input.setSelectionRange(selectionStart, selectionEnd);
	}
}

function insertAtCursorPos(input, value) {
	if ((input == "") || (input == null)) return;
	if (typeof(input) != 'object'){
		input = document.getElementById(input);
	}
	
	var pos = getSelectionStart(input);
	
	//IE support
	if (document.selection) {
		input.focus();
		sel = document.selection.createRange();
		sel.text = value;
	}
	//MOZILLA/NETSCAPE support
	else if (input.selectionStart || input.selectionStart == '0') {
		var startPos = input.selectionStart;
		var endPos = input.selectionEnd;
		input.value = input.value.substring(0, startPos) + value + input.value.substring(endPos, input.value.length);
	} else {
		input.value += value;
	}
	
	endPosition = pos+value.length;
	setSelectionRange(input, endPosition, endPosition);
	input.focus();
}

function surroundWithTag(objId, tag){
	if (objId == "") return;
	if (typeof(objId) == 'object'){
		var obj = objId;
	} else {
		var obj = document.getElementById(objId);
	}
	
	var openTag = "<" + tag + ">";
	var closeTag = "</" + tag + ">";
	
	//IE support
	if (document.selection) {
		obj.focus();
		sel = document.selection.createRange();
		sel.text = openTag + sel.text + closeTag;
	}
	//MOZILLA/NETSCAPE support
	else if (obj.selectionStart || obj.selectionStart == '0') {
		var startPos = obj.selectionStart;
		var endPos = obj.selectionEnd;
		var sel = obj.value.substring(startPos, endPos);
		obj.value = obj.value.substring(0, startPos) + openTag + sel + closeTag + obj.value.substring(endPos, obj.value.length);
	} else {
		// if aobve is not supported then do nothing
	}
}

var is_gecko = /gecko/i.test(navigator.userAgent);
var is_ie    = /MSIE/.test(navigator.userAgent);

function setSelectionRange(input, start, end) {
	if (is_gecko) {
		input.setSelectionRange(start, end);
	} else {
		// assumed IE
		var range = input.createTextRange();
		range.collapse(true);
		range.moveStart("character", start);
		range.moveEnd("character", end - start);
		range.select();
	}
};

function getSelectionStart(input) {
	if (is_gecko)
		return input.selectionStart;
	var range = document.selection.createRange();
	var isCollapsed = range.compareEndPoints("StartToEnd", range) == 0;
	if (!isCollapsed)
		range.collapse(true);
	var b = range.getBookmark();
	return b.charCodeAt(2) - 2;
};

function getSelectionEnd(input) {
	if (is_gecko)
		return input.selectionEnd;
	var range = document.selection.createRange();
	var isCollapsed = range.compareEndPoints("StartToEnd", range) == 0;
	if (!isCollapsed)
		range.collapse(false);
	var b = range.getBookmark();
	return b.charCodeAt(2) - 2;
};

// cross browser functions
function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}

function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}


function getClientDim(){
		
 	var myWidth = 0, myHeight = 0;
	
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return [myWidth, myHeight]
}


/*
*  function to show some objects and to hide other using the style directive "display:none | block"
*/
function hideShowObj(list_to_show, list_to_hide) {
	if (list_to_show == "" && list_to_hide == "") {
		return false;	
	}

	var arrShow = list_to_show.split(",");
	var arrHide = list_to_hide.split(",");
	
	if (list_to_show == "") arrShow = [];
	if (list_to_hide == "") arrHide = [];
	
	//alert(arrShow.length + " / " + arrHide.length);
	
	for (var i=0; i< arrShow.length; i++) {
		var obj = document.getElementById(arrShow[i]);
		if (null != obj) obj.style.display = "block";
	}
	
	for (var i=0; i< arrHide.length; i++) {
		var obj = document.getElementById(arrHide[i]);
		if (null != obj) obj.style.display = "none";
	}
	
}

checkControl = function(cntrl, msg) {
	if (cntrl == null || cntrl.name == null || cntrl.name == "" || cntrl.id == "0" || cntrl.title == "") return true;
	
	if ((cntrl.type == "text") || (cntrl.type.indexOf("select") > -1) || (cntrl.type == "textarea")) {
		if (cntrl.value == "") {
			if (!msg) {
				msg = cntrl.title;
			}
			alert(msg);
			cntrl.focus();
			return false;
		}
	} else if (cntrl.type == "radio") {
		if (!msg) {
			msg = cntrl.title;
		}
		
		group = document.getElementsByName(cntrl.name);
		var checked = false;
		for (var i=0; i < group.length; i++){
			checked = checked || group[i].checked;
		}
		if (!checked) {
			alert(msg).
			group.focus();
			return false;
		}
		//alert(propertiesToString(cntrl));
	}
	return true;
}

propertiesToString = function(obj) {
	var tmp = "";
	for (prop in obj) {
		tmp += prop + "=" + obj[prop] + "\n";
	}
	
	return tmp;
}

// validates the form
function validateForm(form){
	var res = true;
	var tmp = "";
	
   	for (var i = 0; i < form.elements.length; i++) {
		tmp += form.elements[i].type + "\n";
	      if (checkControl(form.elements[i]) == false) {
		      res = false;
		      break;
	      } else {
		      res = true;
	      }
  	}
   //alert(tmp);
	if (form == null || res == false) {
 		return true;
	} else if (form != null && res){
		if (isIE) {
			setTimeout("document.getElementById('"+form.id+"').submit()",600);
		} else {
			form.submit();	
		}
	}	
};

// 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 setRadioValue(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;
		}
	}	
}
