﻿/* FUNCTIONS */
function printMe() {
	var link = document.location.href;
	var re = /\?/i;
	var separator = re.test(link) ? "&" : "?";
	re = /print=true/i;
	if(!re.test(link)) {
		document.location.href = link + separator + "print=true";
	}
}

function mainwin(id) {
	window.open('main_win.aspx?id='+id, '_blank', 'top=10,left=10,width=600,height=720,toolbar=no,location=no,directories=no,resizable=1,status=no,menubar=no,scrollbars=1');
}

function launchDesc(fId) {window.open('publShow.aspx?id='+ fId, '_news','top=10,left=10,width=500,height=660,toolbar=no,location=no,directories=no,resizable=1,status=no,menubar=no,scrollbars=1');}
function readTerms(fName) {window.open('readTerms.asp?file='+ fName, '_terms', 'top=10,left=10,width=600,height=450,toolbar=no,location=no,directories=no,resizable=1,status=no,menubar=no,scrollbars=1');}
function readTerms2(fName) {window.open('readTerms2.asp?file='+ fName, '_terms', 'top=10,left=10,width=700,height=600,toolbar=no,location=no,directories=no,resizable=1,status=no,menubar=no,scrollbars=1');}

/* HELP FUNCTIONS */
function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + '=' + escape(value) + ((expires) ? '; expires=' + expires.toGMTString() : '') + ((path) ? '; path=' + path : '') + ((domain) ? '; domain=' + domain : '') + ((secure) ? '; secure' : '');
	document.cookie = curCookie;
}

function getCookie(name, d) {
	if (!d) var d = null;
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) {
			var endstr = document.cookie.indexOf (";", j);
			if (endstr == -1) endstr = document.cookie.length;
			return unescape(document.cookie.substring(j, endstr));
 		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return d;
}

function deleteCookie(CookieName,path,domain) {
	if (getCookie(CookieName))
		document.cookie = CookieName + '=' + ((path) ? ';path='+path : '') + ((domain) ? ';domain='+domain : '') + ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

function RegularExpressionValidator(controlId, regExp, errMessage) {
		var value = ValidatorGetValue(controlId);
		var rx = new RegExp(regExp);
		var matches = rx.exec(value);
		res = (matches != null && value == matches[0]);
		if(!res)
			alert(errMessage);
		return res;
}
function RequiredFieldValidator(controlId, initialValue, errMessage) {
	res = ValidatorGetValue(controlId) != ValidatorTrim(initialValue);
	if(!res)
		alert(errMessage);
	return res;
}
function ValidatorGetValue(controlId) {
		var control = document.getElementById(controlId);
		return ValidatorTrim(control.value);
}
function ValidatorTrim(s) {
		var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
		return (m == null) ? "" : m[1];
}

function $() {
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = window.document.getElementById(element);
  		return element;
	}
}