// JavaScript Document

function fdispatchnote(dn) {
	var url="lyn-finddespatchnote.asp";
	var dnAJAX=new ajaxRequest();
	var dn = encodeURIComponent(dn);
	var parameters="dn="+dn;
	dnAJAX.onreadystatechange=function(){
	 if (dnAJAX.readyState==4){
		if (dnAJAX.status==200 || window.location.href.indexOf("http")==-1){
			var returneddata = dnAJAX.responseText
			if (returneddata.indexOf("OK") >-1) {
				var xx = returneddata.split("|");
				parent.location="ipn/l-despatchnote.asp?custom="+xx[1];
			}

		}
		else{
		 alert(dnAJAX.responseText+"An error has occured trying to find the dispatch note")
		}
	 }
	}
	dnAJAX.open("POST", url, true)
	dnAJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	dnAJAX.send(parameters)
}
//update the margin high light figure

function edithighlight(highlight) {
	var url="edit-highlight.asp";
	var updText=new ajaxRequest();
	var highlight = encodeURIComponent(highlight);
	var parameters="highlight="+highlight;
	updText.onreadystatechange=function(){
	 if (updText.readyState==4){
		if (updText.status==200 || window.location.href.indexOf("http")==-1){
			return
		}
		else{
		 alert("An error has occured trying to change the margin highlight figure")
		}
	 }
	}
	updText.open("POST", url, true)
	updText.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	updText.send(parameters)

}

//ajax request
function ajaxRequest(){
 var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"]
 if (window.ActiveXObject){ 
  for (var i=0; i<activexmodes.length; i++){
   try{
    return new ActiveXObject(activexmodes[i])
   }
   catch(e){
   }
  }
 }
 else if (window.XMLHttpRequest) 
  return new XMLHttpRequest()
 else
  return false
}

//Restrict to whole numbers on input	
function isWholeNumber(e){
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=8 && unicode!=45){ 
		if (unicode<48||unicode>57) 
		return false 
	}
}

//Restrict to decimal numbers on input	
function isDeclNumber(e){
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=8){ 
		if (unicode<46||unicode>57) 
		return false 
	}
}

//format to d decimal places
function toDecl(obj,a,d) {
		if (!isNaN(a)) {
		a = a / 1;
		a = a.toFixed(d); 
		document.getElementById(obj).value = a;
	}
}

function alltrim(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = / +/g;
   temp = temp.replace(obj, " ");
   if (temp == " ") { temp = ""; }
   return temp;
}


function checkemail(q) {
	if (isValidEmail(q)) {
		alert("OK");
	}
	else {
		alert("Email invalid");
	}
}

toCamelCase.exp = / ([a-z])/;
function toCamelCase(s) {
	s = ' '+s.toLowerCase();
	for(var exp = toCamelCase.exp; 
		exp.test(s); 
		s = s.replace(exp, ' '+RegExp.$1.toUpperCase()) );
	return alltrim(s);
}

function passwordTrim(value) {
	var obj=/\W/g;
		value = value.replace(obj, "");
		return value;
}


function isValidEmail(emailAddress) {
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(2([0-4]\d|5[0-5])|1?\d{1,2})(\.(2([0-4]\d|5[0-5])|1?\d{1,2})){3} \])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    return re.test(emailAddress);
}

//function noSpecials(value) {
//	var obj=/[&/=:#?*\\'\\"<>%$]/g;
//		value = value.replace(obj, " ");
//		return value;
//}
//

function noSpecials(value) {
	var obj=/[&/=:#?*\\'\\"<>%$]/g;
	var obj = /&nbsp;|\*picture\*|\f|\n|\r|\t|[&/=:#?*<>%$\\"\\'\.\,\)\(]/g;
		value = value.replace(obj, " ");
		return value;
}


