function multi_select(id, all) {
	var target = document.getElementById("selected_"+id);
	var source = document.getElementById("avail_"+id);	
	
	var tpos = target.options.length;
	
	
	for(i=0;i<source.options.length;) {
		if(source.options[i].selected || all) {
			target.options[tpos] = new Option(source.options[i].text,source.options[i].value);
			target.options[tpos].selected = true;
			
			tpos++;
		    
			source.options[i] = null;
			i=0;
		} else {
			i++;
		}
	}
	updateMultiSelectHidden(id);
}

function updateMultiSelectHidden(id) {

	var target = document.getElementById("selected_"+id);
	var hidden = document.getElementById(id);
	
	hidden.value = "";
	for(i=0;i<target.options.length;i++) {
		hidden.value = hidden.value + "," +target.options[i].value;
	}

}

function multi_unselect(id, all) {
	var source = document.getElementById("selected_"+id);
	var target = document.getElementById("avail_"+id);	
	
	var tpos = target.options.length;
	
	for(i=0;i<source.options.length;) {
		if(source.options[i].selected || all) {
			target.options[tpos++] = new Option(source.options[i].text,source.options[i].value);
			source.options[i] = null;
			i=0;
		} else {
			i++;
		}
	}
	updateMultiSelectHidden(id);
}

function deselectCheckBox(checkBoxId)
{
	document.getElementById(checkBoxId).checked = false;
}

function checkUncheckAll(theElement) {
     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++){
      if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
	  theForm[z].checked = theElement.checked;
	  }
     }
    }


function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( name ) {
		
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function changeLanguage(src) {
	var lang = src.value;
	Set_Cookie("OD_language",lang,300,"","","");
	document.getElementById("changeLanguage").submit();
}

function changeCurrency(src) {
	var currency = src.value;
	Set_Cookie("OD_currency",currency,300,"","","");
	document.getElementById("changeCurrency").submit();
}


function isInt(x) {
	var y=parseInt(x);
	if (isNaN(y)) return false;
	return x==y && x.toString()==y.toString();
} 

function showForm(ref) {
	var nonEdit = document.getElementById("pNonEdit_"+ref);
	var edit = document.getElementById("pEdit_"+ref);
	nonEdit.style.display = "none";
	edit.style.display = "inline";
}

function validatePercentage(ref) {
	var val = document.getElementById("percentage_"+ref).value;
	var ok = isInt(val);
	if (!ok || (val>100 || val<0) ) {
		alert("Please enter integer number between 0 and 100");
		return false;
	}
	return true;
}

function submitForm(action,formName) { 
	var actionField = document.getElementById("action_"+formName);
	actionField.value = action;

	actionField.form.submit();
}



























