function my_submit() { 	
	
	if (check_inputs()) document.generalform.submit();
}

function check_inputs() {

	//check if radio buttons are set for both input
	input1_choise = get_radio("generalform","input1");
	input2_choise = get_radio("generalform","input2");

	//if none then print error
	if (input1_choise == "empty") {
		alert("Select one possible choice for first input sequence...");
		return false;
	}
	else if (input2_choise == "empty") {
		alert("Select one possible choice for second input sequence...");
		return false;
	}

	//if set, check that fields are not blank
	if ( check_blank_field(input1_choise,1) && check_blank_field(input2_choise,2) )	
	{	
		//passed all checks. SUBMIT form
		//alert("sottomesso!");
		return true;
	}
	else {return false;}

}

function check_blank_field(id,num){


	field = get_field(id,num);
	myarr = field.split('*'); i = 0;

	//caso particolare, inserito CROMOSOMA
	if (id == 'range') { 
		for (i in myarr) {
			if ( document.getElementById(myarr[i]).value == '' ) {
				alert("For chromosomal range(input n."+num+"), you must specify every field...");
				return false; 
			}
		}
		if (  document.getElementById(myarr[1]).value > document.getElementById(myarr[2]).value  ) {
			alert("Chromosomal error (input n."+num+"):\nThe start value cannot be greater than the end value"); 
			return false;
		}
		return true;
	}
	
	else {
		temp_field = myarr[0];

		oggetto = document.getElementById(temp_field);

		if (oggetto != null) {

			if (oggetto.value != "")  return true;
			else {
				alert("Input n."+num+" has a blank field selected..."); 
				return false;
			}
			
		}
		else { alert("Error field not defined!!"); return false;}
	}
	
	

}

function set_radio(form_name, radio_name, radio_choise) {
	radioSet=eval("document."+ form_name +"."+ radio_name);
	for (i=0;i < radioSet.length;i++) {
		if (radioSet[i].value == radio_choise) 
			radioSet[i].checked = true; 
	}

}

function get_radio(form_name, radio_name) {
	radioSet=eval("document."+ form_name +"."+ radio_name);
	for (i=0;i < radioSet.length;i++) {
		if (radioSet[i].checked == true) 
			return radioSet[i].value;
	}
	return "empty";

}

function get_field(name,number) {
	
	switch(name) {
		case "paste":  return "seq"+number;
		break;
		case "upload":  return "file"+number;
		break;
		case "gene":  return "genename"+number+"*"+"baserange"+number;
		break;
		case "range":  return "chr"+number+"*"+"start"+number+"*"+"end"+number;
		break;
		default: return "error";
	}
}
      
function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;

      }
function myPopUp(URL) {
        day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=320,left = 50,top = 80');");
}

