var xmlHttp;

function showLogistikPreview(omgang, logistik_speditor, logistik_ankomstdag, logistik_ankomstpass, what) { 
	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}


	var divname="sms_preview"+omgang;
	var url="/direct/ajax.php?action=logistik_preview&omgang="+omgang+"&logistik_speditor="+logistik_speditor+"&logistik_ankomstdag="+logistik_ankomstdag+"&logistik_ankomstpass="+logistik_ankomstpass+"&what="+what;
	url=url+"&this="+Math.random();

	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
			if (xmlHttp.responseText.match("<html")) {
				document.getElementById(divname).innerHTML="<div class='preview'><b>Du är inte inloggad.</b></div>";
			} else {
				document.getElementById(divname).innerHTML=xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);

}

function GetXmlHttpObject() {
	var xmlHttp=null;

	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}

	catch (e) {
		//Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	
		catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}

	return xmlHttp;
}





function showhide(action, id) {
	if (action == "show") {
		document.getElementById(id).style.display = "block";
	} else {
		document.getElementById(id).style.display = "none";
	}
}

function showhide_two(action1, id1, action2, id2) {
	showhide(action1, id1);
	showhide(action2, id2);
}


function setfield(theField, theValue) {
	theField.value = theValue;
}

function setfieldIfEmpty(theField, theValue) {
	if (theField.value == "") {
		theField.value = theValue;
	}
}

function confirmation(fraga, url) {
	var answer = confirm(fraga)
	if (answer){
		window.location = url;
	}
}

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 CountLeft(field, count, max) {
	// if the length of the string in the input field is greater than the max value, trim it 
	if (field.value.length > max)
		field.value = field.value.substring(0, max);
	else
		count.value = max - field.value.length;
}

function ortval(theform) {
	document.getElementById('levtypruta').style.display = "none";
	document.getElementById('levruta').style.display = "none";
	theform.salami_leveranstyp[0].checked = false;
	theform.salami_leveranstyp[1].checked = false;
	theform.salami_leveranstyp[2].checked = false;
	
}

