﻿function toggleDivDisplay(divId) {
	if (document.getElementById(divId).style.display == "none")
		document.getElementById(divId).style.display = "block";
	else
		document.getElementById(divId).style.display = "none";
}

function showDiv(divId) {
	document.getElementById(divId).style.display = "block";
}

function hideDiv(divId) {
	document.getElementById(divId).style.display = "none";
}

var popupWindow = false; 
function openPopup(url,w,h) {
	x = screen.width/2-w/2;
	y = screen.height/2-h/2;
	if (popupWindow) popupWindow.close();
    popupWindow=window.open(url,'ny','toolbar=no,copyhistory=no,location=no,' + 'directories=no,status=no,menubar=no,scrollbars=no,' +'resizable=no,width=' + w + ',height=' + h + ',top=' + y +',left=' + x);
}

function openPopupPay(url,w,h) {
	x = screen.width/2-w/2;
	y = screen.height/2-h/2;
	if (popupWindow) popupWindow.close();
    popupWindow=window.open(url,'ny','toolbar=no,copyhistory=no,location=yes,' + 'directories=no,status=yes,menubar=no,scrollbars=yes,' +'resizable=no,width=' + w + ',height=' + h + ',top=' + y +',left=' + x);
}

function checkPreview(id, plateText, plateId)
{
	if (plateText == ''){alert('Du måste fylla i en text på skylten'); return false;}
	var xmlHttp;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		try
		  {
		  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		catch (e)
		  {
		  alert("Your browser does not support AJAX!");
		  return false;
		  }
		}
	  }
	var url="/includes/asp/searchImage.asp";
	url=url+"?image="+plateId;
	plateText = plateText.replace(/&/g,"*am*");
	plateText = plateText.replace(/=/g,"*eq*");
	plateText = plateText.replace(/\+/g,"*pl*");
	plateText = plateText.replace(/\%/g,"*pr*");
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			if (xmlHttp.responseText == 'error'){
			alert ('Angivet id ej möjligt att förhandsgranska')
			}
			else{
				id.href="/includes/asp/aspjpeg.asp?image="+plateId+".jpg&text="+plateText+"&<%=now()%>";
				myLightbox.preloadNeighborImages(id)
				myLightbox.start(id);
				
				id.href="#";
			}
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}