function tr_over(obj, col)  { obj.style.backgroundColor=col; }

function tr_out(obj) { obj.style.backgroundColor=''; }

var	ie=document.all;

function start() {
var myobj=document.getElementById? document.getElementById("msgBody") : document.all.msgBody;  
var pageWidth=window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
var pageHeight=document.body.clientHeight + document.body.scrollTop;
var posTop=typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
var msgobj=document.getElementById? document.getElementById("msgDiv") : document.all.msgDiv;
msgobj.style.width = pageWidth;  
msgobj.style.height = pageHeight;  
var x = ((pageWidth/2)-310) + 'px';
var y = (posTop+100) + 'px';
//alert(pageHeight);
myobj.style.left = x;
myobj.style.top = y;
}

function show_warning(txt, act) {
var msgobj=document.getElementById? document.getElementById("msg_txt") : document.all.msgWarn;  
var actobj=document.getElementById? document.getElementById("actLink") : document.all.actLink;  
  if (ie) {
    for( i = 0; i < document.all.tags('SELECT').length; i++ ) {
      obj = document.all.tags('SELECT')[i];
      obj.style.visibility = "hidden";
    }	
  }
  msgobj.innerHTML = "<br>" + txt;
  actobj.href = act;
  document.getElementById('msgDiv').style.visibility = "visible";
}

function hide_warning() {
  if (ie) {
    for( i = 0; i < document.all.tags('SELECT').length; i++ ) {
      obj = document.all.tags('SELECT')[i];
      obj.style.visibility = "visible";
    }	
  }
  document.getElementById('msgDiv').style.visibility = "hidden";
}

function IsValidSymbol(obj, data_type)
{
  var KeyCode = event.keyCode;
  var ReturnTrue = true;

  switch ( data_type ) {
    case "PRICE" :
      if(
        ((48 <= KeyCode)  && (KeyCode <= 57))  ||	//0..9
        (KeyCode == 13)  ||  //CR
        (KeyCode == 10)  ||  //LF
        (KeyCode == 46)  )	 // .
        {
		  if (KeyCode == 46) {
			for (i=0; i<obj.value.length; i++) {
			  if (obj.value.charAt(i) == ".") { ReturnTrue = false; }	
			}  
		    if (ReturnTrue) { return true; }
		    else {
              event.returnValue = false;
              return;
            }
		  } else { return true; }
		}
      else {
        event.returnValue = false;
        return;
      }
    break;
    case "ID" :
      if(
        ((48 <= KeyCode)  && (KeyCode <= 57))  ||	//0..9
        (KeyCode == 13)  ||  //CR
        (KeyCode == 10)  )   //LF
        {return true;}
      else {
        event.returnValue = false;
        return;
      }
    break;
    default :
      return false;
  }
  return false;
}

function valid_submit(max_sum)
{
  max_sum = parseFloat(max_sum);
  max_sum = Math.round(max_sum*100)/100;
  var s = parseFloat(document.trans.sum.value);
  s = Math.round(s*100)/100;
  s = s.toFixed(2);
  var msg1 = "Невалидна сума";
  var msg2 = "Невалидна сума ("+s+" > "+max_sum+")";
  
  if (!isNaN(s)) document.trans.sum.value = s;
  if (isNaN(s) || s <= 0) { alert(msg1); return false; }
  if (s > max_sum) { alert(msg2); return false; }

  if (trans.btn.disabled) return false;
  else {trans.btn.disabled = true; return true;}
}

function sum_onchange(max_sum, send_to)
{
  var t = parseFloat(0.5);
  var s = parseFloat(document.trans.sum.value);
  max_sum = parseFloat(max_sum);
  max_sum = Math.round(max_sum*100)/100;
  
  if (s <= max_sum && s > 0) document.trans.btn.disabled = false;
  if (s > max_sum || isNaN(s) || s <= 0) document.trans.btn.disabled = true;
  
  if (send_to == 'send_user') {
    if (s > 100) t = 1;
    if (s > 500) t = 1.5;
    if (s > 1000) t = 2;
  }
  if (send_to == 'send_bank') t = 2;
  if (send_to == 'send_epay') t = 1;
  
  if (isNaN(s)) {t = 0; s = 0;}
  
  s += t;
  s = Math.round(s*100)/100;
  
  document.getElementById("tax").innerHTML = t.toFixed(2);
  document.getElementById("total").innerHTML = s.toFixed(2);
}

function email_validate() {
    var valid_email = /^[a-zA-Z0-9._-]+[@][a-zA-Z0-9_-]+[.][a-zA-Z0-9._-]*[a-zA-Z0-9_-]+$/
	var email = document.trans.email.value;
	if ( !valid_email.test(email) || email.length>=100 || email.length<10) {
		if ( email != '' )
			alert('Невалиден e-mail ('+email+')');
		else 
			alert('Моля, въведете e-mail на получател!');
		document.trans.email.focus();
		return false;
	} else {
		return true;
	}
}

function show_loading() {
	$('loading').removeProperty('style');
	var html_str = '<div class="generic_dialog_popup"><table class="pop_dialog_table" id="pop_dialog_table"><tbody><tr><td class="pop_topleft"></td><td class="pop_border pop_top"></td><td class="pop_topright"></td></tr><tr><td class="pop_border pop_side"></td><td id="pop_content" class="pop_content"><div class="dialog_content"></div></td><td class="pop_border pop_side"></td></tr><tr><td class="pop_bottomleft"></td><td class="pop_border pop_bottom"></td><td class="pop_bottomright"></td></tr></tbody></table></div>';
	$('loading').set('html', html_str);
}

