var dom = (document.getElementById)? true:false;
var dom= (document.getElementById)? true:false
var ns4= (document.layers)? true:false
var ie4= (document.all && !document.getElementById)? true:false
var active = 0
var whitespace =" \t\n\r ";

if (dom) {
	doc = "document.getElementById(\""
	sty = "\").style"
}

if (ns4){
	doc = "document."
	sty = ""
}

if (ie4){
	doc = "document.all[\""
	sty = "\"].style"
}

/*	~~ Routine for alternate row colors of a table ~~~~~~~~~~~~~~~~~~~~~~~~~ */
function fdU(sStr){ return(sStr.replus());}
function fnStripes() {
	var ids = document.getElementsByTagName("table");
	for(k = 0;k < ids.length; k++){
		var id = ids[k].id;		
		if(id){	
			var table = document.getElementById(id);
			var rows = table.getElementsByTagName("tr");	
			for(i = 0; i < rows.length; i++){
				if(rows[i].className == "" ) {
					if (i % 2 == 0){
						rows[i].className = "evRow";
						rows[i].onmouseout = function() {this.className= "evRow"; return false}
					}
					else
					{
						rows[i].className = "odRow";
						rows[i].onmouseout = function() {this.className= "odRow"; return false}
					}
					rows[i].onmouseover = function() {this.className='ruled';return false}
				}
			}
		}
	}
}

function fnRow() {
	var ids = document.getElementsByTagName("table");
	for(k = 0;k < ids.length; k++){
		var id = ids[k].id;		
		if(id){	
			var table = document.getElementById(id);
			var rows = table.getElementsByTagName("tr");	
			for(i = 0; i < rows.length; i++){
				if(rows[i].className == "" ) {
					if (i % 2 == 0){
						rows[i].className = "evRow";						
					}
					else
					{
						rows[i].className = "odRow";
					}
				}
			}
		}
	}
}

/*	~~ Routine for changing colors on focus of input boxes ~~~~~~~~~~~~~~~~~~~~~~~~ */
function fnCFocus(obj) {
	obj.style.backgroundColor = '#f2faf9';
	obj.style.borderColor = '#75a7a3';
	obj.style.color = '#ff0000';
}

function fnCBlur(obj) {
	obj.style.backgroundColor = '#ffffff';
	obj.style.borderColor = '#75a7a3';
	obj.style.color = '#000000';
}

function isNumeric(val){
	var msg = parseFloat(val,10)==(val*1);
	if (msg=true && (val*1)>=0) {
		return true;
	} else {
		return false;
	}
}

function IsEmail(sEmail) 
{	
	sEmail=sEmail.trim();
	if( sEmail != "" ) {
		if( !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(sEmail)) ) {
			return false;
	    }
	}
	return true;
}

/* ~~ Routine for Trim function ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
String.prototype.trim = function(){
	return this.replace(/(^\s*)|(\s*$)/g, "");
}


/* ~~ Routines for Page Setting function ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
function  SetPage(cnt,totpg){	 
	var pgno ,pgval;
	pgno = eval("document.display.txtset"+cnt);
	pgval = pgno.value;
	
  if(!isNumeric(pgval)){
			alert(" - Specify numeric value.")
  }else if( pgval<=0 || pgval > totpg){
  alert(" - Vennligst velg gyldig linjer nr..");
	}else{
		pgval=pgval-1
		changeActive(pgval);		
	}
}

function init(pg) {
	oQuest = new Array();
	var qname = ''
	for (var k=0; k<=pg; k++) {
		qname = 'dv'+k
		oQuest[k] = new createLayer(qname);
	}
	oQuest[0].css.display = "block";
}

function changeActive(num,totPg){	
	oQuest[active].css.display = "none"
	active = num
	oQuest[active].css.display = "block"

	if(eval(num+1)==eval(totPg))
		document.getElementById("spNxt"+num).style.display ="none";
}

function createLayer(obj){
	this.css = eval(doc + obj + sty)
	return this
}

function isEmpty(str) {return ((str == null) || (str.length == 0));}

function isWhitespace(str) {
	var i;
	var flag
	if (isEmpty(str)) return true;		
	for (i = 0; i < str.length; i++) {   
		var c = str.charAt(i);
		if (whitespace.indexOf(c) == -1)
		return false
	}	
		return true;
}

function IsNumber(strString)
{
	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;

	if (strString.length == 0) return false;

	for (i = 0; i <strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
		{
			blnResult = false;
		}
	}
	if (blnResult==true)
	{
		if(parseInt(strString)<=0)
		{
			return false;
		}
	}
	return blnResult;
}
function SetPage(){
	var frm = document.frmRaceList;
	var totPgs  = frm.hidPages.value; 
	var curPgs  = frm.txtset.value; 
	if(isWhitespace(curPgs)==true){
		alert("- Vennligst velg gyldig linjer nr.");
		frm.txtset.focus();
	}
	else{
		if(IsNumber(curPgs)==false){
			alert("- Vennligst velg gyldig linjer nr.");
			frm.txtset.focus();
		}
		else{
			if( eval(curPgs) <= 0 || eval(curPgs) > eval(totPgs)){
				alert("- Vennligst velg gyldig linjer nr.");
				frm.txtset.focus();
			}
			else
				fnPrevNextPg();
		}
	}
}
String.prototype.trim = function(){	return this.replace(/(^\s*)|(\s*$)/g, "");}
String.prototype.plus = function(){ return this.replace(/\+/g, "%2B");}
String.prototype.replus = function(){ return this.replace(/%2B/g, "+");}

function trim(pstrString) {
	return pstrString.replace(/(^\s*)|(\s*$)/g, "");
}

/* ------------ Routine for Zebra Tables ------------ */
function stripe() {
	var ids = document.getElementsByTagName("table");
	for(k = 0;k < ids.length; k++){
		var id = ids[k].id;		
		if(id){	
			var table = document.getElementById(id);
			var rows = table.getElementsByTagName("tr");	
			for(i = 0; i < rows.length; i++){
				if(rows[i].className == "" ) {
					sRc = (i % 2 == 0) ? "evRow":"odRow";
					rows[i].className = sRc;
				}
				
				if(rows[i].parentNode.nodeName=='TBODY') {
					rows[i].onmouseover = function() {this.className='ruled';return false}
					if (i % 2 == 0) {
						rows[i].onmouseout = function() {this.className= "evRow"; return false}
					} else {
						rows[i].onmouseout = function() {this.className= "odRow"; return false}
					}
				}
			}
		}
	}
}

function fnFillCombo(cmbNm, arrNm, dval){
    var select = document.getElementById(cmbNm);
    var i;    
    select.options[select.options.length] = new Option("Select","0");    
    for(i = 0; i< arrNm.length;i++){
		select.options[select.options.length] = new Option(arrNm[i][1],arrNm[i][0]);	    				 
	}
	if(dval){
	  select.value = dval
	}
}

function fnEnQuote(str){
    str = str.replace(/\'/g,"&#039;"); 
    str = str.replace(/\"/g,"&#034;"); 
    return str;
}