/* Copyright 2005 - 2007 www.mihalism.com */

num = 0;
dah = 10

function dispMoreFiles() {
	if (num<dah) {
		var filelocal = document.getElementById('morefiles');
		var fileID = "file"+num+"input";
		var fileDIV = document.createElement('div');
		fileDIV.setAttribute("id", fileID);
		fileDIV.innerHTML = "<INPUT name='userfile[]' id='"+fileID+"' style=\"height:21px;width:400px;\" TYPE='file' size='50'> <input type=\"button\" onclick=\"javascript:rmvMoreFiles('"+fileID+"')\" style=\"height:21px;\" value=\"Remove\"> <br>";
		filelocal.appendChild(fileDIV);
		num++;
	} else {
		alert('You can only add '+dah+' files to each upload.');
	}
}
	
function rmvMoreFiles(divNum){
	var d = document.getElementById('morefiles');
	var olddiv = document.getElementById(divNum);
	d.removeChild(olddiv);
	num--;
}

function highlight(field) {
       	field.focus();
       	field.select();
}

function toggle(id) {
	var obj = "";
	if(document.getElementById){
		obj = document.getElementById(id);
	}else if(document.all){
		obj = document.all[id];
	}else if(document.layers){
		obj = document.layers[id];
	}else{
		return 1;
	}
	if (!obj){
		return 1;
	}else if(obj.style){
		obj.style.display = ( obj.style.display != "none" ) ? "none" : "";
	}else{ 
		obj.visibility = "show"; 
	}
}

_uacct = "UA-1125794-2";

function setSelectionRange(input, selectionStart, selectionEnd) {
	if (input.setSelectionRange) {
		input.focus();
		input.setSelectionRange(selectionStart, selectionEnd);
	}else if (input.createTextRange) {
		var range = input.createTextRange();
		range.collapse(true);
		range.moveEnd('character', selectionEnd);
		range.moveStart('character', selectionStart);
		range.select();
	}
}

function replaceSelection (input, replaceString) {
	if (input.setSelectionRange) {
		var selectionStart = input.selectionStart;
		var selectionEnd = input.selectionEnd;
		input.value = input.value.substring(0, selectionStart)+ replaceString + input.value.substring(selectionEnd);
		if (selectionStart != selectionEnd){ 
			setSelectionRange(input, selectionStart, selectionStart + 	replaceString.length);
		}else{
			setSelectionRange(input, selectionStart + replaceString.length, selectionStart + replaceString.length);
		}
	}else if (document.selection) {
		var range = document.selection.createRange();
		if (range.parentElement() == input) {
			var isCollapsed = range.text == '';
			range.text = replaceString;
			 if (!isCollapsed)  {
				range.moveStart('character', -replaceString.length);
				range.select();
			}
		}
	}
}

function catchTab(item,e){
	if(navigator.userAgent.match("Gecko")){
		c=e.which;
	}else{
		c=e.keyCode;
	}
	if(c==9){
		replaceSelection(item,String.fromCharCode(9));
		setTimeout("document.getElementById('"+item.id+"').focus();",0);	
		return false;
	}	    
}

if(dah != 10){
	alert("INVALID KEY");
}
