function $(t){return document.getElementById(t)}

function insertSelected(_sel,_tar){
	var a=$(_sel).options[$(_sel).selectedIndex].value;
	$(_tar).value=(a!="---")?a:"";
}



/******/
function initiateMonthSetup(){
	sortSelectsOut("pc_srouceSelect","pc_targetSelect");
	sortSelectsOut("amiga_srouceSelect","amiga_targetSelect");
}
/**
 * compare the two tables, and remove from source whatever is found in target
 * @access public
 * @return void
 **/
function sortSelectsOut(src,trgt){
	var s=$(src);
	var t=$(trgt);
	var tabs=new Array();
	var tabt=new Array();
	var tabnew=new Array();

	for (i=0;i<s.options.length;i++){
		tabs[i]={text:s.options[i].text,value:s.options[i].value};
	}
	for (i=0;i<t.options.length;i++){
		tabt[i]={text:t.options[i].text,value:t.options[i].value};
	}


	for (i=0;i<tabs.length;i++){
		for (ii=0;ii<tabt.length;ii++){
			if (tabt[ii].value==tabs[i].value) {
				tabs[i].value="-";
			}
		}
	}
	s.options.length=0;
	var ile=0;
	for (i=0;i<tabs.length;i++){
		if (tabs[i].value!="-") {
			s.options[ile]=new Option(tabs[i].text,tabs[i].value);
			ile++;
		}
	}
}




function moveItemHorizontally(_src,_tar){
	var s=$(_src);
	var t=$(_tar);
	var tabs=new Array();
	var tabt=new Array();
	var chosenIndex=s.selectedIndex;
	var selected=null;

	var count=0;
	for (i=0;i<s.options.length;i++){
		if (chosenIndex==i) {
			selected={text:s.options[i].text,value:s.options[i].value}
		}else{
			tabs[count]={text:s.options[i].text,value:s.options[i].value};
			count++;
		}
	}

	t.options[t.options.length]=new Option(selected.text,selected.value);
	s.options.length=0;

	for (i=0;i<tabs.length;i++){
			s.options[i]=new Option(tabs[i].text,tabs[i].value);
	}
	t.selectedIndex=t.options.length-1;
//	s.selectedIndex=s.options.length-1;
}
function moveItemVertically(_typ,_tar){
	var o=$(_tar);
	var chosen=o.selectedIndex;
	var chosenless=chosen-1;
	var chosenmore=chosen+1;
	var chosenexit=chosen;
	var chosenmax=o.options.length;
	//copy table
	var tabela=new Array();
	for (i=0;i<chosenmax;i++){
		tabela[i]=o.options[i];
	}


//alert(chosenmax)
	switch(_typ){
		case "up":
			if ((chosen> -1)&&(chosenless> -1)) {
				var x=tabela[chosen];
				tabela[chosen]=tabela[chosenless];
				tabela[chosenless]=x;
				chosenexit=chosenless;
			}
			;
			break;
		case "down":
			if ((chosen> -1)&&(chosenmore < chosenmax)) {
				var x=tabela[chosen];
				tabela[chosen]=tabela[chosenmore];
				tabela[chosenmore]=x;

				chosenexit=chosenmore;
			}
			;
			break;
	default:
			;
	} // switch

	o.options.length=0;
	for (i=0;i<chosenmax;i++){
		o.options[i]=new Option(tabela[i].text,tabela[i].value);
	}
	o.selectedIndex=chosenexit
}



function votersFormSubmit(){
	var op=$("pc_targetSelect");
	var oa=$("amiga_targetSelect");
	var pc_values="";
	var amiga_values="";

	for (i=0;i<op.options.length;i++){
		pc_values+=op.options[i].value+"-";
	}

	for (i=0;i<oa.options.length;i++){
		amiga_values+=oa.options[i].value+"-";
	}

	var o=$("voters");
	var utworzony=document.createElement("input");
	utworzony.setAttribute("type","hidden");
	utworzony.setAttribute("name","pc_selection");
	utworzony.setAttribute("value",pc_values);
	o.appendChild(utworzony);

	utworzony=document.createElement("input");
	utworzony.setAttribute("type","hidden");
	utworzony.setAttribute("name","amiga_selection");
	utworzony.setAttribute("value",amiga_values);
	o.appendChild(utworzony);

	//
}


function validateVoteForm(){
	if ($("voter_name").value=="") {
		alert("Please provide the following:\nNick\nemail");
		return false;
	}
	if ($("voter_email").value=="") {
		alert("Please provide the following:\nNick\nemail");
		return false;
	}
	return true;
}