

function obj(id){
	return document.getElementById(id);
}


function popupwindow(url,name,width,height){
	return window.open(url,name,"left=100,top=100,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width="+width+",height="+height);
}


function confirmSubmit(text){
	var agree=confirm(text);
	if(agree){
		return true;
	}else{
		return false;
	}	
}







function setValue(ID,newValue){
	// does not work well on FORM objects..
	document.getElementById(ID).value = newValue;
}



function scrolltotop(){
	window.scroll(0,0);
	document.scroll(0,0);
}



function cursor(newstyle){
	this.style.cursor = newstyle;
}




function format_money(num){
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + '.' + cents);
}




function display_money(num){
	var num = format_money(num);
	if(num<0){
		return "- $"+num;
	}else{
		return "$"+num;
	}
}










function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}




function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}





function isNumberKey(evt){
	var charCode = (evt.which) ? evt.which : event.keyCode
	if(charCode > 31 && (charCode < 48 || charCode > 57)){
		return false;
	}
	return true;
}







function show(id){
	try{
		document.getElementById(id).style.opacity = 100;
		document.getElementById(id).style.MozOpacity = 100;
		document.getElementById(id).style.KhtmlOpacity = 100;
	}
	catch(e){};
	try{
		document.getElementById(id).style.display='';
	}
	catch(e){};
}



function hide(id){
	try{
		document.getElementById(id).style.display='none';
	}
	catch(e){};
}




	
function toggleDisplay(id){
	if(document.getElementById(id).style.display=='none'){
		opacity(id,0,100,1000);
	}else{
		opacity(id,100,0,300);
	}
}



function swapDisplay(idShow,idHide,speed){
	var speed = Number(speed);
	opacity(idHide,100,0,50);
	setTimeout("opacity('"+idShow+"',0,100,"+speed+")",20);
}











function fadeIn(id,speed){
	var speed = Number(speed);
	opacity(id,0,100,speed);
}

function fadeOut(id,speed){
	var speed = Number(speed);
	opacity(id,100,0,speed);
}


function toggleFade(id){
	if(document.getElementById(id).style.display=='none'){
		fadeIn(id,500);
	}else{
		fadeOut(id,500);
	}
}








function opacity(id,opacStart,opacEnd,millisec){
	var speed = Math.round(millisec/100);
	var browser=navigator.appName;
	if(browser.match("Mozilla")||browser.match("Netscape")){
		if(opacStart>opacEnd){
			var i=0;
			while((opacStart-i+1)>opacEnd){
				setTimeout("changeOpac('"+(opacStart-i)+"','"+id+"');",(i*speed));
				i++;
			}
		}
		if(opacStart<opacEnd){
			var i=0;
			while((opacStart+i-1)<opacEnd){
				setTimeout("changeOpac('"+(opacStart+i)+"','"+id+"');",(i*speed));
				i++;
			}
		}
		if(opacEnd>0){
			if(document.getElementById(id).style.display=='none'){
				setTimeout("document.getElementById('"+id+"').style.display='';",10);
			}
		}else{
			setTimeout("document.getElementById('"+id+"').style.display='none';",millisec);
		}
	}else{
		if(opacEnd>0){
			show(id);
		}else{
			hide(id);
		}
	}
}





function changeOpac(opacity,id){
	var browser=navigator.appName;
	if(browser.match("Mozilla")||browser.match("Netscape")){
		document.getElementById(id).style.opacity = (opacity/100);
		document.getElementById(id).style.MozOpacity = (opacity/100);
		document.getElementById(id).style.KhtmlOpacity = (opacity/100);
	}
}








function is_numeric(sText){
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
	for(i=0; i<sText.length && IsNumber==true; i++){ 
		Char = sText.charAt(i); 
		if(ValidChars.indexOf(Char)==-1){
			return false;
		}
	}
	return true;
}



function loadurl(url,callback){
	var response;
	var req = false;
	if(window.XMLHttpRequest && !(window.ActiveXObject)) {
		try{
			req = new XMLHttpRequest();
		}catch(e){
			req = false;
		}
	}else if(window.ActiveXObject){
		try{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				req = false;
			}
		}
	}
	if(req){
		req.onreadystatechange = function(){
			if(req.readyState==4){
				var response = req.responseText;
				eval(""+callback+"");
			}
		}
		req.open('GET',url,true);
		req.send(null);
	}
}



function goto(URL){
	location.href = URL;
	return true;
}











function POST(target,vars,callback){
	var response;
	var req = false;
	
	if(window.XMLHttpRequest && !(window.ActiveXObject)) {
		try{
			req = new XMLHttpRequest();
		}catch(e){
			req = false;
		}
	}else if(window.ActiveXObject){
		try{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				req = false;
			}
		}
	}
	
	if(req){
		req.onreadystatechange = function(){
			if(req.readyState==4){
				var response = req.responseText;
				eval(""+callback+"");
			}
		}
		req.open('POST',target,true);
		req.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		req.setRequestHeader("Content-length",vars.length);
		req.setRequestHeader("Connection","close");
		req.send(vars);
	}
}













function showAddNote(TARGET,TITLE){
	if(!TITLE){
		TITLE = "Add a Note";
	}
	var HTML = '<div style="padding:10px;">';
	HTML += '<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0">';
	HTML += '<tr id="JS_ADDNOTE_ERROR" style="display:none;"><td style="background-color:#FAE7E7;color:#990000;padding-bottom:5px;text-align:center;"><span id="JS_ADDNOTE_ERROR_TEXT"></span></td></tr>';
	HTML += '<tr>';
	HTML += '<td align="left" valign="middle" style="padding-top:10px;padding-bottom:5px;">';
	HTML += '<textarea name="textarea" id="JS_ADDNOTE_CONTENT" style="width:400px; height:100px; color:#666666; border:1px #CCCCCC solid; padding:7px;" onclick="this.value=\'\'; this.onclick=\'\'; this.style.color=\'#232323\';">Enter your note here..</textarea>';
	HTML += '</td>';
	HTML += '</tr>';
	HTML += '<tr>';
	HTML += '<td style="padding-top:10px;padding-bottom:5px;" align="center" valign="middle"><input type="button" class="button" value="Submit" tabindex="2" onClick="addNote(\''+TARGET+'\');" /></td>';
	HTML += '</tr>';
	HTML += '</table>';
	HTML += '</div>';
	showModal(HTML,TITLE);
}

function addNote(TARGET){
	var CONTENT = obj('JS_ADDNOTE_CONTENT').value;
	if(!CONTENT|CONTENT=="Enter your note here.."){
		obj('JS_ADDNOTE_CONTENT').value = '';
		obj('JS_ADDNOTE_ERROR_TEXT').innerHTML='Error: Your note must contain some content!';
		fadeIn('JS_ADDNOTE_ERROR',500);
		setTimeout('fadeOut(\'JS_ADDNOTE_ERROR\',500);',3500);
	}else{
		var POST_VARS = 'CONTENT='+escape(CONTENT);
		POST(TARGET,POST_VARS,"goto('"+TARGET+"');");
	}
}













function prettySEO(){
	var tags = Array("h1","h2","h3");
	for(a in tags){
		var b = tags[a];
		var c = document.body.getElementsByTagName(b);
		for(d in c){
			var e = c[d];
			if(e.title){
				try{
					if(e.firstChild.tagName=="A"){
						e.firstChild.innerHTML = "<img src=\""+e.title+"\" alt=\""+e.firstChild.innerHTML+"\" title=\""+e.firstChild.innerHTML+"\" border=\"0\">";
					}else{
						e.innerHTML = "<img src=\""+e.title+"\" alt=\""+e.innerHTML+"\" title=\""+e.innerHTML+"\" border=\"0\">";
					}
					e.style.padding="0px";
					e.title="";
				}catch(e){}
			}
		}
	}
}
















function center(id){
	try{
		var parent = obj(id).parentNode;
		var s1 = Number(obj(id).clientWidth);
		var s2 = Number(obj(id).clientHeight);
		if(parent.tagName=="BODY"){
			if(window.innerHeight){
				s3 = window.innerWidth;
				s4 = window.innerHeight;
			}else{
				var s3 = document.documentElement.clientWidth;
				var s4 = document.documentElement.clientHeight;
			}
		}else{
			var s3 = parent.clientWidth;
			var s4 = parent.clientHeight;
		}
		parent.style.paddingLeft = ((s3-s1)/2)+'px';
		parent.style.paddingTop = ((s4-s2)/2)+'px';
	}catch(e){}
	return true;
}





function trackFocus(id){
	window.xFocus=id;
}
function getFocus(id){
	return window.xFocus;
}




function stopBubbling(e) {
	try{ window.event.cancelBubble = true; }catch(e){}
	try{ e.stopPropagation(); }catch(e){}
}


