﻿function TrimString(str) {
	str = str.replace(/^\s+/g, ""); // strip leading
	return str.replace(/\s+$/g, ""); // strip trailing
}

function ShowShow(ele, cur) {
	var e = document.getElementById(ele);
	e.style.visibility = (e.style.visibility == "visible") ? "hidden" : "visible";
	e.style.cursor = ( cur && e.style.visibility == "visible") ? "pointer" : "default";
}

function LayerOn(ele, cur) {
	var e = document.getElementById(ele);
	e.src = e.src.replace("Off", "On");
	if (cur) e.style.cursor = "pointer";
	if (ele.indexOf("SJ") > -1) {
		e = document.getElementById("SJ_1");
	} else {
		e = document.getElementById("CS_1");		
	}
	e.style.left = (Number(e.style.left.split('p')[0]) - 1) + "px";
	e.style.top = (Number(e.style.top.split('p')[0]) - 1) + "px";
}

function LayerOff(ele) {
	var e = document.getElementById(ele);
	e.src = e.src.replace("On", "Off");
	e.style.cursor = "default";
	if (ele.indexOf("SJ") > -1) {
		e = document.getElementById("SJ_1");
	} else {
		e = document.getElementById("CS_1");
	}
	e.style.left = (Number(e.style.left.split('p')[0]) + 1) + "px";
	e.style.top = (Number(e.style.top.split('p')[0]) + 1) + "px";
}
function ImageHandler(imgName) {
	var img = document.getElementById(imgName);
	if (img != null) {
		img.src = (img.src.indexOf("Off") > -1) ? img.src.replace("Off", "On") : img.src.replace("On", "Off");
	}
}
function isAlpha(val) {
	var Alpha = /^[a-zA-Z\s.]+$/;
	return (Alpha.test(val));
}

function isAlphaNumeric(val) {
	var Alpha = /^[\W\s.]+$/;
	return (Alpha.test(val));
}

function isLegalText(val) {
	var txt = /^[a-zA-Z0-9\.\&\-\s.]+$/;
	return (txt.test(val));
}

function isFloatNum(val) {
	var FloatNum = /^[-+]?\d*\.?\d*$/;
	return FloatNum.test(val)
}

function isGuid(val) {
	var Guid = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
	return Guid.test(val)
}

function isFileName(val) {
	 var pat = /^[a-zA-Z0-9\.\_\-\ ]+$/;
	 return pat.test(val);
}

function isNumeric(val) {
	var Numbers = /^-{0,1}\d*\.{0,1}\d+$/;
	return (Numbers.test(val));
}

function isPhone(val) {
	var Phone = /^(\(?\d\d\d\)?)?( |-|\.)?\d\d\d( |-|\.)?\d{4,4}(( |-|\.)?[ext\.]+ ?\d+)?$/;
	return Phone.test(val);
}

function isZipCode(val) {
 // USA only
	var ZipCode = /^\d{5}-\d{4}|\d{5}$/;
	return ZipCode.test(val);
}

function isPostalCode(val) {
	// Canadian only
	var PostalCode = /^[A-Z]\d[A-Z]\s{0,1}\d[A-Z]\d$/;
	return PostalCode.test(val);
}

function Sleeper(naptime) {
	naptime = naptime * 1000;
	var sleeping = true;
	var now = new Date();
	var alarm;
	var startingMSeconds = now.getTime();
	while (sleeping) {
		alarm = new Date();
		alarmMSeconds = alarm.getTime();
		if (alarmMSeconds - startingMSeconds > naptime) { sleeping = false; }
	}
}

function SubmitDoc(qry) {
	document.forms[0].action = qry;
	document.forms[0].submit();
	return true;
}

function cutHex(h) { return (h.charAt(0) == "#") ? h.substring(1, 7) : h }
function HexToR(h) { return parseInt((cutHex(h)).substring(0,2),16) }
function HexToG(h) { return parseInt((cutHex(h)).substring(2,4),16) }
function HexToB(h) { return parseInt((cutHex(h)).substring(4,6),16) }



