//****************************************************************************************************
// javafunc.js
// Misc. Javascript Functions
//
//****************************************************************************************************

function controlEnterCommand(event, clickObjName){

	var isEnter = false;

	if(is.ie && event.keycode == 13){
		isEnter=true
	}else if(event.keyCode == 13)
		isEnter = true
				
	if(isEnter){
		var btn = document.getElementById(clickObjName);
		if(btn)
			btn.click();
	}
			
	return !isEnter;
}

//Browser check JS include

function BrowserCheck () {
	var b = navigator.appName;
	if (b=="Netscape") this.b = "ns";
	else if (b=="Microsoft Internet Explorer") this.b = "ie";
	else this.b = b
	this.v = parseInt(navigator.appVersion);
	this.ns = (this.b=="ns" && this.v >= 4);
	this.ns4 = (this.b=="ns" && this.v == 4);
	this.ns5 = (this.b=="ns" && this.v == 5);
	this.ie = (this.b=="ie" && this.v >= 4);
	this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0);
	this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0);
	this.ie6 = (navigator.userAgent.indexOf('MSIE 6')>0);
	if (this.ie5) this.v=5;
	if (this.ie6) this.v=6;
	this.min = (this.ns || this.ie);
}



function trim(st) {
	var len = st.length
	var begin = 0, end = len - 1;
	while (st.charAt(begin) == " " && begin < len) {
		begin++;
	}
	while (st.charAt(end) == " " && begin < end) {
		end--;
	}
	return st.substring(begin, end+1);
}

function removeCommas(str) {
		var new_str="";
		for(i=0;i<str.length;i++)
		{
			if (str.charAt(i)!=',')
				new_str +=str.charAt(i);
		}
			return new_str;
	}
	
function stringCompare(string1,string2){
	if (string1.length != string2.length)
		return false;
	for(i=0;i<string1.length;i++){
		if(string1.charAt(i) != string2.charAt(i))
			return false; 
	}
	return true;		
}

function removeLineBreaks(str){
	var new_str = '';
	for( i =0; i < str.length; i++){
		if ((str.charAt(i)!='\r') && (str.charAt(i)!='\n') && (str.charAt(i)!='\t') && (str.charAt(i)!='\f') && (str.charAt(i)!='\b'))
			new_str += str.charAt(i);
		}
	return new_str;
}

function removeSpace(bob){
	var new_bob = '';
	for( i =0; i < bob.length; i++){
		if (bob.charAt(i)!=' ')
			new_bob += bob.charAt(i);
		}
	return new_bob;
}

function replace(argvalue, x, y) {

  if ((x == y) || (parseInt(y.indexOf(x)) > -1)) {
    errmessage = "replace function error: \n";
    errmessage += "Second argument and third argument could be the same ";
    errmessage += "or third argument contains second argument.\n";
    errmessage += "This will create an infinite loop as it's replaced globally.";
    alert(errmessage);
    return false;
  }
    
  while (argvalue.indexOf(x) != -1) {
    var leading = argvalue.substring(0, argvalue.indexOf(x));
    var trailing = argvalue.substring(argvalue.indexOf(x) + x.length, 
	argvalue.length);
    argvalue = leading + y + trailing;
  }

  return argvalue;

}

function switchCursors(obj,cursorURL){
	if(is.v >= 6){
		obj.style.cursor = "url(" + cursorURL + ")";
	}
}

// automatically create the "is" object
is = new BrowserCheck()


