


/**
 * @author jazzvm
 */

function hasAnAttribute(object_or_element, attribute_name) {
   var isset;
   try {
      eval("isset=typeof object_or_element."+attribute_name+"!='undefined';");
   } catch (e) {
      isset=false;
   }
   return isset;
}


function get_input_character_code(e) {
	if(e && e.which) { //if which property of event object is supported (NN4)
		e = e
		var characterCode = e.which //character code is contained in NN4's which property
	} else {
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}
	
	return characterCode;
}

function empty(text) {
	for(i=0 ; i<text.length ; i++) {
		var ch = text.charAt(i);
		if((ch != " ") && (ch != '\t'))
			return false;
	}
	return true;
}


function isEmpty(field_name, alert_msg){
	var text = '';

	var obj;

	if (document.getElementById(field_name) != null) {
		obj = document.getElementById(field_name);
		text = obj.value;
	} else if(document.getElementsByName(field_name)[0] != null) {
		obj = document.getElementsByName(field_name)[0];
		text = obj.value;
	} else {
		alert("Fatal error: /" + field_name + "/ does not exist!");
		return false;
	}

    for (var i = 0; i < text.length; i++) {
        var ch = text.charAt(i);
        if ((ch != " ") && (ch != '\t')) 
            return false;
    }
	
	alert( alert_msg );
	obj.focus();
	
    return true;
}

function isRadioSelected(form_name, radio_name){
	var f = document.form[form_name];
	var radioElement = form.getElements(radio_name);

    for (i = 0; i < f.radioElement.length; i++) {
        if (f.radioElement[i].checked) 
            return true;
    }
    return false;
}



function wrong_char(text){
    if (text.length < 8) 
        return true;
    if (text.charAt(0) == '@') 
        return true;
    if (text.charAt(text.length - 1) == '@') 
        return true;
    
    for (i = 0; i < text.length; i++) {
        var ch = text.charAt(i);
        if (ch == '@') {
        
            for (j = i + 2; j < text.length; j++) {
                var ch = text.charAt(j);
                if (ch == '.') 
                    return false;
            }
        }
    }
    return true;
}


function ConvertRowsToLinks(xTableId){

	var rows = document.getElementById(xTableId).getElementsByTagName("tr");
	
	for(var i=0;i<rows.length;i++){
	  var link = rows[i].getElementsByTagName("a")
	  if(link.length == 1){
	    rows[i].onclick = new Function("document.location.href=\"" + link[0].href + "\"");
	    rows[i].onmouseover = new Function("this.className='highlight'");
	    rows[i].onmouseout = new Function("this.className=''");
	  }
	}

}



function substringWithReplacement(text, length, str_replacement) {
	if( text == null || text.length < length) return text;
	return text.substring(text, length) + str_replacement;
}


function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}