

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 obj(id){
	return document.getElementById(id);
}





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 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{
		obj(id).style.display='';
	}
	catch(e){};
}



function hide(id){
	try{
		obj(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){
	opacity(idHide,100,0,50);
	setTimeout("opacity('"+idShow+"',0,100,'"+speed+"')",50);
}











function fadeIn(id,speed){
	opacity(id,0,100,speed);
}



function fadeOut(id,speed){
	opacity(id,100,0,speed);
}











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 loadLink(URL){
	/* Displays a 'Please Wait' while the URL loads.. */
	var DIV = document.createElement("div");
	DIV.innerHTML = "<div style=\"position:fixed; left:0px; top:0px; width:100%; height:100%; background-image:url('https://www.satworx.com/images/modal/fade_85.png');\"><table align=\"center\" cellspacing=\"0\" cellpadding=\"0\" style=\"margin-top:350px;\"><tr><td style=\"font-size:21px; font-weight:bold; color:#FFFFFF;\">Please Wait..</td></tr></table></div>";
	DIV.setAttribute('id','loadLink');
	document.body.appendChild(DIV);
	if(URL){
		setTimeout("window.location.href='"+URL+"'",250);
	}
}











function showModalFrame(URL,WIDTH,HEIGHT,TITLE){
	showModal('<span><iframe src="'+URL+'" width="'+WIDTH+'" height="'+HEIGHT+'" frameborder="0"></iframe></span>',TITLE);
}

function showModal(INNERHTML,TITLE){
	var IMG_DIR = "/images/modal/";
	var HTML = '<div id="MODAL_C1" align="center" style="position:fixed; left:0px; top:0px; z-index:99999; background-image:url(\''+IMG_DIR+'/fade_65.png\');"></div>';
	
	HTML += '<div id="MODAL_C2" style="position:fixed; left:0px; top:0px; z-index:999999;">';
	HTML += '<table width="250" border="0" cellspacing="0" cellpadding="0">';
	HTML += '<tr><td>';
	HTML += '<table width="100%" border="0" cellpadding="0" cellspacing="0">';
	HTML += '<tr>';
	HTML += '<td width="25" align="left" valign="top"><img src="'+IMG_DIR+'/top_left.png" width="25" height="52" /></td>';
	HTML += '<td style="background-image:url(\''+IMG_DIR+'/top_middle.png\'); background-repeat:repeat-x; background-position:top;"><img src="'+IMG_DIR+'/spacer.png" height="52" width="52" /></td>';
	HTML += '<td width="25" align="right" valign="top"><img src="'+IMG_DIR+'/top_right.png" height="52" /></td>';
	HTML += '</tr>';
	HTML += '</table>';
	HTML += '</td>';
	HTML += '</tr>';
	HTML += '<tr>';
	HTML += '<td>';
	HTML += '<table width="100%" border="0" cellpadding="0" cellspacing="0">';
	HTML += '<tr>';
	HTML += '<td width="25" style="background-image:url('+IMG_DIR+'/middle_left.png); background-repeat:repeat-y; background-position:left;"><img src="'+IMG_DIR+'/spacer.png" alt="" width="25" height="25" /></td>';
	HTML += '<td bgcolor="#FFFFFF">'+INNERHTML+'</td>';			
	HTML += '<td width="25" style="background-image:url(\''+IMG_DIR+'/middle_right.png\'); background-repeat:repeat-y; background-position:right;"><img src="'+IMG_DIR+'/spacer.png" alt="" width="25" height="25" /></td>';
	HTML += '</tr>';
	HTML += '</table>';
	HTML += '</td>';
	HTML += '</tr>';
	HTML += '<tr>';
	HTML += '<td>';
	HTML += '<table width="100%" border="0" cellpadding="0" cellspacing="0">';
	HTML += '<tr>';
	HTML += '<td width="25" align="left" valign="bottom"><img src="'+IMG_DIR+'/bottom_left.png" alt="" width="25" height="25" /></td>';
	HTML += '<td style="background-image:url('+IMG_DIR+'/bottom_middle.png); background-repeat:repeat-x; background-position:bottom;"><img src="'+IMG_DIR+'/spacer.png" height="25" width="25" /></td>';
	HTML += '<td width="25" align="right" valign="bottom"><img src="'+IMG_DIR+'/bottom_right.png" alt="" width="25" height="25" /></td>';
	HTML += '</tr>';
	HTML += '</table>';
	HTML += '</td></tr>';
	HTML += '</table>';
	HTML += '</div>';
	
	if(TITLE){
		HTML += '<div id="MODAL_TITLE" align="left" style="position:fixed;height:18px;width:200px;overflow:hidden;white-space:nowrap;left:0px;top:0px;z-index:9999999;"><span style="color:#FFF; font-weight:600; text-shadow:#000 0px 0px 4px; font-face:Helvetica,Arial; font-size:12px;">'+TITLE+'</span></div>';
	}
	
	HTML += '<div id="MODAL_CLOSE" align="left" style="position:fixed; left:0px; top:0px; z-index:9999999;"><a href="#none" title="Close Window"><img src="'+IMG_DIR+'/close.png" border="0" onClick="hideModal();" onMouseOver="this.src=\''+IMG_DIR+'/close_on.png\';" onMouseOut="this.src=\''+IMG_DIR+'/close.png\';"></div>';
	
	
	var DIV = document.createElement("div");
	DIV.innerHTML = HTML;
	DIV.setAttribute('id','MODAL');
	document.body.appendChild(DIV);
	
	/* calculate window width and height */
	if(parseInt(navigator.appVersion)>3){
		if(window.innerHeight){
			ww = window.innerWidth;
			wh = window.innerHeight;
		}else{
			var ww = document.documentElement.clientWidth;
			var wh = document.documentElement.clientHeight;
		}
	}
	
	/* resize the MODAL_C1 div to fit the window */	
	obj('MODAL_C1').style.width = ww+'px';
	obj('MODAL_C1').style.height = wh+'px';
	
	/* calculate the size of the MODAL_C2 div */
	mw = obj('MODAL_C2').clientWidth;
	mh = obj('MODAL_C2').clientHeight;
	
	/* positon the MODAL_C2 div */
	if(wh>mh){
		obj('MODAL_C2').style.top = ((wh-mh)/2)+'px';
	}else{
		obj('MODAL_C2').style.top = '75px';
	}
	if(ww>mw){
		obj('MODAL_C2').style.left = ((ww-mw)/2)+'px';
	}else{
		obj('MODAL_C2').style.left = '50px';
	}
	
	/* position the MODAL_CLOSE div */
	obj('MODAL_CLOSE').style.left = (Number(obj('MODAL_C2').style.left.replace(/[^0-9.]/g,''))+mw-71)+'px';	
	obj('MODAL_CLOSE').style.top = 	(Number(obj('MODAL_C2').style.top.replace(/[^0-9.]/g,''))+16)+'px';

	/* position the MODAL_TITLE div */
	if(TITLE){
		obj('MODAL_TITLE').style.left = (Number(obj('MODAL_C2').style.left.replace(/[^0-9.]/g,''))+27)+'px';	
		obj('MODAL_TITLE').style.top = 	(Number(obj('MODAL_C2').style.top.replace(/[^0-9.]/g,''))+27)+'px';
		obj('MODAL_TITLE').style.width = (mw-124)+'px';
	} 
}

function hideModal(){
	document.body.removeChild(obj('MODAL'));
}












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 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 core(cmd,args,callbacks){
	POST("/core/"+cmd+"?",args,"var core = eval(\"(\"+response+\")\");  if(core['JS']){ eval(core['JS']) }  var callbacks="+JSON.stringify(callbacks)+"; if(callbacks){ if(callbacks[core['RESPONSE']]){ eval(callbacks[core['RESPONSE']]); } }","var callbacks="+JSON.stringify(callbacks)+"; eval(callbacks['TIMEOUT']);",nocache());
}

function nocache(){
	var d = new Date;
	return d.getMilliseconds();
}





function ifKey(key,action){
	try{
		if(window.event.keyCode){
			if(window.event.keyCode==key){
				eval(action);
			}
		}else if(e.which){
			if(e.which==key){
				eval(action);
			}
		}
	}
	catch(e){}
}





/**
 * Converts the given data structure to a JSON string.
 * Argument: arr - The data structure that must be converted to JSON
 * Example: var json_string = array2json(['e', {pluribus: 'unum'}]);
 * 			var json = array2json({"success":"Sweet","failure":false,"empty_array":[],"numbers":[1,2,3],"info":{"name":"Binny","site":"http:\/\/www.openjs.com\/"}});
 * http://www.openjs.com/scripts/data/json_encode.php
 */
function array2json(arr) {
    var parts = [];
    var is_list = (Object.prototype.toString.apply(arr) === '[object Array]');

    for(var key in arr) {
    	var value = arr[key];
        if(typeof value == "object") { //Custom handling for arrays
            if(is_list) parts.push(array2json(value)); /* :RECURSION: */
            else parts[key] = array2json(value); /* :RECURSION: */
        } else {
            var str = "";
            if(!is_list) str = '"' + key + '":';

            //Custom handling for multiple data types
            if(typeof value == "number") str += value; //Numbers
            else if(value === false) str += 'false'; //The booleans
            else if(value === true) str += 'true';
            else str += '"' + value + '"'; //All other things
            // :TODO: Is there any more datatype we should be in the lookout for? (Functions?)

            parts.push(str);
        }
    }
    var json = parts.join(",");
    
    if(is_list) return '[' + json + ']';//Return numerical JSON
    return '{' + json + '}';//Return associative JSON
}




