var activeSub=0;
var SubNum=0;

function reDo(){ window.location.reload() }
if (document.layers) {
    //alert ("Running Netscape 4");
}
else {
    // window.onresize = reDo;
}

//Define global variables
var timerID = null;
var timerOn = false;
var timecount = 500;
var what = null;
var newbrowser = true;
var check = false;
var new_window;

function init(){
    //alert ("Running Init");
    if (document.layers) {
	//Netscape 4
	layerRef="document.layers";
	styleSwitch="";
	visibleVar="show";
	screenSize = window.innerWidth;
	what ="ns4";
	
    }else if(document.all){
	//IE
	layerRef="document.all";
	styleSwitch=".style";
	visibleVar="visible";
	screenSize = document.body.clientWidth + 18;
	what ="ie";
	
    }else if(document.getElementById){
	//Netscape 6
	layerRef="document.getElementByID";
	styleSwitch=".style";
	visibleVar="visible";
	what="moz";
	
    }else{
	//Older than 4.0 browser
	what="none";
	newbrowser = false;
    }
    window.status='SK Svejsemateriel A/S';
    check = true;
}

// Turns the layers on and off
function showLayer(layerName){
    if(check){
	if (what =="none"){
	    return;
	}
	else if (what == "moz"){
	    document.getElementById(layerName).style.visibility="visible";
	}
	else{
	    eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="visible"');
	}
    }
    else {// alert ("Please wait for the page to finish loading.");
	return;}
}

function hideLayer(layerName){
    if(check){
	if (what =="none"){
	    return;
	}
	else if (what == "moz"){
	    document.getElementById(layerName).style.visibility="hidden";
	}
	else{
	    eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"');
	}
        
    }
    else {// alert ("Please wait for the page to finish loading.");
	return;}
}


function hideAll(){
    hideLayer('layer1');
}


function startTime() {
    if (timerOn == false) {
	timerID=setTimeout( "hideAll()" , timecount);
	timerOn = true;
    }
}

function stopTime() {
    if (timerOn) {
	clearTimeout(timerID);
	timerID = null;
	timerOn = false;
    }
}
 function onLoad(){
     init();
 }
function window_close() {
    new_window.close();
}

function changeLink(myForm,actionNo){
    alert("hej");
    myForm.navact.value=actionNo;
    myForm.action="index.php";
    myForm.submit();	
}

function confirmSubmit(txt){
    if(confirm(txt))
	return true ;
    else
	return false ;
}

function areYouSure(myForm,url,txt,incase){
  if(confirmSubmit(txt)){
    myForm.action = url;
    myForm.check.value = 'ersat';
    myForm.submit();
  }
  else {
    myForm.action = url;
    myForm.check.value = '';
    myForm.submit();
  }
}

function isEmpty(strcompany,stremail,strnumber) {
    strcompany = document.forms[0].company.value;
    stremail = document.forms[0].email.value;
    strnumber = document.forms[0].antal0.value;
    if (strcompany == "" || strcompany == null 
	|| !isNaN(strcompany) || strcompany.charAt(0) == ' '){
	alert("Udfyld venligst \"Navn kunde\".");	
	return false;
    }
    if (stremail == "" || stremail == null || 
	stremail.charAt(0) == ' '){
	alert("Udfyld venligst \"E-mail adresse\".");
	return false;
    }
    if (strnumber.length == 0){
	alert("Udfyld venligst \"Antal\".");	
  	return false;
    }
    var val = parseInt(strnumber);
    if ((val < 1) || (val > 100000)){
  	alert('Antal skal være mellem 1 og 100000');
  	return false;
    }
    return true;
}

function isValidEmail(strEmail){
    validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
    strEmail = document.forms[0].email.value;
    if (strEmail.search(validRegExp) == -1){
	alert('E-mail adressen \" '+strEmail+'\" er ikke korrekt. \nUndersøg om adressen er korrekt og prøv venligst igen.');
	return false;
    } 
    return true; 
}

function checkIt(form,val){
    if (isEmpty(form.company)){
	if (isEmpty(form.email)){
	    if (isValidEmail(form.email)){
		if (isEmpty(form.antal0)){
		    form.ccemail.value=val;
		    form.action='sendorder.php';
		    form.submit();
		}
	    }
	}     
    }
    return false;
}

function checkAndPrint(form){
    if (isEmpty(form.company)){
	if (isEmpty(form.email)){
	    if (isValidEmail(form.email)){
		if (isEmpty(form.antal0)){
		    new_window = window.open("","kvittering","dependent");
		    new_window.document.writeln('<html>');
		    new_window.document.writeln('<head>');
		    new_window.document.writeln('<title>Kvittering for bestilling<\/title>');
		    new_window.document.writeln('<\/head>');
		    new_window.document.writeln('<body onLoad="window.print();">');
		    new_window.document.writeln("<table id=\"toptable\">");
		    new_window.document.writeln("<tr><th>BESTILLINGSLISTE</th></tr>");
		    new_window.document.writeln("<tr><td>E-mail:</td><td>"+document.forms[0].email.value+"</td></tr>");
		    new_window.document.writeln("<tr><td>Navn kunde:</td><td>"+document.forms[0].company.value+"</td></tr>");
		    new_window.document.writeln("<tr><td>Dato:</td><td>"+document.forms[0].date.value+"</td></tr>");
		    new_window.document.writeln("<tr><td>Ref nr:</td><td>"+document.forms[0].ref.value+"</td></tr>");
		    new_window.document.writeln("</table>");
		    new_window.document.writeln("<table border=\"0\"><tr>");
		    new_window.document.writeln("<th class=\"count\">Antal</th><th class=\"number\">Nummer</th>");
		    new_window.document.writeln("<th class=\"article\">Beskrivelse</th><th class=\"remark\">Bem&aelig;rkninger</th></tr>");
		    antal = 'antal0';
		    number = 'no0';
		    article = 'artikel0';
		    remark = 'remark0';
		    var i=0;
		    while(!(document.forms[0].elements[antal].value=="")){
			new_window.document.writeln("<tr><td class=\"count\">"+document.forms[0].elements[antal].value+"</td>");
			new_window.document.writeln("<td class=\"number\">"+document.forms[0].elements[number].value+"</td>");
			new_window.document.writeln("<td class=\"article\">"+document.forms[0].elements[article].value+"</td>");
			new_window.document.writeln("<td class=\"remark\">"+document.forms[0].elements[remark].value+"</td></tr>");
			i++; 
  			antal = 'antal'+i;
			number = 'no'+i;
			article = 'artikel'+i;
			remark = 'remark'+i;
		    }
		    new_window.document.writeln("</table>");
		    new_window.document.writeln("<\/body>");
		    new_window.document.writeln("<\/html>");
		    new_window.document.close();
		    form.action='sendorder.php';
		    form.submit();
		}
	    }
	}     
    }
    return false;
}    


