function breakout()
{ if (top.location != location) {top.location.href = document.location.href;}}

function popUp(page, name, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
var winprop  = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=yes';
win = window.open(page, name, winprop); win.focus();
return win;
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

function isEmpty(obj){
/*-----------------------------
Accepts 
	object 
	returns true or false   
-----------------------------*/
if(obj){if(0 == trim(obj.value).length)return true; else return false;}}

function isLength(len,obj)
{if(obj){if(obj.value.length <= len) return true; else return false;}}

function isNumeric(obj){
/*-----------------------------
Accepts 
	object 
	returns true or false   
------------------------------*/
	if(obj)
	{ var val = obj.value; var n = 0; 
		for(var i = 0; i < val.length; i++)
		{ if((val.charCodeAt(i)>=48)&&(val.charCodeAt(i)<=57)) {n++;}
		else { if(val.charCodeAt(i)==45)n++;}
		} if (n == val.length )return true; else return false;}
}
function isValidString(str){
/*----------------------------
Aaccepts 
	string 
	returns true or false
	!!!!temp. took out space!!!!
-----------------------------*/
	var InvalidChars="/\\|;:*?<>";
		for(i=0;i<str.length;i++)
		{
			for(j=0;j<InvalidChars.length;j++)
			{
				if(str.charAt(i)==InvalidChars.charAt(j))
				{
				return false;
				}
			}
		}
	return true;
}

function isValidEmail(str){
/*--------------------------------
Accepts 
	string 
	returns true or false
----------------------------------*/
	
	if ((isValidString(str))&&(-1==str.indexOf(" "))&&(-1==str.toLowerCase().indexOf("perfectmatch"))&&(-1==str.toLowerCase().indexOf("eharmony"))){
		
		if (str.length<6) return false;
		if (( -1 == str.indexOf("@"))||(-1 == str.indexOf(".")))
		{return false;}
		else
		{if ((0==str.indexOf("@"))||(str.indexOf("@")==str.length-1)) return false;
		if ((0==str.indexOf("."))||(str.indexOf(".")==str.length-1)) return false;
		}return true;
	}	
	else
	{
		return false;
	}	
}

/*--------------------------
SelectOption accepts object
and a string
-----------------------------*/
function SelectOption(SelectName, OptionValue)
{
	if (true == SelectName.multiple) var blnMltBox = true;
	var MultiValues = new Array;
	MultiValues = OptionValue.split(', ');
	for (var i=0; i < SelectName.options.length; i++)
	{
		for( var j=0; j < MultiValues.length; j++)
  		{
  			if(SelectName.options[i].value.toLowerCase() == MultiValues[j].toLowerCase()) // && !("0"==MultiValues[j]))
  			{SelectName.options[i].selected = true;}
		}
	}
}

function IsEmptyList(objListName){
	var listarray = new Array();
	listarray = objListName;
	n=0;
	for(var i=0;i<listarray.length;i++)
		{	
		  if(listarray[i].checked == true){n++;}
		}
	if(n == 0)
	{return true;}
	else
	{return false;}
}

function Spaces(str, fieldname){
var count = 0;
var	n = 0;
var	i = 0;
var	j = 0;
for (i=0; i < str.length; i++)
	{
		if((str.charAt(i)==" ") || (str.charAt(i)=="\n") || (str.charAt(i)=="\r"))
		{if(n > count)count = n;n=0;j++;}n++;}
		count = (n > count) ? n : count;
		if (count>=40) // ||(str.indexOf(" ") == -1 )
		{alert("For display purposes text must contain spaces between words.\n\r\Please edit text and try again.");
		return false;
	}
return true;
}

function TruLength(str){
	var len = 0;
	var cnt = 0;
	var res = 0;
	len = str.length;
	res =len; 
	for (i=0; i < len; i++){
		if((str.charAt(i)=="\n") || (str.charAt(i)=="\r")){ res--;}
	}
	return res;
}

function baseConverter (number,ob,nb){
	number = number.toString()
	number = number.toUpperCase();
	var list = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var dec = 0;
	for (var i = 0; i <=  number.length; i++) {
		dec += (list.indexOf(number.charAt(i))) * (Math.pow(ob , (number.length - i - 1)));
	}
	number = "";
	var magnitude = Math.floor((Math.log(dec))/(Math.log(nb)));
	for (var i = magnitude; i >= 0; i--) {
		var amount = Math.floor(dec/Math.pow(nb,i));
		number = number + list.charAt(amount); 
		dec -= amount*(Math.pow(nb,i));
	}
	return number;
}

function trim(strText){ 
    //Get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    //Get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);
   return strText;
} 

function formatZip(obj){
	var txt=trim(obj.value);
	var newTxt;
	txt=txt.replace(/ /g, '');
	
	if(isNaN(txt.substring(0,1)) && !isNaN(txt.substring(1,2)) && isNaN(txt.substring(2,3)))
		newTxt=txt.substring(0, 3) + ' ' + txt.substring(3, txt.length);
	else
		newTxt=txt
		
	obj.value=newTxt;

}

/*
	getCookieData
	cName=This is the cookie name.
		For sub cookie, separate the cookie name and the sub cookie name
		with a dot (cookieName.subCookieName).

*/
function getCookieData(cookieName){
	cookieName=cookieName.toLowerCase();
	var cookieLCase=document.cookie.toLowerCase();
	var returnData=document.cookie;
	var arrCookieName, cookieIndex, cookieEnd, isMultiLevel=false;
	var cookieDelimiter=';';
	var prevChar;
	
	if(cookieName.indexOf('.')>0){
		arrCookieName=cookieName.split('.');
		cookieName=arrCookieName[0];
		isMultiLevel=true;
	}
	
	cookieIndex=cookieLCase.indexOf(cookieName+'=');
	if (cookieIndex!=-1){
		prevChar='';
		if(cookieIndex>0)
			prevChar=cookieLCase.substring(cookieIndex-1, cookieIndex)
		
		cookieIndex=cookieIndex+cookieName.length+1;
		cookieEnd=cookieLCase.indexOf(cookieDelimiter, cookieIndex);
		
		if (cookieEnd==-1)
			cookieEnd=cookieLCase.length;
		
		if(prevChar=='' || prevChar==' ' || prevChar==';')
			returnData=returnData.substring(cookieIndex, cookieEnd);
		else{
			returnData='';
		}
	}
	else{
		returnData='';
	}
		
	
	if(isMultiLevel && cookieLCase!=''){
		cookieName=arrCookieName[1];
		cookieDelimiter="&";
		cookieLCase=returnData.toLowerCase();
		cookieIndex=cookieLCase.indexOf(cookieName+'=');
		cookieEnd=0;
	
		if (cookieIndex!=-1){
			prevChar='';
			if(cookieIndex>0)
				prevChar=cookieLCase.substring(cookieIndex-1, cookieIndex)
			cookieIndex=cookieIndex+cookieName.length+1;
			cookieEnd=cookieLCase.indexOf(cookieDelimiter, cookieIndex);
			
			if (cookieEnd==-1)
				cookieEnd=cookieLCase.length;
			
			if(prevChar=='' || prevChar=='&')
				returnData=returnData.substring(cookieIndex, cookieEnd);
			else{
				returnData='';
			}
		}
		else
			returnData='';
	}

	return unescape(returnData);
}

/*
	setCookieData
	cName=This is the cookie name.
		For sub cookie, separate the cookie name and the sub cookie name
		with a dot (cookieName.subCookieName).

*/
function setCookieData(cName, Props){
	var arrCName;
	var cData, cLCase, prevChar;
	if (cName.indexOf('.')>=0){
		arrCName=cName.split('.');
		cName=arrCName[0];
		cData=getCookieData(arrCName[0]);
		if (cData!=''){
			cLCase=cData.toLowerCase();
			var cIndex=cLCase.indexOf(arrCName[1].toString().toLowerCase()+'=');
			if(cIndex!=-1){
				prevChar='';
				if(cIndex>0)
					prevChar=cLCase.substring(cIndex-1, cIndex)
				
				cEnd=cLCase.indexOf('&', cIndex);
				
				if(cEnd==-1)
					cEnd=cLCase.length;
				
				if (prevChar=='' || prevChar=='&')
					cData = cData.substring(0, cIndex) + arrCName[1] + '=' + escape(Props) + cData.substring(cEnd, cData.length);
			}
			else{
				cData += '&' + arrCName[1] + '=' + escape(Props);
			}
		}
		else
			cData = arrCName[1] + '=' + escape(Props);
	}
	else{
		cData=escape(Props);
	}
	document.cookie = cName + '=' + cData + '; path=/;';
}