var change;
change=0;
function byt() {
		change=1;
}

function newpage(sida){
	if (change==1)
	{

			change=0;
			document.buyprod.action="tom.asp?todo=" + sida
			document.buyprod.submit()

	}
	else
	{
//		alert(sida+".asp")
		location=sida+".asp"
	}
}

function addrows(sida) {
		change = 0;
		document.buyprod.action="tom.asp?todo=" +sida
		document.buyprod.submit()
}

function update(){
	if (change==1){
		var name = confirm("Vill du uppdatera varukorgen?")
		if (name == true){
			document.buyprod.action="tom.asp"
			document.buyprod.target="meny1"
			document.buyprod.submit()
		}
	}
}
function mailaorder() {
dtFormat = 'YYYY-MM-DD'
udt = document.buyprod.datum.value;
	if (udt.length>0){
		if(udt.indexOf("-") == -1){
			alert('Datumformatet ska vara:'+dtFormat);
			document.buyprod.datum.focus();
			return false;
		}
		dt1 = udt.split("-")
		dd1 = parseInt(dt1[2],10);
		mm1 = parseInt(dt1[1],10);
		yy1 = parseInt(dt1[0],10);
		if(isNaN(yy1) || isNaN(mm1) || isNaN(dd1)){
			alert('Invalid Date ! '+yy1+'-'+mm1+'-'+dd1);
			document.buyprod.datum.focus();
			return false;
		}
		
		dt2 = new Date(yy1+'/'+mm1+'/'+dd1)
		egd = dd2 = dt2.getDate();
		mm2 = dt2.getMonth()+1;
		yy2 = dt2.getFullYear();
		
		if(dd1==dd2 && mm1==mm2 && yy1==yy2){
			dt3 = new Date();
			dd3 = dt3.getDate();
			mm3 = dt3.getMonth()+1;
			yy3 = dt3.getFullYear();
			dt3 = new Date(yy3+'/'+mm3+'/'+dd3);
			
				if(dt2>=dt3){
				mailaorder2();
				}
				else{
				alert('Man kan bara skriv ett datum i framtiden');
				document.buyprod.datum.focus();
				return false;
				}
			}
		else{
			alert('Otillåtet datum');
		document.buyprod.datum.focus();
		return false;
		}
	}
	else{
	mailaorder2();
	}
}
function mailaorder2() {
		if (change==1)
		{
		change = 0;
		document.buyprod.action="/post/index.asp?todo=maila"
		document.buyprod.submit()
		}
		else
		{
		document.buyprod.action="/post/mail.asp"
		document.buyprod.submit()
		}
}
function loggaut(){
	if (change==1)
		{
		change = 0;
		}
	location='loggaut.asp';
}
function loggautupdate(){
	parent.kundkorg.location.href="kundkorg.asp"
	parent.meny1.location.href="tom.asp"
}
function submit_login(typ)
{
	if (typ=='2'){
		document.login.kundtyp.value="demokund"
		return true;
	}
	else{
    	if (document.login.namn.value == "") {
        	alert('Användarnamn eller lösenord saknas');
        	document.login.namn.focus();
			return false;
    	} else if (document.login.losenord.value == "") {
        	alert('Användarnamn eller lösenord saknas');
        	document.login.lösenord.focus();
			return false;
    	} else {
			document.login.kundtyp.value="kund"
        	return true;
    	}
	}
}
function noSpam(user,domain){ 
	locationstring = "mailto:" + user + "@" + domain; 
	window.location = locationstring; 
}

function getHTTPObject() {
	var xmlhttp;
	/*@cc_on
	@if (@_jscript_version >= 5)
		try {
			xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e) {
			try {
				xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
			} catch (E) {
				xmlhttp = false;
			}
		}
	@else
		xmlhttp = false;
	@end @*/

	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp = false;
		}
	}

	return xmlhttp;
}

var http = getHTTPObject();

function receiveResults()
{
	if(http.readyState == 4)
	{
		if(http.status == 200)
		{
			data = http.responseText;

			if(data == 'plus')
				alert('Artikeln inlagd bland favoriterna.');
			else if(data == 'minus')
				alert('Artikeln borttagen.');	
			else if(data == 'redan')
				alert('Artikeln finns redan bland dina favoriter.');
			else
				alert('Något blev fel:');
		}
		else
			alert('Det uppstod ett serverfel vid rättningen. Försök igen senare.');
	}
}

function favoritadd(x)
{
	http.open('GET', '/kundzon/favoriter/lista.asp?i='+x+'&a=1', true);
	http.onreadystatechange = receiveResults;
	http.send(null);
}
function favoritdel(x)
{		
	document.getElementById("F_"+x).innerHTML="<INPUT TYPE=text NAME=H_"+x+" size=6 value =0>";
	document.getElementById(x).style.display='none';
	http.open('GET', '/kundzon/favoriter/lista.asp?i='+x+'&a=2', true);
	http.onreadystatechange = receiveResults;
	http.send(null);
}

function radera(artnr){
	var name = confirm("Är du säker på att du vill ta bort orderraden?")
	if (name == true){
	document.buyprod.action="/post/index.asp";
	document.getElementById(artnr).style.display='none';
	document.getElementById("F_"+artnr).innerHTML="<INPUT TYPE=text NAME=H_"+artnr+" size=6 value =0>";
	document.buyprod.submit()
	}
}
function doLoad()
{
    // the timeout value should be the same as in the "refresh" meta-tag
    setTimeout( "refreshteaser()", 5*1000 );
}

function refreshteaser()
{
    //  This version of the refresh function will cause a new
    //  entry in the visitor's history.  It is provided for
    //  those browsers that only support JavaScript 1.0.
    //
    http.open('GET', 'startteaser.asp', true);
	http.onreadystatechange = receiveTeaser;
	http.send(null);
	doLoad()
	//document.getElementById('start-teaser').innerHTML = "test";
	//doLoad()
}
function receiveTeaser()
{
	if(http.readyState == 4)
	{
		if(http.status == 200)
		{
		document.getElementById('start-teaser').innerHTML = http.responseText;
		}
	}
}
function retail_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}