function openprint (file) {
	var width = 650;
	var height = 500;
	var leftmargin = 100;
	var topmargin = 50;
	var statusbar = "no";
	var toolbar = "yes";
	var menubar = "yes";
	var title = "printing";
    window.open(file,title,'width='+width+',height='+height+',left='+leftmargin+',top='+topmargin+',scrollbars=yes,status='+statusbar+',toolbar='+toolbar+',menubar='+menubar);
}

function openhelp (url) {
	var width = 450;
	var height = 350;
	var leftmargin = 150;
	var topmargin = 100;
	var statusbar = "no";
	var toolbar = "no";
	var menubar = "no";
	var title = "help";
    window.open(url,title,'width='+width+',height='+height+',left='+leftmargin+',top='+topmargin+',scrollbars=yes,status='+statusbar+',toolbar='+toolbar+',menubar='+menubar);
}

function showimage(file) {
	if (file) {
		window.open("image_popup.html?file="+ file,"imagepopup","width=400,height=400,left=0,top=0");
	} else {
		return false;
	}
}

function showimagewindow(file, imgwidth, imgheight) 
{
	if (file)
	{
		window.open("image_popup.html?file="+ file,"imagepopup","width="+imgwidth+",height="+imgheight+",left=0,top=0");
	} 
	else 
	{
		return false;
	}
}
		
function MM_preloadImages() 
{ //v3.0
	var d=document; 
	if(d.images)
	{ 
		if(!d.MM_p)
		{ 
			d.MM_p=[];
		}
		var i,j=d.MM_p.length, a=arguments; 
		for(i=0; i<a.length; i++)
		{
		if (a[i].indexOf("#")!==0)
		{ 
			d.MM_p[j]=new Image(); 
			d.MM_p[j++].src=a[i];
		}
		}
	}
}
	
function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++){ x.src=x.oSrc; }
}
	
function MM_findObj(n, d) { //v4.0
	var p,i,x;  if(!d) { d=document; } if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all){ x=d.all[n];} for (i=0;!x&&i<d.forms.length;i++){ x=d.forms[i][n];}
	for(i=0;!x&&d.layers&&i<d.layers.length;i++){ x=new MM_findObj(n,d.layers[i].document);}
	if(!x && document.getElementById){ x=document.getElementById(n);} return x;
}
	
function MM_swapImage() { //v3.0
	var i,j=0,x,a=arguments; document.MM_sr=[]; for(i=0;i<(a.length-2);i+=3){
	x = MM_findObj(a[i]);if (x!==null){document.MM_sr[j++]=x; if(!x.oSrc){ x.oSrc=x.src;} x.src=a[i+2];}}
}


function Cm_bwcheck(){
	//In theory we should use object detection, but this script needs work-arounds for almost every browser...
	this.ver=navigator.appVersion;
	this.agent=navigator.userAgent.toLowerCase();
	this.dom=document.getElementById?1:0;
	this.ns4=(!this.dom && document.layers)?1:0;
	this.op=window.opera;
	this.moz=(this.agent.indexOf("gecko")>-1 || window.sidebar);
	this.ie=this.agent.indexOf("msie")>-1 && !this.op;
	if(this.op){
		this.op5=(this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1);
		this.op6=(this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1);
		this.op7=this.dom&&!this.op5&&!this.op6; //So all higher opera versions will use it
	}else if(this.moz) {this.ns6 = 1;}
	else if(this.ie){
		this.ie4 = (!this.dom && document.all);
  	this.ie5 = (this.agent.indexOf("msie 5")>-1);
  	this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1);
  	this.ie6 = this.dom && !this.ie4 && !this.ie5 && ! this.ie55;
	}
	this.mac=(this.agent.indexOf("mac")>-1);
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6 || this.op7);
  this.usedom= this.ns6||this.op7;//Use dom creation
  this.reuse = this.ie||this.op7||this.usedom; //Reuse layers
  this.px=this.dom&&!this.op5?"px":"";
	return this;
}
var bw=new Cm_bwcheck();

function changeCase(obj) {
	var temp = obj.value.substring(0,1);
	var temp2 = obj.value.substring(1,obj.value.length);	
	obj.value = temp.toUpperCase() + temp2;
}

// Opens new window for payment
function openpay(mode) {
	var width = 0;
	var height = 0;
	if (mode == 1){
		width = 725;
		height = 550;
	} else {
		width = 775;
		height = 550;
	}
	var leftmargin = 25;
	var topmargin = 25;
	var statusbar = "yes";
	var toolbar = "no";
	var menubar = "no";
	var resizable = "yes";
	var title = "paywindow";
	var paywindow = window.open('./tpl/empty.html',title,'width='+width+',height='+height+',left='+leftmargin+',top='+topmargin+',scrollbars=yes,status='+statusbar+',toolbar='+toolbar+',menubar='+menubar+',resizable='+resizable);
}

function opentracktrace () {
	var width = 550;
	var height = 350;
	var leftmargin = 100;
	var topmargin = 100;
	var statusbar = "no";
	var toolbar = "no";
	var menubar = "no";
	var title = "winTracknTrace";
	var winTracknTrace = window.open('./tpl/blank.html',title,'width='+width+',height='+height+',left='+leftmargin+',top='+topmargin+',scrollbars=yes,status='+statusbar+',toolbar='+toolbar+',menubar='+menubar);
	window.winTracknTrace.focus();
}

function validate_basket_amount (frm,qty,min_qty,qty_round,colli_size,unit_txt,error_txt_1,error_txt_2,error_txt_3,basketid)
{
	var error_msg = "";
	min_qty = parseFloat(min_qty);
	colli_size = parseFloat(colli_size);
	qty_round = parseFloat(qty_round);
	var min_sale = (min_qty < colli_size) ? colli_size : min_qty;
	
	// Replacing danish decimal formatting
	qty = qty.replace(",",".");
	
	// Finding number of decimals
	var pos = qty.lastIndexOf(".");
	var decimals = (pos == -1) ? 0 : qty.substring(pos+1);
	
	// Calc multiplier for rounding
	var round_multiplier = (qty_round > 0) ? Math.pow(10,qty_round) : 1;	
	
	// Rounding the qty
	qty = (qty_round < decimals.length) ? Math.round(qty * round_multiplier)/round_multiplier : qty;
	
	// Storing rounded value in input field
	var qty_string = String(qty);
	if (basketid.length > 0)
	{
		frm['amount[' + basketid + ']'].value = qty_string.replace(".",",");
	}
	else
	{
		frm.amount.value = qty_string.replace(".",",");	
	}
	
	if((qty.length === 0) || isNaN(qty))
	{
			error_msg = error_txt_1;
	}
	
	if(qty < min_sale)
	{
			error_msg = error_txt_2.replace("%1",min_sale);
			error_msg = error_msg.replace("%2",unit_txt);
	}
	
	if(((qty % colli_size) !== 0) && (colli_size > 0))
	{
			error_msg = error_txt_3.replace("%1",min_sale);
	}			
	return error_msg;
}

var timeout_destination;
function timeout_warning(destination)
{
	var howLong = (1000*60*30*10); //millisec (100ms * 60sec * 30min * 1 hours)
	var t = null;
	timeout_destination  = destination;
	t = setTimeout(close_warning,howLong);
}

function close_warning()
{
//alert("The window has been idle for to long. And due to security you will have to log in again.");
//alert("Going to: "+timeout_destination);
document.location=timeout_destination;
}

/**
Helperfunction to append an onload event to existing loadevents
*/
function addLoadEvent(func)
{
    var oldonload = window.onload;
    if (typeof window.onload != 'function')
    {
        window.onload = func;
    }
    else
    {
        window.onload = function() {
        if (oldonload) 
        {
            oldonload();
        }
            func();
        };
    }
}

function IsNumeric(strString){
    var strValidChars = "0123456789.-";
    var strChar;
    var blnResult = true;
    if (! strString){
        return false;
    }
    for (i = 0; i < strString.length && blnResult == true; i++)
    {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1)
        {
            blnResult = false;
        }
    }
    return blnResult;
}
/**
Converts a variable or array to JSON
Uses the jquery.json-1.3.min.js or similar plugin
*/
function ParseValue(pValue){
    return  $.toJSON(pValue);
}

