// common library for tech artisans development
// v1.0.3
// added option 'all', 'default' and 'none'
// v1.0.2
// made scrollbars show up by default
// v1.0.1
// bring window to front if it exists
// v1.0

function openWin(url, winName, pxwidth, pxheight, pxtop, pxleft, options)  
{
	var toolbar = "no";
	var location = "no";
	var directories = "no";
	var status = "no";
	var menubar = "no";
	var scrollbars = "yes";
	var resizable = "no";

	if (pxheight==null)	pxheight= 550;
	if (pxwidth==null)	pxwidth	= 790;
	
	if (pxleft==null)	pxleft	= Math.floor((screen.width - pxwidth) / 2);
	if (pxtop==null)	pxtop	= Math.floor((screen.height - pxheight) /2);

	if (screen.width==800) 
	{
		pxleft=0;
		pxtop=0;
	}

	if (options == 'all')
	{
		toolbar = 'yes';
		location = 'yes';
		directories = 'yes';
		status = 'yes';
		menubar = 'yes';
		scrollbars = 'yes';
		resizable = 'yes';
	}
	else if (options == 'none')
	{
		toolbar = 'no';
		location = 'no';
		directories = 'no';
		status = 'no';
		menubar = 'no';
		scrollbars = 'no';
		resizable = 'no';		
	}
	else if (options) 
	{
		if (options.indexOf('status')!=-1) 
		{
			status = "yes";
		}
		if (options.indexOf('menubar')!=-1) 
		{
			menubar = "yes";
		}
	}


	features = "top=" + pxtop + ",";
	features += "left=" + pxleft + ",";
	features += "width=" + pxwidth + ",";
	features += "height=" + pxheight;

	if (options != 'default')
	{
		features += "toolbar=" + toolbar + ",";
		features += "location=" + location + ",";
		features += "directories=" + directories + ",";
		features += "status=" + status + ","; 
		features += "menubar=" + menubar + ",";
		features += "scrollbars=" + scrollbars + ",";
		features += "resizable=" + resizable + ",";
	}
	
	theWin = window.open (url, winName, features)
	if (!theWin.opener) 
	{
		theWin.opener = self;
	}

	theWin.focus();

}

var cookies = document.cookie;

function readCookie(name) {

	var start = cookies.indexOf(name + "=");
	
	if (start == -1) {
		//alert('Cookie "' + name + '" not found.');
		return false;
	}

	start = cookies.indexOf("=", start) + 1;
	
	var end = cookies.indexOf(";", start);
	
	if (end == -1) {
		end = cookies.length;
	}
	
	var value = unescape(cookies.substring(start, end));
	
	if (value == null) {
		//alert('No cookie found');
		return false;
	} else {
		//alert('Cookie "' + name + '" = ' + value);
		return value;
	}

}

function writeCookie(name, value, years, path, domain) {

	var fulldate = new Date();
	var year = fulldate.getFullYear();
	var month = fulldate.getMonth();
	var date = fulldate.getDate();
	if (years) year = year + years; //cookie will last for 'years' years
	var expirydate = new Date(year,month,date);
		
	var thecookie;
	
	thecookie = name + "=" + value + ";";
	if (path) thecookie = thecookie + "path=" + path + ";";
	if (domain) thecookie = thecookie + "domain=" + domain + ";";
	thecookie = thecookie + "expires=" + expirydate.toString() + ";";
	
	//alert('thecookie = ' + thecookie);
	
	document.cookie = thecookie;

}

function isNumber(str)
{
	var r1 = new RegExp("[a-z]|[A-Z]");
	return (!r1.test(str));
}

function regExpSupported()
{
	if (window.RegExp) 
	{
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}

function isTelephone(str) 
{
	if (!regExpSupported())
		return (true);
	var r1 = new RegExp("[0-9]");
	return (r1.test(str));
}

function isEmail(str) 
{
	if (!regExpSupported()) 
	{
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	}

	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}