function setFormValuesAndSubmit(formName, action, value, value2){
	var sForm = document.getElementById(formName);
	
	var specialObject = document.getElementById('special_object_id');
	if( specialObject!=null ){
		if( !confirm(specialObject.value) ){
			return false;
		}
	}
	
	if(action == 'goto-page') {
		if (value == 'previous') {
			sForm.curPage.value = Math.abs(sForm.curPage.value)-1;
		} else if (value == 'next') {
			sForm.curPage.value = Math.abs(sForm.curPage.value)+1;
		}else if (value == 'first') {
			sForm.curPage.value = 1;
		}else if (value == 'last') {
			sForm.curPage.value = value2;
		}else {		
			sForm.curPage.value = value;
		}
		
		if( checkDateFun() ) sForm.submit();
	}else
	if(action == 'set-records') {
		sForm.maxRecords.value = value;
		if( checkDateFun() ) sForm.submit();
	}else
	if (action == 'sort-column') {
		sForm.sortColumn.value = value;
		sForm.sortDirection.value = value2;
		if( checkDateFun() ) sForm.submit();
	}else{
		var elem = document.getElementsByName(action);
		if(elem != null && elem.length > 0 && elem[0] != null){
			elem[0].value = value;
			if( checkDateFun() ) sForm.submit();
		}
	}
}

function gotoUrlPaged(url){
	var ext = "";
	if(document.getElementsByName("maxRecords") != null && document.getElementsByName("maxRecords")[0] != null){
		ext += "&maxRecords=" + document.getElementsByName("maxRecords")[0].value;
	}
	if(document.getElementsByName("curPage") != null && document.getElementsByName("curPage")[0] != null){
		ext += "&curPage=" + document.getElementsByName("curPage")[0].value;
	}
	//alert(ext);
	location.href=url + ext;
}

function checkOnlyDigit(elementId){
	var source = document.getElementById(elementId);
	var reg = /^[\d|\u002E|\u002C]*$/;
	if( !reg.test(source.value) ){
		window.alert('Only digits in this field!');
		source.focus();
	}	
}

function getTableOut(path, format, name){

	if( format == "Excel03" ){
		window.open(path+'/console/admin/pager/TableToExcel.jsp?name='+name);
	}else if( format == "eMail" ){
		showUsersLookup(path+'/tableToEmail.do', 800, 450);
		//window.open(path+'/tableToEmail.do');
	}else if( format == "pdf"){
		window.open(path+'/topdf?name='+name);
	}	
}


// light row wiht checkbox
function lightRowByInput(id){
	var obj = document.getElementById(id);
	if( obj.checked ){
		obj.parentNode.parentNode.style.cssText = "color: blue; font: bold 1em arial;";
	}else{
		obj.parentNode.parentNode.style.cssText = "";
	}
}

var allSelected = true;
function allSelect(clazzName){
	var source = document.getElementsByTagName("input");
    for(i=0; i<source.length; i++){ 
    	if( source[i].className.indexOf( clazzName )!=-1 ){
    		source[i].checked = allSelected; 
    		if(allSelected){
    			source[i].parentNode.parentNode.style.cssText = "color: blue; font: bold 1em arial;";
    		}else{
    			source[i].parentNode.parentNode.style.cssText = "";
    		}
    	}
    }
    allSelected = !allSelected;
}

// add to standard type String function trim() like in String from JDK
String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

//add checking current function with RegExp
String.prototype.regexp = function (regexp) {
    return regexp.test(this);
}

// add to standard type String function startWith()
String.prototype.startsWith = function(str) 
{
	return (this.match("^"+str)==str);
}

// add o standard String function endWith
String.prototype.endsWith = function(str) 
{
	return (this.match(str+"$")==str);
}


function resetItem(id){
	if (document.getElementById(id)!= null){
		 document.getElementById(id).value = '';
		
		 }
		 
		 if (document.getElementById(id+'_prev')!= null){
		 	 document.getElementById(id+'_prev').src= '';
		 	 
		 }
		 
		 if (document.getElementById(id+'_href')!= null){
		  	document.getElementById(id+'_href').href='';
		  	 
		 	document.getElementById(id+'_href').innerHTML = '';
		 	
		 }
		  
		 if (document.getElementById(id+'_filePath')!= null){
		 	document.getElementById(id+'_filePath').value= '';
		 	
		 }
}

/* get HTTPRequestObject for AJAX query */
function getHTTPRequestObject() {
  var xmlHttpRequest;
  /*@cc_on
  @if (@_jscript_version >= 5)
  try {
    xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (exception1) {
    try {
      xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (exception2) {
      xmlHttpRequest = false;
    }
  }
  @else
    xmlhttpRequest = false;
  @end @*/
 
  if (!xmlHttpRequest && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlHttpRequest = new XMLHttpRequest();
    } catch (exception) {
      xmlHttpRequest = false;
    }
  }
  return xmlHttpRequest;
}

function isIE(){
	var browser = navigator.appName;
	if (browser.indexOf("Internet Explorer") != -1){
		return true;
	}else{ 
		return false; 
	} 
}

function isFF(){
	var browser = navigator.userAgent.toLowerCase();
	
	if (browser.indexOf("firefox") != -1 ){
		return true;
	}else{ 
		return false; 
	} 
}

// IE doesn't support 'table-row' and other special display mode, replace on 'block'
function getDisplayRowForTable(){
	if( isIE() ){
		return "block";
		//return "";
	}else{
		return "table-row";
		//return "";
	}
}

// all property of object (you should specify the name)
function dump(obj, obj_name) {
  var result = "";
  for (var i in obj)
    result += obj_name + '.' + i + ' = ' + obj[i] + '\n';
  return result;
}

/*
* for master and slave accounts 
*/
function displayCurrencyRow(show, curRow, masterRow){
	if(show){  
		try{
			//alert("is "+document.getElementById(curRow).style.display+" set like "+getDisplayRowForTable());
			document.getElementById(curRow).style.display = getDisplayRowForTable();
			 
		}catch(e){ /* alert(e.message); */ }
		try{
			document.getElementById(masterRow).style.display = 'none';
		}catch(e){ /* alert(e.message); */ }
	}else{
		try{
			document.getElementById(curRow).style.display = 'none';
		}catch(e){ /* alert(e.message); */ }
		try{
			document.getElementById(masterRow).style.display = getDisplayRowForTable();
		}catch(e){ /* alert(e.message); */ }	
	}
}

// check select fieldId with control value controlValue and lock input field part name partName
function checkFieldAndLock(fieldId, controlValue, partName){
	var typeSel = document.getElementById('allocationTypeId');
	var selectedItem = typeSel[typeSel.selectedIndex];
	if( selectedItem.value == controlValue ){
		var inputs = document.getElementsByTagName("INPUT");
		for(i=0; i<inputs.length; i++){
			if( inputs[i].name.indexOf(partName) != -1 ){
				inputs[i].style.visibility = 'hidden';
			}else{
				inputs[i].style.visibility = 'visible';
			}
		}
	}
}

function isInteger(val)
{
    if(val==null)
    {
        return false;
    }
    if (val.length==0)
    {
        return false;
    }
    for (var i = 0; i < val.length; i++) 
    {
        var ch = val.charAt(i)
        if (i == 0 && ch == "-")
        {
            continue
        }
        if (ch < "0" || ch > "9")
        {
            return false
        }
    }
    return true
}

/* dd-MM-yyyy hh:mm*/
function checkLongDate(text){
	if(text == '') return true;
	if(text == '~~-~~-~~~~ ~~~') return true;
	var reg = /^\d{2}[\/-]\d{2}[\/-]\d{4}\s{1}\d{2}[\/:]\d{2}$/;
	return reg.test(text);
}

/* dd-MM-yyyy */
function checkShortDate(text){
	if(text == '') return true;
	if(text == '~~-~~-~~~~ ~~~') return true;
	var reg = /^\d{2}[\/-]\d{2}[\/-]\d{4}$/;
	return reg.test(text);
}

// onload func and delete date onclick
function placeDates(){
	var inputs = document.getElementsByTagName('INPUT');
	for(i = 0; i < inputs.length; ++i){
		if( inputs[i].className.indexOf('date ')!=-1 || inputs[i].className.indexOf('time ')!=-1 ){
			try{
				if( inputs[i].value.trim()=='' ){
					if( inputs[i].className.indexOf('date ')!=-1 )
					{
						inputs[i].value = 'dd-MM-yyyy';
						
						
						inputs[i].onclick=function(){
							if (this.value == 'dd-MM-yyyy'){this.value = ''} 
						};
						
						
						inputs[i].onblur = function(){
							if (this.value == '') {this.value = 'dd-MM-yyyy'} 
						};
						
					}else{
						inputs[i].value = 'dd-MM-yyyy hh:mm';
						
						inputs[i].onclick=function() { 
							if (this.value == 'dd-MM-yyyy hh:mm'){this.value = ''; }
							};
						
						inputs[i].onblur = function(){
								if (this.value == '') {this.value = 'dd-MM-yyyy hh:mm'} };
					}
				}
			}catch(e){}
		} // class we need
		
	}
}

// submit
function checkDateFun(){
	var inputs = document.getElementsByTagName('INPUT');
	for(i = 0; i < inputs.length; ++i){
		if( inputs[i].className.indexOf('date ')!=-1 || inputs[i].className.indexOf('time ')!=-1 ){
			try{
				
				if( inputs[i].className.indexOf('date ')!=-1 ){
					if( inputs[i].value=='dd-MM-yyyy' ) inputs[i].value='';
					if( !checkShortDate(inputs[i].value) ){
						alert('Wrong date format, sould be: dd-MM-yyyy');
						return false;
					}
				}else{
					if( inputs[i].value=='dd-MM-yyyy hh:mm' ) inputs[i].value='';
					if( !checkLongDate(inputs[i].value) ){
						alert('Wrong date format, sould be: dd-MM-yyyy hh:mm');
						return false;
					}
				}
				
			}catch(e){}
		} // class we need
	}
	return true;
}

// animate image branding, very cool:)
function animate_Img(imgId)
{
	try{
	var $bigImg = $('#'+imgId);
    
    if($bigImg.hasClass('isOpen')) 
    {
        $bigImg.animate({width:"32px", height: "32px"},150 );
        $bigImg.addClass('isClose');
        $bigImg.removeClass("isOpen");
    } else {
        $bigImg.animate({width:"132px", height: "132px"}, 300, function(){  $bigImg.removeClass("isClose"); $bigImg.addClass('isOpen'); });
    }
	}catch(e){alert(e.message);}
	
}	

// function "stop parent script" for table head example "find users" 
function stopBuble(e)
{
	 e = e || window.event;
	 e.cancelBubble = true;
	 
	 if (e.stopPropagation)
	 { e.stopPropagation(); }
}

function controlVisibility(id, visible){
	try{
		var el = document.getElementById( id );
		if( visible ){
			el.style.visibility = 'visible';
		}else{
			el.style.visibility = 'hidden';
		}
	}catch(ex){
		alert(ex.message);
	}
}

function processCheckboxPassword(chBox, fieldId){
	var state = chBox.checked;
	if (state==false){
		document.getElementById(fieldId).disabled=true;
		document.getElementById(fieldId).value='';
	}else{
		document.getElementById(fieldId).disabled=false;
	}
}



