function bytbild(img,ny){
        if (document.images){
	 document.images[img].src = ny;		
}}


/**
* pops a window
*/
function printpop(url,name) {
	popupWin = window.open(url, name,'toolbar=1,location=no,directories=0,status=1,menubar=1,scrollbars=1,resizable=yes,width=640,height=600')
	
}

function credpop()
{
   	window.open('cred.asp','cred','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,height=270,width=350')
}

function SearchPop(sida,namn) {


				window.open(sida+'?namn='+document.searchform.namn.value, namn, 'toolbar=no,location=no,status=no,menubar=no,resizable=no,scrollbars=yes,width=510,height=400,screenX=40,screenY=300,dependent=no');
			}

function go1(){ 
if 
(document.selecter1.select1.options[document.selecter1.select1.selectedIndex 
].value != "none") { 
location = 
document.selecter1.select1.options[document.selecter1.select1.selectedIndex] 
.value 
} 
} 



/**
* check the form
*/
function CheckVarumarkenSearchForm(obj){
	
	if (obj.query.options[document.forms[0].query.selectedIndex].value != -1){
		return true;
	}else{
		return false;
	}

}


function Open(sida,namn) {
				window.open(sida, namn, 'toolbar=no,location=no,status=no,menubar=no,resizable=no,scrollbars=yes,width=560,height=560,screenX=100,screenY=300,dependent=no');
			}


function check_email(e){
ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

for(i=0; i < e.length ;i++)
{
if(ok.indexOf(e.charAt(i))<0)
{ 
return (false);
}	
} 

if (document.images) {
re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (!e.match(re) && e.match(re_two)) 
{
return (-1);		
} 

}

}

function check_form(f){

var test = false;
for (var i=0;
i<f.Typ.length; 
i++) if (f.Typ[i].checked) 
{ 
test = true; 
}
if (!test) 
{ 
alert('Du måste välja typ av förfrågan.'); 
return false;
} 

if(f.Namn.value.length < 1)
{
alert("Du måste fylla i ditt namn.");
f.Namn.focus();
if(document.all || document.getElementByID)
{
f.Namn.style.background = "red";
}
return false;
}

if(!check_email(f.Email.value))
{
alert("Ogiltig E-postadress.");
f.Email.focus(); 
if(document.all || document.getElementByID)
{
f.Email.style.background = "red";
}
return false;
}

}



function CheckPersNr(persnr){
var summa = 0;
for(i = 0; i < 10; i++){
var x = parseInt(persnr.substr(i,1));
if(i % 2 == 0){
x = 2 * x;
}
summa += (parseInt(x / 10)) + (x % 10);
}
if(summa % 10 == 0){
return true;
}else{
return false;
}
}



function VerifyData()
{
	var persnr = document.frmUser.Pnr.value;
    
	if ((document.frmUser.FNamn.value == "") || (document.frmUser.ENamn.value == "") || (document.frmUser.Pnr.value == "") || (document.frmUser.Gadd.value == "") || (document.frmUser.Postnr.value == "") || (document.frmUser.Padd.value == "") || (document.frmUser.Epost.value == "")) {
      		alert ("Du måste fylla i alla rutor !!");
      		return false;
    	}else{ 
		if (CheckPersNr(persnr)){
			if (document.frmUser.Losen.value != document.frmUser.VerifyPassword.value){
      			alert ("Lösenorden stämmer ej -- Testa igen");
      			return false;
			}else{
			return true;}
		}else{
		alert('Ej giltigt personnummer !!');
		return false;
		}
	}
		
  }

function check_box()
{
	if (!document.betalla.villkor.checked){
		alert("Du måste läsa och godkänna beställningsvillkoret.");
		return false;
	} 
}


function check_fields()
{
	if ((document.bestalla.Org.value == "") || (document.bestalla.Namnlev.value == "") || (document.bestalla.Epostlev.value == ""))
		{
			alert("Du måste fylla i alla fält som är obligatoriska!");
			return false;
		}
	if (!document.bestalla.villkor.checked)
		{
			alert("Du måste läsa och godkänna beställningsvillkoret.");
			return false;
		}
}

function check_pris(p){

ok = "1234567890";

for(i=0; i < p.length ;i++)
{
if(ok.indexOf(p.rakna.value.charAt(i))<0)
{ 
alert("Ogiltigt värde.");
return false;
}	
} 
}

function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
else
cntfield.value = maxlimit - field.value.length;
}		


function VerifyRegForetagsUser()
{
    
	if ((document.frmUser.Foretagsnamn.value == "") || (document.frmUser.Orgnr.value == "") || (document.frmUser.Fnamn.value == "") || (document.frmUser.Enamn.value == "") || (document.frmUser.Gadd.value == "") || (document.frmUser.Postnr.value == "") || (document.frmUser.Padd.value == "") || (document.frmUser.Epost.value == "") || (document.frmUser.Tel.value == "")) {
      		alert ("Du måste fylla i alla rutor !!");
      		return false;
    	}else{ 
		if (document.frmUser.Losen.value != document.frmUser.VerifyPassword.value){
      			alert ("Lösenorden stämmer ej -- Testa igen");
      			return false;
		}else{
			return true;}
	}
		
  }

function PrePop(sida,motiv,namn) {


				window.open(sida+'?namn='+document.previewform.onskar.value+'&rubrik1='+document.previewform.rubrik1.value+'&rubrik2='+document.previewform.rubrik2.value+'&message='+document.previewform.message.value+'&datum='+document.previewform.datum.value+'&tid='+document.previewform.tid.value+'&plats='+document.previewform.plats.value+'&plats2='+document.previewform.plats2.value+'&kontakt='+document.previewform.kontakt.value+'&overigt='+document.previewform.overigt.value+'&osa='+document.previewform.osa.value+'&fnamenew='+document.previewform.fnamenew.value+'&lnamenew='+document.previewform.lnamenew.value+'&adressnew='+document.previewform.adressnew.value+'&postnrnew='+document.previewform.postnrnew.value+'&ortnew='+document.previewform.ortnew.value+'&portkod='+document.previewform.portkod.value+'&tel='+document.previewform.tel.value+'&mobil='+document.previewform.mobil.value+'&epost='+document.previewform.epost.value+'&fnameold='+document.previewform.fnameold.value+'&lnameold='+document.previewform.lnameold.value+'&adressold='+document.previewform.adressold.value+'&postnrold='+document.previewform.postnrold.value+'&ortold='+document.previewform.ortold.value+'&typsnitt='+ returnRvalue() +'&mot='+motiv, namn, 'toolbar=no,location=no,status=no,menubar=no,resizable=no,scrollbars=yes,width=700,height=400,screenX=40,screenY=300,dependent=no');
			}

function returnRvalue()
{

for (i=0;i<document.previewform.typsnitt.length;i++)
{
  if (document.previewform.typsnitt[i].checked) return document.previewform.typsnitt[i].value;
}
}

function PreSteg2(sida,motiv,kategori,namn) {
				window.open(sida+'?mot='+motiv+'&kat='+kategori, namn, 'toolbar=no,location=no,status=no,menubar=no,resizable=no,scrollbars=yes,width=700,height=400,screenX=100,screenY=300,dependent=no');
			}

function check_datum_field()
{
	if ((document.previewform.postdate.value == "") || (document.previewform.postdate.value == "ÅÅÅÅ-MM-DD") ){
			alert("Du måste fylla i ett datum när korten ska vara framme");
		return false;
	}else{
		return true;
	}
}


	function submitCheck(frm)
	{
		if (frm.CardNumber)
		{
			var RegularExpression = /^[0-9]{13,16}$/i;
				
			if (! ValidateField(RegularExpression, frm.CardNumber.value))
			{
				alert('Ogiltigt format på kortnumret.');
				frm.CardNumber.focus();
				return false;
			}
			

			sum = 0; mul = 1; l = frm.CardNumber.value.length;
			for (i = 0; i < l; i++) 
			{
				digit = frm.CardNumber.value.substring(l-i-1,l-i);
				tproduct = parseInt(digit ,10)*mul;
				if (tproduct >= 10)
					sum += (tproduct % 10) + 1;
				else
					sum += tproduct;
				if (mul == 1)
					mul++;
				else
					mul--;
			}
			if (!(sum % 10) == 0)
			{
				alert('Ogiltigt format på kortnumret.');
				frm.CardNumber.focus();
				return false;
			}
		}
	}

	function ValidateField(pattern, FieldStr)
	{
		return pattern.test(FieldStr);
	}

function check_fields_fvsmallar()
{
	if ((document.bestalla.Org.value == "")){
			alert("Du måste fylla i alla fält som är obligatoriska!");
		return false;
		}else{
	if (!document.bestalla.villkor.checked){
		alert("Du måste läsa och godkänna beställningsvillkoret.");
		return false;
		}
	}
}

function popup(url,h,w){
window.open(url,"windownamw","toolbar=no,resizable=no,location=no,directories=no,status=no,menubar=no,scrolling=yes,width=" + w + ",height=" + h);
}