//-- WINDOW FUNCTIONS --

var win = new Array();
var winCount = 0;


//-- LAUNCH NEW WINDOW --

function win_open(url,name,winArgs,focus,timeout){

	if(winArgs == 'full'){
		winArgs = 'width='+document.body.clientWidth+',height='+document.body.clientHeight;
	}

	if(winArgs == 'half'){
		winArgs = 'width='+document.body.clientWidth/2+','+document.body.clientHeight;
	}

	eval('win['+winCount+'] = window.open(\''+url+'\',\''+name+'\',\'scrollbars=yes,resizable=yes,status=yes,'+winArgs+'\')');
	if(focus == 'self'){ self.focus(); }
	if(timeout > 0){ setTimeout('win[winCount-1].close()',(timeout*1000)); }
	winCount++;
}


//-- CLOSE ALL OPEN WINDOWS --

function win_close(){
	for(x = 0; x < winCount; x++){
		win[x].close();
	}
}


//-- LAUNCH HELP WINDOW --

function help(keywords){
	win_open('http://63.241.144.187/templates/default.asp?id=19448&PG=Search&target='+ keywords,'Manual','','',-1);
	win[winCount-1].focus();
}


//-- LAUNCH PREVIEW WINDOW --

function preview(id,query){
	var page = "?id="+id;
	if(query != ""){ page += '&'+ query; }
	win_open('../templates/default.asp'+page,'Preview','','',-1);
	win[winCount-1].focus();
}




//-- NAVIGATION FUNCTIONS --

//-- EXIT MANAGER --

var origin = '';

function exitManager(){
	var loc = document.location+'';

	win_close(); //-- Close all opened windows.

	if(loc.indexOf("admin.asp") != -1){
		document.location = origin;
	}else{
		document.location = 'admin.asp';
	}
}


//-- FRAME NAVIGATE TO PAGE --

function navTo(page,fName){ eval(fName+'.location = '+page); }





//-- FORM FUNCTIONS --

var errors = 0;
var formName = 'input';


//-- SET SELECT --

function set_select(name,id){
	for(x = 0; x < eval('document.'+formName+'.'+name+'.length'); x++){
		if(eval('document.'+formName+'.'+name+'['+x+'].value == "'+id+'"')){
			eval('document.'+formName+'.'+name+'.selectedIndex = '+x);
		}
	}
}


//-- EVENT HANDLING --


function new_eventHandler(action,pList,pVal){
	var paramList = pList.split(",");
	var paramValue = pVal.split(",");

	document.write('<form name="eventHandler" action="'+ action +'.asp" method="POST">\n');

	for(x = 0; x < paramList.length; x++){
		document.write('<input type="hidden"" name="'+ paramList[x] +'" value="'+ paramValue[x] +'">\n');
	}
	document.write('</form>\n');
}


function new_event(pList,pVal){
	var paramList = pList.split(",");
	var paramValue = pVal.split(",");

	for(x = 0; x < paramList.length; x++){
		eval('document.eventHandler["'+ paramList[x] +'"].value = "'+ paramValue[x] +'"');
	}

	document.eventHandler.submit();
}

function set_select(field,value){
	for(x = 0; x < eval('document.'+formName+'.'+field+'.length'); x++){
		if(eval('document.'+formName+'.'+field+'['+x+'].value == '+ value)){
			eval('document.'+formName+'.'+field+'.selectedIndex = '+x)
		}
	}
}

//-- FORM VALIDATION ROUTINES --


function new_test(){
	errors = 0;
}

function send_form(){
	if(errors == 0){ eval('document.'+formName+'.submit()');	}
}

function raiseError(field,errorTxt,type){
	errors++;
	if(type == 1){ alert('ERROR: You must enter a valid value for '+ errorTxt +'.'); }
	if(type == 2){ alert('ERROR: You must select a '+ errorTxt +' option.'); }
	if(type == 3){ alert('ERROR: '+ errorTxt +' is not a valid date.'); }
	eval('document.'+formName+'.'+field+'.focus()');
}

function check_text(field,errorTxt){
	if(errors == 0){
		if(eval('document.'+formName+'.'+field+'.value == ""')){
			raiseError(field,errorTxt,1);
		}
	}
}

function check_select(field,errorTxt){
	if(errors == 0){
		if(eval('document.'+formName+'.'+field+'.selectedIndex == 0')){
			raiseError(field,errorTxt,2);
		}
	}
}

function check_box(field,errorTxt){
	if(errors == 0){
		if(! eval('document.'+formName+'.'+field+'.checked')){
			raiseError(field,errorTxt,2);
		}
	}
}

function check_len(field,errorTxt,operator,length){
	if(errors == 0){
		if(eval('document.'+formName+'.'+field+'.value.length '+operator+' '+length)){
			raiseError(field,errorTxt,1);
		}
	}
}

function check_str(field,errorTxt,target){
	if(errors == 0){
		var cStr = eval('document.'+formName+'.'+field+'.value');
		if(cStr.indexOf(target) == -1){
			raiseError(field,errorTxt,1);
		}
	}
}

function check_email(field){
	var domainFound = 0;
	var dList = new Array('com','net','org','mil','biz','info','tv','ws','as','ac','at','au','be','do','tp','hm','lt','nz','pk','ru','vc','st','za','to','ua','uk','vu','vg','cx','ms','gs','tj','tc','cc');

	var eStr = eval('document.'+formName+'.'+field+'.value');
	check_str(field,'e-mail (missing "@")','@');

	if(errors == 0){
		for(x = 0; x < dList.length; x++){
			if(eStr.indexOf('.'+dList[x]) >= 1){
				domainFound = 1;
				break;
			}
		}
		if(domainFound == 0){
			raiseError(field,'e-mail (invalid domain)',1);
		}
	}
}

function check_num(field,errorTxt){
	if(errors == 0){
		var cStr = eval('document.'+formName+'.'+field+'.value');
		if(cStr - cStr != 0){
			raiseError(field,errorTxt,1);
		}
	}
}

function check_date(field,errorTxt){
	if(errors == 0){
		var strDate = eval('document.'+formName+'.'+field+'.value');
		var checkDate = new Date(strDate);
		if((checkDate.getMonth() + 1) != strDate.substring(0,strDate.indexOf("/"))){
			raiseError(field,strDate,3);
		}
	}
}

function replace_str(field,target,result){
	eval('document.'+formName+'.'+field+'.value = document.'+formName+'.'+field+'.value.replace(/'+target+'/g, "'+result+'")');
}



//-- DYNAMIC MEASUREMENTS --

function set_Width(pix){
	return (document.body.clientWidth - pix);
}

function set_Height(pix){
	return (document.body.clientHeight - pix);
}


//-- WRITE DYNAMIC IFRAME --

function create_Iframe(src,name,width,height,scroll){

	if((scroll == "Y")||(scroll == "y")){ scroll = "YES"; }else{ scroll = "NO"; }
	if(width == 0){ width = set_Width(250); }
	if(height == 0){ height = set_Height(100); }

	document.write('<P><IFRAME WIDTH='+width+' HEIGHT='+height+' NAME="'+name+'" SRC="'+src+'" SCROLLING='+scroll+' MARGINWIDTH=0 MARGINHEIGHT=0></IFRAME></P>');
}



//-- MENU DISPLAY FUNCTIONS --

function windowShade(id){
	if(document.all){
		if(eval('document.all["'+id+'"].style.display == "none"')){
			eval('document.all["'+id+'"].style.display = ""');
		}else{
			eval('document.all["'+id+'"].style.display = "none"');
		}
	}
}

function positionDialog(id,top,left){
	if(document.all){
		eval('document.all.'+id+'.style.top = '+top+';');
		eval('document.all.'+id+'.style.left = '+left+';');
	}
}


//-- TOOL TIPS --

var tips = new Array();

function tip(id,content){
	this.id = id;
	this.content = content;
}

function showTip(lang,id,msg){
	if(document.all){
		document.all.tipBox.innerHTML = '<B>'+tips[(lang*1000)+id].id+'</B><BR>'+tips[(lang*1000)+id].content
		if(msg){ document.all.tipBox.innerHTML += ' '+msg; }
		if(event.clientX < 201){
			document.all.tipBox.style.left = document.body.scrollLeft + event.clientX;
		}else{
			document.all.tipBox.style.left = document.body.scrollLeft + event.clientX - 200;
		}
		document.all.tipBox.style.top = (document.body.scrollTop + event.clientY + 10);
		document.all.tipBox.style.visibility = 'visible';
	}
}

function hideTip(){
	if(document.all){
		document.all.tipBox.style.visibility = 'hidden';
		document.all.tipBox.innerHTML = '';
	}
}


//-- MENU MOUSE OVER --
function menuOver(linkID,classID){
	return false;
}

//-- MENU MOUSE OUT --
function menuOut(linkID,classID){
	return false;
}


//-- IMAGE FUNCTIONS --

function imgSwap(imgID,newSrc){
	if(document.images){
		document.images[imgID].src = 'menu/'+imgID+newSrc+'.gif';
	}
}


//-- SECURE RESOURCE MESSAGE --

function secureAlert(id){
	alert('SECURITY ALERT:\n\nThis resource requires a valid username and password. Please login on our home page.');
	document.location = 'default.asp?id='+id;
}


//-- BROWSER CHECK --

function browserCheck(){
	var bType = navigator.userAgent;
	var bName = navigator.appName;
	var bVer = navigator.appVersion;
	bVer = bVer.substring(bVer.lastIndexOf(";") - 3, bVer.lastIndexOf(';')) * 1
	var rVer = 5.5
	var OUT = '';

	if((bType.indexOf("MSIE") == -1)||(bVer < rVer)){
		OUT=OUT+ '<CENTER><TABLE WIDTH=700><TR><TD><H3>Windows PC and Internet Explorer '+ rVer +' Required:</H3>\n'+
		'You may continue using '+ bName +' '+ bVer +' to view your site; however, you will need to load Internet Explorer '+ rVer +' or later to administrate your site. If you recently ordered a site and did not have IE '+ rVer +' on your computer, we have already put a CD containing IE '+ rVer +' in the mail. If you are using a demo version or would like to begin administrating your site before the IE '+ rVer +' CD arrives, you may obtain IE '+ rVer +' by:\n<UL>\n'+
		'<LI>Downloading IE '+ rVer +' from <A HREF="http://www.microsoft.com/windows/ie/default.htm" TARGET="_blank">http://www.microsoft.com/windows/ie/default.htm.</A> '+
		'Please note that this download can take up to six hours and requires you to be online for the duration of the download.\n'+
		'<LI>Purchasing IE '+ rVer +' where you buy computer software.\n</UL></TD></TR></TABLE></CENTER>\n';

		document.write (OUT);
	}
}