//Javascripts all coding done by Anders Brännmark
//Please notify me if you want to use any of these scripts at: anders.brannmark@gmx.net

function printNewWindow(strElement, strTitle, strURL, boolAutoPrint){
	//This function retrives a specfied elements contents and opens it a new window that is
	//printer friendly.
	//Title of the new window can be specfied.
	//URL is inserted at the top and bottom of the page information to be printed. 
	//A boolean can be specfied to trigger automatic printing of the new window.
	//Change layout of the elements by using the sperate stylesheet for printing.
	
	if (document.getElementById != null)
	{
		var strHTML;
		
		strHTML = '<html>\n<head>\n<title>' + strTitle + '</title>\n<style type="text/css" media="all">@import "stylesheets/printer.css";</style>\n</head>\n<body class="PrintBody">\n';
		strHTML = strHTML + '<div class="PrintURL">' + strURL + '</div>\n';
		var printReadyElem = document.getElementById(strElement);
		if (printReadyElem != null)
		{
				strHTML = strHTML + '<div class="PrintContents"><br>' + printReadyElem.innerHTML + '<br></div>';
		}
		else
		{
			alert("Kan ej hitta dokumentet för utskrift.\n\nCould not find the document section to print.");
			return;
		}
		
		strHTML = strHTML + '\n<div class="PrintURL">' + strURL + '</div><br>';
		strHTML = strHTML + '\n</body>\n</html>';
		
		var printWindow;
		printWindow = window.open("","PrintWindow","height=500,width=700px,location=no,scrollbars=yes,menubar=yes,toolbars=yes,resizable=no");
		printWindow.document.open();
		printWindow.document.write(strHTML);
		printWindow.document.close();
		if (boolAutoPrint)
			printWindow.print();
		}
	else
	{
		alert("Tyvärr fungerar denna fuktion endast i nyare webläsare.\n\nSorry, the print feature is only available in newer browsers.");
	}
}

function openWindow(urlLink, winName){
	window.open(urlLink, winName);
}

function openWindowInternal(urlLink, winName){
	window.open(urlLink, winName, "width=1024, height=768, menubar=no, status=no, location=no, toolbar=yes, scrollbars=yes, resizable=yes");
}

function openWindowAddress(urlLink){
	window.open(urlLink, "Återförsäljare", "width=400, height=200, menubar=no, status=no, location=no, toolbar=no, scrollbars=no, resizable=no");
}

function addBookmark(){
	var bookmarkUrl;
	var bookmarkTitle;
	
	bookmarkUrl = "http://www.mtnprod.se";
	bookmarkTitle = "Swedish Mountain Products";
	
	if (document.all) {
		window.external.AddFavorite(bookmarkUrl,bookmarkTitle);
	}
}

function createDate(){
	var objDate;
	var dayOfWeek;
	var day;
	var month;
	var year;
	var strDate;
	
	objDate = new Date();
	dayOfWeek = objDate.getDay();
	day = objDate.getDate();
	month = objDate.getMonth();
	year = objDate.getYear();
	
	arrDayName = new Array("Söndag", "Måndag", "Tisdag", "Onsdag", "Torsdag", "Fredag", "Lördag");
	arrMonthName = new Array("Januari", "Februari", "Mars", "April", "Maj", "Juni", "Juli", "Augusti", "September", "Oktober", "November", "December");
	if (year <= 2000) {
		year = year + 1900;
	}
	strDate = arrDayName[dayOfWeek] + " den " + day + " " + arrMonthName[month] + " " + year;
	
	return strDate;
}

function check(theForm) {
    if (theForm.kund.value.length == 0) {
        alert("Fyll i ditt Kundnamn.");
        theForm.kund.focus();
        return false;
    }
    else if (theForm.kundnr.value.length == 0) {
        alert("Fyll i ditt Kundnummer.");
        theForm.kundnr.focus();
        return false;
        }
        else if (theForm.artikelnr1.value.length == 0) {
        alert("Du kan inte skicka en tom beställning");
        theForm.kundnr.focus();
        return false;
        }

    else if ( theForm.epost.value.length > 0 )  {
        var pCnt = 0, sCnt = 0;
        for (index = 1; index < theForm.epost.value.length; index++) {
            if (theForm.epost.value.substring (index-1, index) == '@')
                sCnt++;
            else if (theForm.epost.value.substring (index-1, index) == '.' && sCnt > 0)
                pCnt++;
        }
        if ( sCnt != 1 || pCnt < 1 ) {
            alert ('E-postadressen är felaktig.\nKontrollera och försök igen.')
            theForm.epost.select();
            return false;
        }
    }
    if (theForm.epost.value.length == 0) {
        alert ('Fyll i din e-postadress.');
        theForm.epost.focus();
        return false;
    }
        theForm.epost.value = theForm.epost.value.toLowerCase();
    return true;
}
