//__________________________________________________________________________________
function disable_input(id) {
	obj=ge(id);
	if (eval('typeof(obj'+id+'_className)=="undefined"')){
		eval('obj'+id+'_className=\''+obj.className+'\';');
	}
	obj.className += ' disabled';
	obj.blur();
}
//__________________________________________________________________________________
function enable_input(id) {
	obj=ge(id);
	if (eval('typeof(obj'+id+'_className)=="undefined"')){
		eval('obj'+id+'_className=\''+obj.className+'\';');
	}
	obj.className += ' enabled';
}
//__________________________________________________________________________________
function hover_input(id) {
	obj=ge(id);
	if (eval('typeof(obj'+id+'_className)=="undefined"')){
		eval('obj'+id+'_className=\''+obj.className+'\';');
	}
	obj.className += ' hovered';
}
//__________________________________________________________________________________
function normalize_input(id) {
	obj=ge(id);
	eval('obj.className=obj'+id+'_className;');
}
//__________________________________________________________________________________
function BoundCountryState(){
	addEvent(gebid('country_id'),'change',BoundCountryState_OnCountryChanged,true);
}
//__________________________________________________________________________________
function BoundCountryState_OnCountryChanged(){
	obj=gebid(gebid('country_id').value);
	objParent=obj.parentNode;
	for(i=1;i<objParent.childNodes.length;i++){
		
		if (objParent.childNodes[i].id!=obj.id){
			objParent.childNodes[i].disabled=true;
		}else{
			objParent.childNodes[i].disabled=false;
		}
	}
}
//__________________________________________________________________________________
function LoadSelectWithAjaxAutoSelect(obj,default_key){ // expects key|value|key|value|key|value|key|value
	arr=ajax_return.split('|');
	obj.options.length=0;
	obj.options[0]=new Option('Select one','');
	ret=false;
	for (i=0;i<arr.length;i=i+2){
		obj.options[(i+2)/2]=new Option(arr[i+1],arr[i]);
		if (default_key==arr[i]){
			obj.options[(i+2)/2].selected=true;
			ret=true;
		}
	}
	//alert(obj.options.length);
	if (default_key=='' && obj.options.length>1){
		obj.options[1].selected=true;
	}
	return(ret);
}
//__________________________________________________________________________________
function LoadSelectWithAjax(obj,default_key){ // expects key|value|key|value|key|value|key|value
	arr=ajax_return.split('|');
	obj.options.length=0;
	ret=false;
	for (i=0;i<arr.length;i=i+2){
		obj.options[i/2]=new Option(arr[i+1],arr[i]);
		if (default_key==arr[i]){
			obj.options[i/2].selected=true;
			ret=true;
		}
	}
	return(ret);
}
function LoadSelectWithAjax2(obj,default_key){ // expects value|value|value
	arr=ajax_return.split('|');
	obj.options.length=0;
	ret=false;
	for (i=0;i<arr.length;i++){
		obj.options[i]=new Option(arr[i],arr[i]);
		if (default_key==arr[i]){
			obj.options[i].selected=true;
			ret=true;
		}
	}
	return(ret);
}
function LoadSelectWithString(obj,s,default_key){ // expects key|value|key|value|key|value|key|value
	arr=s.split('|');
	obj.options.length=0;
	ret=false;
	for (i=0;i<arr.length;i=i+2){
		obj.options[i/2]=new Option(arr[i+1],arr[i]);
		if (default_key==arr[i]){
			obj.options[i/2].selected=true;
			ret=true;
		}
	}
	return(ret);
}
function LoadSelectWithString2(obj,s,default_key){ // expects value|value|value
	arr=s.split('|');
	obj.options.length=0;
	ret=false;
	for (i=0;i<arr.length;i++){
		obj.options[i]=new Option(arr[i],arr[i]);
		if (default_key==arr[i]){
			obj.options[i].selected=true;
			ret=true;
		}
	}
	return(ret);
}
//__________________________________________________________________________________
function addEvent(obj, evType, fn, useCapture){
 if (obj==null) return(false);
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be attached");
  }
}
//__________________________________________________________________________________
function DisplayError(title,message,objID){
	if (gebid('status_section')){
		obj=gebid('status_section');
		obj.innerHTML='';
		obj.style.display='none';
	}
	if (gebid('error_section')){
		obj=gebid('error_section');
		if (objID!=null){
			message+='<p><a href="javascript:gebid(\''+objID+'\').focus();">Click here</a> to continue</p>';
		}
		obj.innerHTML='<h1>'+title+'</h1><p><table cellpadding="3"><tr><td><img src="'+js_dir+'images/icons/error2.gif"></td><td>'+message+'</td></tr></table></p>';
		obj.style.display='';
		scroll(0,0);
		return(true);
	}
	return(false);
}
//__________________________________________________________________________________
function DisplayStatus(s){
	obj=gebid('status_section');
	obj.style.display='none';
	obj.innerHTML=s;
	obj.style.display='';
}
//__________________________________________________________________________________
function HideStatus(){
	gebid('status_section').style.display='none';
}
//__________________________________________________________________________________
function HideError(){
	gebid('error_section').style.display='none';
}
//__________________________________________________________________________________
function isValidEmailAddress( str ) {
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
	if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid
		return true;
	}
	return false;
}
function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}
function isFunction(a) {
    return typeof a == 'function';
}
//__________________________________________________________________________________
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}
//__________________________________________________________________________________
function UpdateDateTo(from_value,n,objId){// n: num_of_days
	a=from_value.split('-'); // YYYY-mm-dd
	var D=new Date();
	D.setDate(Number(a[2]));
	D.setMonth(Number(a[1]));
	D.setFullYear(Number(a[0]));
	N=addDays(D,n);
	gebid(objId).value=N.getFullYear()+'-'+twoDigit(N.getMonth())+'-'+twoDigit(N.getDate());
}
//__________________________________________________________________________________
function addDays(myDate,days) {
    return new Date(myDate.getTime() + days*24*60*60*1000);
}
//__________________________________________________________________________________
function gebid(id){return(document.getElementById(id));}
function gebna(id){return(document.getElementsByName(id));}
function twoDigit(m){return ((m<10)?'0'+m:m)}
function ge(id){return(document.getElementById(id));}
function gv(id){return(ge(id).value);}
function sf(id){ge(id).focus();}
//__________________________________________________________________________________





function compareOptionValues(a, b)
{
var sA = parseInt( a.value, 36 );
var sB = parseInt( b.value, 36 );
return sA - sB;
}
function compareOptionText(a, b)
{
var sA = parseInt( a.text, 36 );
var sB = parseInt( b.text, 36 );
return sA - sB;
}
function moveDualList( srcList, destList, moveAll )
{
if ( ( srcList.selectedIndex == -1 ) && ( moveAll == false ) )
{
return;
}
newDestList = new Array( destList.options.length );
var len = 0;
for( len = 0; len < destList.options.length; len++ )
{
if ( destList.options[ len ] != null )
{
newDestList[ len ] = new Option( destList.options[ len ].text, destList.options[ len ].value, destList.options[ len ].defaultSelected, destList.options[ len ].selected );
}
}
for( var i = 0; i < srcList.options.length; i++ )
{
if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )
{
newDestList[ len ] = new Option( srcList.options[i].text, srcList.options[i].value, srcList.options[i].defaultSelected, srcList.options[i].selected );
len++;
}
}
newDestList.sort( compareOptionValues ); // BY VALUES
for ( var j = 0; j < newDestList.length; j++ )
{
if ( newDestList[ j ] != null )
{
destList.options[ j ] = newDestList[ j ];
}
}
for( var i = srcList.options.length - 1; i >= 0; i-- )
{
if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )
{
srcList.options[i] = null;
}
}
} // End of moveDualList()
// End -->