String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
function isNumeric(val){return(parseFloat(val,10)==(val*1));}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function toggleDisplay(id) {
	if (document.getElementById(id).style.display == '') {
		document.getElementById(id).style.display = 'none';
	} else {
		document.getElementById(id).style.display = '';
	}
}

function replaceHtml(el, html) {
	var oldEl = typeof el === "string" ? document.getElementById(el) : el;
	/*@cc_on // Pure innerHTML is slightly faster in IE
		oldEl.innerHTML = html;
		return oldEl;
	@*/
	var newEl = oldEl.cloneNode(false);
	newEl.innerHTML = html;
	oldEl.parentNode.replaceChild(newEl, oldEl);
	/* Since we just removed the old element from the DOM, return a reference
	to the new element, which can be used to restore variable references. */
	return newEl;
};


function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = '';
}

function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) thisfield.value = "";
}

function clickrecall(thisfield, defaulttext) {
	if (thisfield.value.length == 0) thisfield.value = defaulttext;
}

function gotosite(site) {
	if (site !== '') {self.location.href=site;}
}


function DisplayMail(Server, Login, Display){
	if ((Display.length == 0) || (Display.indexOf('@')+1)) {
	document.write('<a href=' + '"mai' + 'lto:' + Login + '@' + Server + '">' + Login + '@' + Server + '<\/a>'); }
	else  {
	document.write('<a href=' + '"mai' + 'lto:' + Login + '@' + Server + '">' + Display + '<\/a>'); }
}

function DisplayMail2(Server, Login, Display, Style){
	document.write('<a href=' + '"mai' + 'lto:' + Login + '@' + Server + '"');
	if (Style.length != 0) { document.write(' class="' + Style + '"'); }
	document.write('>');
	if ((Display.length == 0) || (Display.indexOf('@')+1)) {
		document.write(Login + '@' + Server); }
	else  { document.write(Display); }
	document.write('<\/a>');
}

function won(text) {window.status=text;}
function woff() {window.status='';}

function checkML() {
		f = document.MLForm;				// the form
		e = document.MLForm.elements;		// elements of the form
		l = document.MLForm.length;		// number of form elements

		if (f.Subscriber.value.length==0)  { alert("Please enter your NAME."); 			f.Subscriber.focus(); return false; }
		if (f.Email.value.length==0)  { alert("Please enter your EMAIL ADDRESS."); f.Email.focus(); return false; }
		var re = new RegExp("^[0-9A-Z]+([-_.0-9A-Z])*@[0-9A-Z]+([-.][0-9A-Z]+)*[.][A-Z]{2,4}$","i");
		if(!re.test(f.Email.value))
		{	alert("Please enter a valid EMAIL ADDRESS.");
			f.Email.focus();
			return false;
		}
	return true;
}

function showDiv(divList){
	var i = divList.split(",");
	for (a=0;a<i.length;a++) {
		if(document.getElementById(i[a]) != null){
			if (document.getElementById(i[a]).style.display == 'none'){
				document.getElementById(i[a]).style.display = '';
			} 
		}
	}
}

function hideDiv(divList){
	var i = divList.split(",");
	for (a=0;a<i.length;a++) {
		if(document.getElementById(i[a]) != null){
			if (document.getElementById(i[a]).style.display != 'none'){
				document.getElementById(i[a]).style.display = 'none';
			}	
		}
	}
}

/* Submit Once form validation - Dynamic Drive (www.dynamicdrive.com)
http://www.dynamicdrive.com/dynamicindex11/submitonce.htm
Modified by SunStar Media (www.ssmedia.com)
<form method="POST" onsubmit="submitonce(this)">  */
function submitonce(theform){
	if (document.getElementById){
		for (i=0;i<theform.length;i++){
			var tempobj=theform.elements[i];
			if (tempobj.type) {
				if(tempobj.type.toLowerCase()=="submit" || tempobj.type.toLowerCase()=="reset" || tempobj.type.toLowerCase()=="button") {tempobj.disabled=true;}
			}
		}
	}
}

/* "Accept terms" form submission - Dynamic Drive (www.dynamicdrive.com)
http://www.dynamicdrive.com/dynamicindex16/acceptterm.htm
Modified by SunStar Media (www.ssmedia.com)
<form name="agreeform" onsubmit="return defaultagree(this)">
<input name="IAgree" type="checkbox" onclick="agreesubmit(this)">I agree
<input type="submit" value="Submit!" disabled>  */
var checkobj
function agreesubmit(el){
	checkobj=el;
	if (document.all||document.getElementById){
		for (i=0;i<checkobj.form.length;i++){
			var tempobj=checkobj.form.elements[i];
			if (tempobj.type) {
				if(tempobj.getAttribute('name')&&tempobj.type.toLowerCase()=="submit"){
					tempobj.disabled=!checkobj.checked;
				}
			}	
		}
	}
}

function defaultagree(el){
	if (!document.all&&!document.getElementById){
		if (window.checkobj&&checkobj.checked) {return true;}
		else{
			alert("Please read/accept terms to submit form.");
			return false;
		}
	}
}



/***********************************************
* Form Field Progress Bar- By Ron Jonk- http://www.euronet.nl/~jonkr/
* Modified by Dynamic Drive for minor changes
* Script featured/ available at Dynamic Drive- http://www.dynamicdrive.com
* Please keep this notice intact
* http://www.dynamicdrive.com/dynamicindex16/limitinput2.htm
***********************************************/
function textCounter(field,counter,maxlimit,linecounter) {
	/* text width */
	var fieldWidth =  parseInt(field.offsetWidth);
	var charcnt = field.value.length;        
	/* trim the extra text */
	if (charcnt > maxlimit) { field.value = field.value.substring(0, maxlimit); }
	else { 
	/* progress bar percentage */
	var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
	document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
	document.getElementById(counter).innerHTML="&nbsp;Limit: "+percentage+"%"
	/* color correction on style from CCFFF -> CC0000 */
	setcolor(document.getElementById(counter),percentage,"background-color");
	}
}
function setcolor(obj,percentage,prop){
	obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}

/* <input onkeypress="return numbersonly(this, event);">
(optional) dec = field name to jump to when the . key is pressed
 */
function numbersonly(myfield, e, dec) {
	var key;
	var keychar;
	if (window.event) key = window.event.keyCode;
	else if (e) key = e.which;
	else return true;
	keychar = String.fromCharCode(key);
	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )  return true;
	// numbers
	else if ((("0123456789").indexOf(keychar) > -1)) return true;
	// decimal point jump
	else if (dec && (keychar == ".")) {
	   myfield.form.elements[dec].focus();
	   return false;
	   }
	else return false;
}


function changeclass(idref, classname) {   
	var el = document.getElementById(idref); 
	var attributeNode = el.getAttributeNode("class"); 
	if( attributeNode ) { attributeNode.value = classname; } 
	else { el.setAttribute("class", classname); } 
}

/*  http://www.onlinetools.org/articles/unobtrusivejavascript/cssjsseparation.html */
function jscss(a,o,c1,c2){
  switch (a){
    case 'swap':
      o.className=!jscss('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
    break;
    case 'add':
      if(!jscss('check',o,c1)){o.className+=o.className?' '+c1:c1;}
    break;
    case 'remove':
      var rep=o.className.match(' '+c1)?' '+c1:c1;
      o.className=o.className.replace(rep,'');
    break;
    case 'check':
      return new RegExp('\\b'+c1+'\\b').test(o.className);
    break;
  }
}


/* http://www.hunlock.com/blogs/Snippets:_Howto_Grey-Out_The_Screen */
function grayOut(vis, options) {
  /* Pass true to gray out screen, false to ungray
  options are optional.  This is a JSON object with the following (optional) properties
  opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  in any order.  Pass only the properties you need to set. */
  var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 70;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    /* The dark layer doesn't exist, it's never been created.  So we'll
     create it here and apply some basic styles.
     If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917 */
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');
        tnode.style.position='absolute';
        tnode.style.top='0px';
        tnode.style.left='0px';
        tnode.style.overflow='hidden';
        tnode.style.display='none';
        tnode.id='darkenScreenObject';
    tbody.appendChild(tnode);
    dark=document.getElementById('darkenScreenObject');
  }
  if (vis) {
    /* Calculate the page width and height */
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }   
    /* set the shader to cover the entire page and make it visible. */
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';                          
  } else {
     dark.style.display='none';
  }
}



function findPosX(Elem) {
	var obj = document.getElementById(Elem);
	var curleft = 0;
	if(obj.offsetParent)
		while(1) {
			curleft += obj.offsetLeft;
			if(!obj.offsetParent) break;
			obj = obj.offsetParent;
		}
	else if(obj.x) curleft += obj.x;
	return curleft;
}

function findPosY(Elem){
	var obj = document.getElementById(Elem);
	var curtop = 0;
	if(obj.offsetParent)
		while(1){
			curtop += obj.offsetTop;
			if(!obj.offsetParent) break;
			obj = obj.offsetParent;
		}
	else if(obj.y) curtop += obj.y;
	return curtop;
}



/* http://www.quirksmode.org/js/cookies.html */
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
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 var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}



function PopUpWindow(url, hWind, nWidth, nHeight, nScroll) {
	var cToolBar = 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=' + nScroll + ',resizable=0,width=" + nWidth + ",height=' + nHeight;
	var popupwin = window.open(url, hWind, cToolBar);
}

/* http://www.white-hat-web-design.co.uk/articles/js-fontsize.php
<a href="javascript:decreaseFontSize();">-</a> 
<a href="javascript:increaseFontSize();">+</a> */
var iMin=8;
var iMax=18;
function increaseFontSize() {
	var p = document.getElementsByTagName('p');
	for(i=0;i<p.length;i++) {
		if(p[i].style.fontSize) {
			var s = parseInt(p[i].style.fontSize.replace('px',''));
		} else {
			var s = 12;
		}
		if(s!=iMax) {
			s += 1;
		}
		p[i].style.fontSize = s+'px';
	}
}
function decreaseFontSize() {
	var p = document.getElementsByTagName('p');
	for(i=0;i<p.length;i++) {
		if(p[i].style.fontSize) {
			var s = parseInt(p[i].style.fontSize.replace('px',''));
		} else {
			var s = 12;
		}
		if(s!=iMin) {
			s -= 1;
		}
		p[i].style.fontSize = s+'px';
	}   
}