function open_window(page,w,h,tit) {
  a=window.open(page,tit,'toolbar=no,location=no,directories=no,status=no,resizable=yes,copyhistory=no,width='+w+',height='+h+',scrollbars=yes');
  a.focus();
  return false;
}
/*
function update_bets(betIndex){
  console.debug('update_bets: '+ betIndex);

  course_win = document.getElementById("bets_"+betIndex+"_course_win");
  course_draw = document.getElementById("bets_"+betIndex+"_td_course_draw");
  course_loose = document.getElementById("bets_"+betIndex+"_td_course_loose");
  if(course_win && course_draw && course_loose){
    validatefloat(course_win,1,2);
    course_draw.innerHTML = course_win.value; 
  }
}
*/





function validatefloat(item,positive,fixed){
  if(fixed == undefined)
    fixed=3;
  //alert('validatefloat'+item);
  myval = parseFloat(item.value);
  if (isNaN(myval)){
    myval = '0';
  }
  if(positive==true && myval<0)
    myval = -myval;
  
  item.value= RoundFloat(myval,fixed);
}

function validatenumber(item){
  //alert('validatenumber');
  myval = parseInt(item.value);
  if (isNaN(myval)){
    myval = '0';
  }
  item.value= myval;
}

/**
 * RoundFloat() - round the number to specified count of decimal points
 * @param X - Input number
 * @param N - Number of decimal points
 * @param exact - if result will be with exact decimal numbers
 * 
 * @return Rounded Number      
 **/

function RoundFloat(X, N){
  Xint = parseInt(X);
  if(Xint == X) // if integer - do not use float
    return Xint;

  if (X.toFixed) // if browser supports toFixed() method
    return X.toFixed(N)*1;

  return X;
}

function validate_inputtext(itemid,errorid,strlen,formOK,displaylive){
  errorblock = document.getElementById(errorid);
	if(document.getElementById(itemid)) {
		if(document.getElementById(itemid).value.length < strlen){
			if(formOK)
			  document.getElementById(itemid).focus();
			formOK = false;
			if(errorblock)
			  errorblock.style.display = displaylive;
		  document.getElementById(itemid).parentNode.className = 'alert';
		} else {
			if(errorblock)
        errorblock.style.display = 'none';
      document.getElementById(itemid).parentNode.className = '';
    }
	}
	return formOK;
}

function validate_inputnumber(itemid,errorid,formOK,displaylive,min,max){
  errorblock = document.getElementById(errorid);
  myitem = document.getElementById(itemid);
	if(myitem) {
	  validatenumber(myitem);
		if(myitem.value < min || myitem.value > max){
			if(formOK)
			  myitem.focus();
			formOK = false;
			myitem.parentNode.className = 'alert';
			if(errorblock)
			  errorblock.style.display = displaylive;
		} else {
      myitem.parentNode.className = '';		
			if(errorblock)
        errorblock.style.display = 'none';
    }
	}
	return formOK;
}

function validate_inputfloat(itemid,errorid,formOK,displaylive,min,max,fixed){
  myitem = document.getElementById(itemid);
	if(myitem) {
	  validatefloat(myitem,true,fixed);
		if(myitem.value < min || myitem.value > max){
			if(formOK)
			  myitem.focus();
			formOK = false;
			myitem.parentNode.className = 'alert';
			document.getElementById(errorid).style.display = displaylive;
		} else {
      myitem.parentNode.className = '';		
      document.getElementById(errorid).style.display = 'none';
    }
	}
	return formOK;
}


function validate_select(itemid,errorid,formOK,displaylive){
  myselect = document.getElementById(itemid);
  if(myselect){
    myval = myselect[myselect.selectedIndex].value;
		if(myval == 0){
			if(formOK)
			  myselect.focus();
			formOK = false;
			document.getElementById(errorid).style.display = displaylive;
      document.getElementById(itemid).parentNode.className = 'alert';
		} else {
      document.getElementById(errorid).style.display = 'none';
      document.getElementById(itemid).parentNode.className = '';
    }
  }
  return formOK;    
}

function set_clear_error(myitem,myerror,formOK){
  if(myitem){
    if(myerror){
      myitem.parentNode.className = 'alert';
      if(formOK)
        myitem.focus();
      formOK = false;
    }else{
      myitem.parentNode.className = '';
    }
  }else
    mydebug(myitem);
    
  return formOK;
}

