function silentErrorHandler() {
	return true;
}
window.onerror=silentErrorHandler;

var currentFontSize = 4;

	var prot = top.location.protocol+"//";
	var loctocheck = top.location.host;
	var loc = "";
	if(loctocheck == "10.0.0.3" || loctocheck == "119.161.33.8")
	{
		loc = prot+loctocheck+"/EventConnect/";
	}
	else
	{
		loc = prot+loctocheck+"/";
	}


function revertStyles(fontsize){
	currentFontSize = fontsize;
	changeFontSize(0);
}

function changeFontSize(sizeDifference){
	//get css font size
	var rule = getRuleByName("body.fs" + (currentFontSize + sizeDifference));
	if (rule){
		document.body.style.fontSize = rule.style.fontSize;
		currentFontSize = currentFontSize + sizeDifference;
		createCookie("FontSize", currentFontSize, 365);
		equalHeight();
	}
	return;
	
};

function getRuleByName(ruleName){
	for (i=0; i<document.styleSheets.length; i++){
		var style = document.styleSheets[i];
		var rules = style.cssRules?style.cssRules:style.rules;
		if (rules){
			for (j = 0; j<rules.length; j++){
				if (rules[j].selectorText.trim().toUpperCase() == ruleName.trim().toUpperCase()){
					return rules[j];
				}
			}
		}
	}
	return null;
}

function setActiveStyleSheet(title) {

	createCookie("ColorCSS", title, 365);
	window.location.reload();
	return;

  var i, a, main, arr;
  arr = document.getElementsByTagName("link");
  for(i=0; (a = arr[i]); i++) {
  	var ltitle = a.getAttribute("title");
    if(a.getAttribute("rel").indexOf("style") != -1 && ltitle) {
      a.disabled = true;
      if(ltitle == title) a.disabled = false;
    }
  }
  createCookie("ColorCSS", title, 365);
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function setScreenType(screentype){
	bclass = document.body.className.trim();
	if (bclass.indexOf(' ') > 0){
		bclass = bclass.replace(/^\w+/,screentype);
	}else{
		bclass = screentype + ' ' + bclass;
	}

	document.body.className = bclass;
	equalHeight();
	createCookie("ScreenType", screentype, 365);
}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };

function changeToolHilite(oldtool, newtool) {
	if (oldtool != newtool) {
		if (oldtool) {
			oldtool.src = oldtool.src.replace(/-hilite/,'');
		}
		newtool.src = newtool.src.replace(/.gif$/,'-hilite.gif');
	}
}

//addEvent - attach a function to an event
function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}

function equalHeight (){
	var obj1 = getElem ('ja-box1');
	var obj2 = getElem ('ja-box2');
	var obj3 = getElem ('ja-box3');
	var maxh = 0;
	if (obj1) maxh = obj1.offsetHeight;
	if (obj2 && obj2.offsetHeight > maxh) maxh = obj2.offsetHeight;
	if (obj3 && obj3.offsetHeight > maxh) maxh = obj3.offsetHeight;
	if (obj1) obj1.parentNode.style.height = maxh + "px";
	if (obj2) obj2.parentNode.style.height = maxh + "px";
	if (obj3) obj3.parentNode.style.height = maxh + "px";
}

function getElem (id) {
	var obj = document.getElementById (id);
	if (!obj) return null;
	divs = obj.getElementsByTagName ('div');
	if (divs && divs.length > 1) return divs[divs.length - 1];
	return null;
}
addEvent (window, 'load', equalHeight);

function addToFavorites(url, title)
{
    if(window.external)
    {
        window.external.AddFavorite(url,title);
    }
    else
    {
        alert("Sorry! Your browser doesn't support this function."); 
    } 

    return false;
}

function modalWin(query) 
{
	//if (window.showModalDialog) 
	//{
	//	window.showModalDialog("upload.aspx","name","dialogWidth:600px;dialogHeight:400px");
	//} 
	//else 
	//{
	//	window.open('upload.aspx','name','height=400,width=600,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes');
	//}
	//window.location.reload();
	var myhost = top.location.host;
	var myloc = "http://"+myhost;
	if(myhost == '10.0.0.3' || myhost == '119.161.33.8')
	{
		myloc = "http://"+myhost+"/eventconnect";
	}
	query = query.replace(/&amp;/g,'&');
	
	var mywin = window.open(myloc+'/upload.aspx?'+query,'name','height=400,width=600,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,address=no');
} 

function taLimit() {
	if (window.event) var e = window.event; 
	var taObj=e.srcElement? e.srcElement : e.target;//event.srcElement;
	var maxLength = taObj.getAttribute("maxlength");
	if (taObj.value.length==maxLength*1) return false;
}

function taCount(visCnt) { 
	var e = window.event; 

	var taObj=e.srcElement? e.srcElement : e.target;//event.srcElement;
	var maxLength = taObj.getAttribute("maxlength");
	if (taObj.value.length>maxLength*1)
	{ 
		var over = (taObj.value.length)-(maxLength*1);
		taObj.value=taObj.value.substring(0,maxLength*1);
		alert("The text in this textbox has been truncated as you have exceeded the character limit by "+over+" characters.\n\nPlease check before continuing.");
	}
	//var countObj = document.getElementById(visCnt);
	//alert(maxLength);
	if (visCnt) 
	{
		if(visCnt.innerText)
		{
			visCnt.innerText=maxLength-taObj.value.length;
		}
		else
		{
			visCnt.textContent=maxLength-taObj.value.length;
		}
	}
}

function fixForWord(txtName)
{
	var myObj = returnObjById(txtName);
	var strToCheck = escape(myObj.value);
	//alert(strToCheck);
	strToCheck = strToCheck.replace(/%u201C/g, "\"");
	strToCheck = strToCheck.replace(/%u201D/g, "\"");
	strToCheck = strToCheck.replace(/%u2019/g, "%27");
	strToCheck = strToCheck.replace(/%u2018/g, "%27");
	myObj.value = unescape(strToCheck);
}

function setFocus(control)
{
	if(document.getElementById(control))
	{
		document.getElementById(control).focus();
	}
	else
	{
		alert('no object');
	}
}

function ConfirmDelete(msg)
{
	var answer = confirm(msg);
	
	if(answer)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function returnObjById( id ) 
{ 
   if (document.getElementById) 
      var returnVar = document.getElementById(id); 
   else if (document.all) 
     var returnVar = document.all[id]; 
   else if (document.layers) 
      var returnVar = document.layers[id]; 
   return returnVar; 
}

function waitPreloadPage() 
	{ //DOM
		window.scrollBy(0,-15000);
		if (document.getElementById)
			{
				document.getElementById('prepage').style.visibility='visible';
				document.getElementById('ani').style.visibility='visible';
				
			}
			else
			{
				if (document.layers)
				{ //NS4
					document.prepage.visibility = 'visible';
					document.ani.visibility = 'visible';
				}
				else 
				{ //IE4
					document.all.prepage.style.visibility = 'visible';
					document.all.ani.style.visibility = 'visible';
				}
			}
	}



