function tr_hover() {
	var tbl = document.getElementById('tbl');
	if(tbl != null){
	var rowLen = document.getElementById('tbl').getElementsByTagName('tr').length;
	for(i = 0; i < rowLen; i++){
		var sRow = document.getElementById('tbl').getElementsByTagName('tr').item(i);
		if(sRow != null){
			
			sRow.onmouseover = function(){
			for(i = 0; i < this.getElementsByTagName('td').length; i++){
				var el = this.getElementsByTagName('td').item(i);
				el.style.background = '#fffbe0 url(\'images/gradient.png\') left top repeat-x';
				el.style.cursor = 'pointer';
				}
				}
			sRow.onmouseout = function(){
			for(i = 0; i < this.getElementsByTagName('td').length; i++){
				var el = this.getElementsByTagName('td').item(i);
				el.style.background = '';
				}
				}

			}
		}
	}
}
function reloadit(){if(location.href.indexOf('reload')==-1) location.replace(location.href+'?reload');}
function init(){
	tr_hover();
}

// main function to process the fade request //
function colorFade(id,element,start,end,steps,speed) {
  var startrgb,endrgb,er,eg,eb,step,rint,gint,bint,step;
  var target = document.getElementById(id);
  steps = steps || 20;
  speed = speed || 20;
  clearInterval(target.timer);
  endrgb = colorConv(end);
  er = endrgb[0];
  eg = endrgb[1];
  eb = endrgb[2];
  if(!target.r) {
    startrgb = colorConv(start);
    r = startrgb[0];
    g = startrgb[1];
    b = startrgb[2];
    target.r = r;
    target.g = g;
    target.b = b;
  }
  rint = Math.round(Math.abs(target.r-er)/steps);
  gint = Math.round(Math.abs(target.g-eg)/steps);
  bint = Math.round(Math.abs(target.b-eb)/steps);
  if(rint == 0) { rint = 1 }
  if(gint == 0) { gint = 1 }
  if(bint == 0) { bint = 1 }
  target.step = 1;
  target.timer = setInterval( function() { animateColor(id,element,steps,er,eg,eb,rint,gint,bint) }, speed);
}

// incrementally close the gap between the two colors //
function animateColor(id,element,steps,er,eg,eb,rint,gint,bint) {
  var target = document.getElementById(id);
  var color;
  if(target.step <= steps) {
    var r = target.r;
    var g = target.g;
    var b = target.b;
    if(r >= er) {
      r = r - rint;
    } else {
      r = parseInt(r) + parseInt(rint);
    }
    if(g >= eg) {
      g = g - gint;
    } else {
      g = parseInt(g) + parseInt(gint);
    }
    if(b >= eb) {
      b = b - bint;
    } else {
      b = parseInt(b) + parseInt(bint);
    }
    color = 'rgb(' + r + ',' + g + ',' + b + ')';
    if(element == 'background') {
      target.style.backgroundColor = color;
    } else if(element == 'border') {
      target.style.borderColor = color;
    } else {
      target.style.color = color;
    }
    target.r = r;
    target.g = g;
    target.b = b;
    target.step = target.step + 1;
  } else {
    clearInterval(target.timer);
    color = 'rgb(' + er + ',' + eg + ',' + eb + ')';
    if(element == 'background') {
      target.style.backgroundColor = color;
    } else if(element == 'border') {
      target.style.borderColor = color;
    } else {
      target.style.color = color;
    }
  }
}

// convert the color to rgb from hex //
function colorConv(color) {
  var rgb = [parseInt(color.substring(0,2),16), 
    parseInt(color.substring(2,4),16), 
    parseInt(color.substring(4,6),16)];
  return rgb;
}


// Validate FORM
function val(field,alerttxt){
	with (field){if (value == null || value == ""){
	document.getElementById('errorbox').innerHTML = '<div id="feedback"><strong>'+alerttxt+'</strong> må fylles inn.</div>'; colorFade('feedback', 'background', '99cee0', 'edf6f9', 25, 30); return false}
	else {return true}
	}
}
// Validate FORM ELEMENTS WITH EMAIL
function vemail(field,alerttxt)
{
with (field)
{
apos=value.indexOf("@")
dotpos=value.lastIndexOf(".")
if (apos<1||dotpos-apos<2) 
  {document.getElementById('errorbox').innerHTML = '<div id="feedback"><strong>'+alerttxt+'</strong> er ikke fyllt ut riktig.</div>' ; return false}
else {return true}
}
}
// Validate FORM ELEMENTS WITH DIGITS
function vdig(field,alerttxt,min,max)
{
with (field)
{
var alertbox = '';
var datatype = 'I';
checkvalue=parseFloat(value);
if (datatype)
{smalldatatype=datatype.toLowerCase();
if (smalldatatype.charAt(0)=="i")
{checkvalue=parseInt(value); if (value.indexOf(".")!=-1) {checkvalue=checkvalue+1}};
}
if ((parseFloat(min)==min && value.length<min) || (parseFloat(max)==max && value.length>max) || value!=checkvalue)
{if (value !== Number) {
document.getElementById('errorbox').innerHTML = '<div id="feedback"><strong>'+alerttxt+'</strong> er ikke fyllt ut riktig, kun siffer.</div>';
} 
if(value == ''){document.getElementById('errorbox').innerHTML = '<div id="feedback"><strong>'+alerttxt+'</strong> må fylles inn.</div>';}
return false;}
else {return true;}
}
}
// Validate LOGIN
function vlogin(thisform)
{ 
with (thisform)
{	
if (val(username,"Brukernavn") == false) { username.focus();return false }
if (val(password,"Passord") == false) { password.focus();return false }
}
}
// Validate FORGOT PW
function vfpw(thisform)
{ 
with (thisform)
{	
if (vemail(email, "Epost") == false) { email.focus();return false }
}
}
// Validate ORDER
function vob(thisform)
{ 
with (thisform)
{	
if (val(name, "Navn") == false) { name.focus();return false }
if (val(address, "Adresse") == false) { address.focus();return false }
if (val(zip, "Postnummer") == false) { zip.focus();return false }
if (val(area, "Sted") == false) { area.focus();return false }
if (vdig(phone1, "Tlf #1","8","12") == false) { phone1.focus();return false }
if (vemail(email, "Epost") == false) { email.focus();return false }
if (vdig(qty, "Antall oblater","1","3") == false) { qty.focus();return false }
if (val(password, "Passord") == false) { area.focus();return false }
}
}
// Validate BIKE REGISTRATION without session A
function vreg0(thisform)
{ 
with (thisform)
{	
if (val(b_brand, "Sykkelmerke") == false) { b_brand.focus();return false }
if (val(b_model, "Modell") == false) { b_model.focus();return false }
if (vdig(b_price, "Pris","3","8") == false) { b_price.focus();return false }
if (val(b_frame, "Rammenr.") == false) { b_frame.focus();return false }
//if (vdig(ob_num, "Oblatnr.","11","15") == false) { ob_num.focus();return false }
if (val(name, "Navn") == false) { name.focus();return false }
if (val(address, "Adresse") == false) { address.focus();return false }
if (val(zip, "Postnummer") == false) { zip.focus();return false }
if (val(area, "Sted") == false) { area.focus();return false }
if (vdig(phone1, "Tlf #1","8","12") == false) { phone1.focus();return false }
if (vemail(email, "Epost") == false) { email.focus();return false }
if (val(password, "Passord") == false) { password.focus();return false }
}
}
// Validate BIKE REGISTRATION without session B
function vreg0b(thisform)
{ 
with (thisform)
{	
if (val(b_brand, "Sykkelmerke") == false) { b_brand.focus();return false }
if (val(b_model, "Modell") == false) { b_model.focus();return false }
if (vdig(b_price, "Pris","3","8") == false) { b_price.focus();return false }
if (val(b_frame, "Rammenr.") == false) { b_frame.focus();return false }
if (vemail(email, "Epost") == false) { email.focus();return false }
if (val(password, "Passord") == false) { password.focus();return false }
}
}
// Validate BIKE REGISTRATION with session
function vreg1(thisform)
{ 
with (thisform)
{	
if (val(b_brand, "Sykkelmerke") == false) { b_brand.focus();return false }
if (val(b_model, "Modell") == false) { b_model.focus();return false }
if (vdig(b_price, "Pris","3","8") == false) { b_price.focus();return false }
if (val(b_frame, "Rammenr.") == false) { b_frame.focus();return false }
if (val(ob_num, "Oblatnr.") == false) { ob_num.focus();return false }
}
}
// Validate USERREG
function ureg(thisform)
{ 
with (thisform)
{	
if (val(name, "Navn") == false) { name.focus();return false }
if (val(address, "Adresse") == false) { address.focus();return false }
if (val(zip, "Postnummer") == false) { zip.focus();return false }
if (val(area, "Sted") == false) { area.focus();return false }
if (vdig(phone1, "Tlf #1","8","12") == false) { phone1.focus();return false }
if (vemail(email, "Epost") == false) { email.focus();return false }
if (val(password, "Passord") == false) { password.focus();return false }
}
}
function doit(el){
	if (el.checked == true){document.getElementById('chk').className = 'chk' }
	else {document.getElementById('chk').className = 'chk not'}
}
