function PopUpGeneric(URL, width, height, text)
	{
	// Popup window with links to image library. 
	var popleft=((document.body.clientWidth - 440) / 2)+window.screenLeft; 
	var poptop=(((document.body.clientHeight - 460) / 2))+window.screenTop-40;		
	window.open(URL,"_blank","resizable=1,scrollbars=auto,width=" + width + ",height=" + height + ",left="+popleft+",top="+poptop)
	}

// Function for poping-up images : Reference it like this in the html: 
// <a href="javascript:;" onClick="PopUpImg('jpg','/assets/layout/my_image.jpg','640','480','Image 1','0','0')">Click!</a> 
function PopUpImg(imageType,imageName,imageWidth,imageHeight,alt,posLeft,posTop) {
 screenh = window.screen.height;
 screenw = window.screen.width;
 posLeft = (screenw-imageWidth)/2;
 posTop = (screenh-imageHeight)/2;
 theWindow = window.open("","theWindow","width="+imageWidth+",height="+imageHeight+",scrollbars=no,left="+posLeft+",top="+posTop);
 theWindow.document.open();
 theWindow.document.write('<html><title>'+alt+'</title><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">');
 theWindow.document.write('<img src="'+imageName+'" width='+imageWidth+' height='+imageHeight+' alt="'+alt+'" onClick="javascript:window.self.close();" galleryimg="no">');
 theWindow.document.write('</body></html>');
 theWindow.document.close();
 theWindow.focus()
}

// Function that displays wait message when submitting a form
// css-style: .waitMsg { visibility:hidden; color: red; }
// sample code: <span class="waitMsg" ID="id_waitmsg">Loading Data. Please Wait...<br><img id=pbar src="/assets/shop/layout/loading.gif"></span>
function ShowWaitMsg()
{
if(id_waitmsg) id_waitmsg.style.visibility = 'visible';
setTimeout('document.images["pbar"].src = "/assets/shop/layout/loading.gif"', 200);
}

// function for statustext onMouseOver
function WinStat(sMessage) 
{ window.status = sMessage; }

//Function to go to URL
// usage: <input type=button value=""Avbryt"" onClick=gotoURL('" & THIS_SCRIPT & "?mode=listSchemas')>
function gotoURL(url)
{ self.location.href = url; }


// SPECIAL - FUNCTIONS RELATED TO COURSES //
// ************************************** //

function copyInvoiceAddress_SE() // Swedish form
{
 document.forms[0].Faktura_kontaktperson.value = document.forms[0].Namn.value;
 document.forms[0].Faktura_adress.value = document.forms[0].Bostadsadress.value;
 document.forms[0].Faktura_postnr.value = document.forms[0].Bostadsadress_postnr.value;
 document.forms[0].Faktura_ort.value = document.forms[0].Bostadsort.value;
 document.forms[0].Faktura_email.value = document.forms[0].Email.value;
}

function copyInvoiceAddress_EN() // English form
{
 document.forms[0].Invoice_contactname.value = document.forms[0].Name.value;
 document.forms[0].Invoice_address.value = document.forms[0].Address.value;
 document.forms[0].Invoice_zip.value = document.forms[0].Zip.value;
 document.forms[0].Invoice_city.value = document.forms[0].City.value;
 document.forms[0].Invoice_email.value = document.forms[0].Email.value;
}

// *************************
// function confirmSubmit()
// used to clear session
// *************************
function confirmSubmit(url)
{
var agree=confirm("VARNING!\nDenna åtgärd avbryter ordern\noch loggar ut dig!\nVill du fortsätta?");
if (agree)
	{self.location.href = url
	return true ;}
else
	return false ;
}

 // ******************************* //
 // Check login form
 // ******************************* //
 function checkLogin()
 {
 var msg
 var btn = valButton(login.customer_type);
 
 msg = "Du måste" + ":\n";

 //if (document.login.customer_email.value == '' && document.login.customer_id.value == '')
//	{ if (btn == null) {msg += ("- välja företag eller privatperson" + "\n"); } }


 checkEmail = document.login.customer_email.value
 if ((checkEmail.indexOf('@') < 0) || ((checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.'))) 
 { msg += ("- fylla i en korrekt emailadress" + "\n"); }

 if (btn == null) {msg += ("- välja företag eller privatperson" + "\n"); }

	if (msg != "Du måste" + ":\n") {
	alert(msg)
	return;
	}

	else 
	{ document.login.submit() }
}

 // ******************************* //
 // Check Customer submit form
 // ******************************* //
 function checkCustomerSubmit(mInput)
 {
 var msg = "Du måste" + ":\n";
 var myCustType = mInput;

 // var btn = valButton(editcustomer.cust_paymode);
 // if (btn == null) {msg += ("\n - Välja betalningssätt"); }

if (myCustType == 2) { // företag
 if (document.editcustomer.cust_orgnr.value == '') { msg += ("\n - Ange Organisationsnr");}
 if (document.editcustomer.cust_companyname.value == '') { msg += ("\n - Ange Företagsnamn");}
 if (document.editcustomer.cust_invoiceaddress.value == '') { msg += ("\n - Ange faktureringsadress");}
 if (document.editcustomer.cust_invoicezipcode.value == '') { msg += ("\n - Ange faktura postnr");}
 if (document.editcustomer.cust_invoicecity.value == '') { msg += ("\n - Ange faktura ort");}
 if (document.editcustomer.cust_invoicecountry.value == '') { msg += ("\n - Ange faktura land");}

}

 if (document.editcustomer.cust_contactname.value == '') { msg += ("\n - Ange Ditt namn");}
 if (document.editcustomer.cust_phone.value == '') { msg += ("\n - Ange telefonnr");}
 if (document.editcustomer.cust_deliveryaddress.value == '') { msg += ("\n - Ange leveransadress");}
 if (document.editcustomer.cust_deliveryzipcode.value == '') { msg += ("\n - Ange postnr leveransadress");}
 if (document.editcustomer.cust_deliverycity.value == '') { msg += ("\n - Ange leveransort");}
 if (document.editcustomer.cust_deliverycountry.value == '') { msg += ("\n - Ange leveransland");}

checkEmail = document.editcustomer.cust_email.value
 if ((checkEmail.indexOf('@') < 0) || ((checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.'))) 
 { msg += ("\n - Fylla i en korrekt emailadress"); }

 if (msg != "Du måste" + ":\n") {
  alert(msg)
  return;
  }

 else 
 { 
  document.editcustomer.save.value = "Sparar...";
  document.editcustomer.save.disabled = true;
  document.editcustomer.submit() 
  }
}

 // ******************************* //
 // Check Order submit form
 // ******************************* //
 function checkOrderSubmit(mInput,bRadios)
 {
 var msg = "Du måste" + ":\n";
 var myTerms = mInput;
 var blnRadios = bRadios;
 
 
 var btn = valButton(doplaceorder.cust_paymode);

if (blnRadios == '1') {
 if (btn == null) {msg += ("\n - Välja betalningssätt"); }
}

 if (document.doplaceorder.cust_orgnr.value == '') { msg += ("\n - Ange Organisationsnr");}
 if (document.doplaceorder.cust_companyname.value == '') { msg += ("\n - Ange Företagsnamn");}
 if (document.doplaceorder.cust_contactname.value == '') { msg += ("\n - Ange Ditt namn");}
 if (document.doplaceorder.cust_phone.value == '') { msg += ("\n - Ange telefonnr");}
 
 if (document.doplaceorder.cust_invoiceaddress.value == '') { msg += ("\n - Ange faktureringsadress");}
 if (document.doplaceorder.cust_invoicezipcode.value == '') { msg += ("\n - Ange faktura postnr");}
 if (document.doplaceorder.cust_invoicecity.value == '') { msg += ("\n - Ange faktura ort");}
 if (document.doplaceorder.cust_invoicecountry.value == '') { msg += ("\n - Ange faktura land");}

 if (document.doplaceorder.cust_deliveryaddress.value == '') { msg += ("\n - Ange leveransadress");}
 if (document.doplaceorder.cust_deliveryzipcode.value == '') { msg += ("\n - Ange postnr leveransadress");}
 if (document.doplaceorder.cust_deliverycity.value == '') { msg += ("\n - Ange leveransort");}
 if (document.doplaceorder.cust_deliverycountry.value == '') { msg += ("\n - Ange leveransland");}

 
// test av frekvens-validering
 for (var i = 0; i < document.doplaceorder.elements.length; i++) {
  if ((document.doplaceorder.elements[i].name.indexOf('prod_freq_') > -1)) {
   if (document.doplaceorder.elements[i].selectedIndex == 0) {
    var mstring = document.doplaceorder.elements[i].name;
    mstring = mstring.replace("prod_freq_","artikel ");
	msg += ("\n - Välja frekvens för " + mstring);
     }
    }
   }

if (myTerms == 1) { // privatperson + beställt hyrd produkt
 if (!doplaceorder.terms_of_delivery.checked) { msg += "\n\n - Godkänna försäljningsvillkoren"; } 
 if (!doplaceorder.terms_of_hire.checked) { msg += "\n - Godkänna hyresvillkoren"; }
 if (!doplaceorder.cust_over18.checked) { msg += "\n - Garantera att du är 18 år eller äldre"; }
}

if (myTerms == 2) { // privatperson som ej beställt hyrd produkt
 if (!doplaceorder.terms_of_delivery.checked) { msg += "\n - Godkänna försäljningsvillkoren"; } 
 if (!doplaceorder.cust_over18.checked) { msg += "\n - Garantera att du är 18 år eller äldre"; }
}

checkEmail = document.doplaceorder.cust_email.value
 if ((checkEmail.indexOf('@') < 0) || ((checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.'))) 
 { msg += ("\n - Fylla i en korrekt emailadress"); }

 if (msg != "Du måste" + ":\n") {
  alert(msg)
  return;
  }

 else 
 { 
  document.doplaceorder.pay.value = "Bearbetar order...";
  document.doplaceorder.exit.disabled = true;
  document.doplaceorder.pay.disabled = true;
  document.doplaceorder.submit()
  if(id_waitmsg) id_waitmsg.style.visibility = 'visible';
  setTimeout('document.images["pbar"].src = "/assets/shop/layout/loading.gif"', 200);
  }
}

// *************************************************************************************** //
// Radio Button Validation helper function to checkLogin() and checkOrderSubmit(mInput)
// *************************************************************************************** //
function valButton(btn) {
 var cnt = -1;
 for (var i=btn.length-1; i > -1; i--) {
   if (btn[i].checked) {cnt = i; i = -1;}
   }
  if (cnt > -1) return btn[cnt].value;
 else return null;
}

// FUNCTIONS RELATED TO SESSION TIME-OUT //
// Usage: Add the following to your page //
// ************************************* //
// <BODY OnLoad="timeIt()">              //
// <form name="timerform"><input type="text" name="clock" size="7" value="2:00"></form> //
// ************************************* //

// Take user here after session timed out
timedouturl = "session-timed-out.html";

function Minutes(data) {
for (var i = 0; i < data.length; i++)
if (data.substring(i, i + 1) == ":")
break;
return (data.substring(0, i));
}

function Seconds(data) {
for (var i = 0; i < data.length; i++)
if (data.substring(i, i + 1) == ":")
break;
return (data.substring(i + 1, data.length));
}

function Display(min, sec) {
var disp;
if (min <= 9) disp = " 0";
else disp = " ";
disp += min + ":";
if (sec <= 9) disp += "0" + sec;
else disp += sec; 
return (disp);
}

function Down() { 
sec--;      
if (sec == -1) { sec = 59; min--; }
 document.timerform.clock.value = Display(min, sec);
 window.status = "Sessionen avslutas om: " + Display(min, sec) + " minuter";
if (min == 0 && sec == 0) {
alert("Din session har avslutats.");
// window.location.href = timedouturl;
}
else down = setTimeout("Down()", 1000);
}

function timeIt() {
min = 1 * Minutes(document.timerform.clock.value);
sec = 0 + Seconds(document.timerform.clock.value);
Down();
}


// END FUNCTIONS RELATED TO SESSION TIME-OUT //