//-- 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(); }else{ eval('win['+winCount+'].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();}
}

//-- PRINT CONTAINER --
function printData(template, winTitle, containerName){
	var PageContents = '';
	if(document.getElementById){
		if(document.getElementById(containerName)){
			PageContents = escape(document.getElementById(containerName).innerHTML);
		}
	}else{
		if(document.all){
			if(eval('document.all["'+ containerName +'"]')){
				PageContents = eval('escape(document.all["'+ containerName +'"].innerHTML)');
			}
		}
	}

	if(PageContents != ''){
		var printWin = window.open('','printWin','width=620,height=460,resizable=yes,scrollbars=yes');
		printWin.document.open();
		printWin.document.write('<HTML><HEAD><TITLE>'+ unescape(winTitle) +'</TITLE><LINK rel="stylesheet" type="text/css" href="/templates/'+ template +'/styles.css"></HEAD><BODY>'+ unescape(PageContents) +'</BODY></HTML>');
		printWin.document.close();
		printWin.defaultStatus = unescape(winTitle);
		printWin.print();
	}else{
		alert('ERROR: There was a problem printing the '+ containerName +' text.');
	}
}

//-- FORM FUNCTIONS --
var errors = 0;
var formName = 'input';


//-- CLEAR FORM --
function clearForm(curForm){
	var fieldType = '';
	for(x = 0; x < curForm.length; x++){
		fieldType = curForm.elements[x].type;
		if((fieldType == 'text')||(fieldType == 'textarea')||(fieldType == 'password')){
			curForm.elements[x].value = '';
		}
		if((fieldType == 'select-one')||(fieldType == 'select-multiple')){
			curForm.elements[x].selectedIndex = 0;
		}
		if((fieldType == 'checkbox')||(fieldType == 'radio')){
			curForm.elements[x].checked = false;
		}
	}
}


//-- SET SELECT --
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)
		}
	}
}

function set_field(name,value){eval('document.'+formName+'.'+name+'.value = "'+ value +'"');}

//-- 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_chr(field,errorTxt,target){
	if(errors == 0){
		var cStr = eval('document.'+formName+'.'+field+'.value');
		if(cStr.indexOf(target) != -1){raiseError(field,errorTxt,1);}
	}
}

function check_value(field,errorTxt,operator,target){
	if(errors == 0){
		if(eval('document.'+formName+'.'+field+'.value '+ operator +' '+ target)){raiseError(field,errorTxt,1);}
	}
}

function check_email(field){
	if(errors == 0){
		var eStr = eval('document.'+formName+'.'+field+'.value');
		check_str(field,'e-mail (missing "@")','@');
		check_str(field,'e-mail (missing ".")','.');
	}
}

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+'")');
}

//-- MENU DISPLAY FUNCTIONS --
function windowShade(id){
	if(document.getElementById){
		var curLayer = document.getElementById(id);
		var optionToggle = document.getElementById("OptionToggle");
		if(curLayer.style.display == "none"){
			if(optionToggle){optionToggle.innerHTML = 'Hide Options';}
			curLayer.style.display = "";
		}else{
			if(optionToggle){optionToggle.innerHTML = 'Show Options';}
			curLayer.style.display = "none";
		}
	}else{
		if(document.all){
			if(eval('document.all["'+id+'"].style.display == "none"')){
				if(document.all.OptionToggle){document.all.OptionToggle.innerHTML = 'Hide Options';}
				eval('document.all["'+id+'"].style.display = ""');
			}else{
				if(document.all.OptionToggle){document.all.OptionToggle.innerHTML = 'Show Options';}
				eval('document.all["'+id+'"].style.display = "none"');
			}
		}
	}
}

function positionDialog(id,top,left){
	if(document.getElementById){
		var curLayer = document.getElementById(id);
		curLayer.style.top = top;
		curLayer.style.left = left;
	}else{
		if(document.all){
			eval('document.all.'+id+'.style.top = '+top+';');
			eval('document.all.'+id+'.style.left = '+left+';');
		}
	}
}

//-- 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';}
}

//-- LAYER FUNCTIONS --
var docLayer = 'document.all';
var docStyle = '.style.';

if(document.layers){
	docLayer = 'document.layers';
	docStyle = '.';
}

if(document.getElementById){docLayer = 'document.getElementById';}

//-- UPDATE STYLE --

function updateStyle(layerName, styleName, styleVal){
	if(document.getElementById){
		var oLayer = document.getElementById(layerName);
		var oStyle = oLayer.getAttribute('style');
		oStyle.setAttribute(styleName, styleVal);
	}else{
		if(eval(docLayer+'["'+ layerName +'"]')){
			eval(docLayer+'["'+ layerName +'"]'+ docStyle + styleName +' = '+ styleVal);
		}
	}
}
