
var http_request = false;


function AllowNext(typ){ //checks if necessary fields are filled-up before allowing next button
	if(typ=="mov"){
		if (((document.getElementById("or_state").value==68) && (document.getElementById("dor_state").value!='') && (document.getElementById("moveSize").value!=''))
		 || ((document.getElementById("or_state").value!='') && (document.getElementById("dor_state").value!='') && (document.getElementById("moveSize").value!='') && (document.getElementById("or_city").value!=''))){
			document.getElementById("next").disabled = false;
		}
		else
			document.getElementById("next").disabled = true;
	}
	else if(typ=="lupu"){
		if((document.getElementById("or_city").value!='') && (document.getElementById("dor_city").value!='' || document.forms[0].samecity.checked)){
			document.getElementById("next").disabled = false;
		}
		else{
			document.getElementById("next").disabled = true;
		}
	}
}

function naNext(){	//disables next button on form; lupu/index.php
	document.getElementById("next").disabled = true;
}

function get(obj) {	//gets the cities of the selected state in origin using New/fs_1.php; lupu/index.php
	
	var poststr = "or_state=" + encodeURI(document.getElementById("or_state").value );
	document.getElementById("or_city").options.length=0;
		
	makePOSTRequest('../modules/fs_1.php', poststr);
	document.getElementById('loaderContainer').style.visibility='visible';	 
}
   
function get2(obj){	//gets the cities of the selected state in destination using New/fs_2.php; lupu/index.php     
	var poststr = "dor_state=" + encodeURI(document.getElementById("dor_state").value );		 
	document.getElementById("dor_city").options.length=0;
	
	makePOSTRequest('../modules/fs_2.php', poststr);
	document.getElementById('loaderContainer').style.visibility='visible';	 
}

function showmap(t) {	//shows map for origin
	window.open("../modules/map.php?i="+t,"map","toolbar=no,location=no,directories=no,status=no,scrollbars=no,menubar=no,fullscreen=no,width=540,height=360");
}

function showmap2(t) {//shows map for destination
	window.open("../modules/map2.php?i="+t,"map","toolbar=no,location=no,directories=no,status=no,scrollbars=no,menubar=no,fullscreen=no,width=540,height=360");
}

function addOption(optionText,optionValue,OptionBool,selectObject) { //add options; used in New/fs_1.php and New/fs_2.php;
	//alert(OptionBool);
	selectObject= document.getElementById(selectObject);
	var optionObject = new Option(optionText,optionValue,false,false)
	var optionRank = selectObject.options.length
	selectObject.options[optionRank]=optionObject
}

function alertContents() {
	if (http_request.readyState == 4){
		if (http_request.status == 200){
			result = http_request.responseText;
			eval(result);
			
			document.getElementById('loaderContainer').style.visibility='hidden';
			document.getElementById('cityrec').innerHTML="<i>if your city is not listed, please select nearest location.</i>";
						     
 		} else {
    	alert('There was a problem with the request. ' + http_request.status);
    }
  }
}

function submit1(obj){
	switch(obj){
		case '1':alert("You can fill this form and have a look how form works");
		case '2':alert("this will go to Loading/Unloading Tab"); break;
		case '3':alert("this will go to Transportation Providers Tab"); break;
		case '4':alert("this will go to Storage Facilities Tab"); break;
		case '5':alert("Packing supplies & Materials"); break;
		default:alert("Unknown Option");
	}
}

function makePOSTRequest(url, parameters){
  http_request = false;
  
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
  	http_request = new XMLHttpRequest();
    
    if (http_request.overrideMimeType) {
    	// set type accordingly to anticipated content type
      //http_request.overrideMimeType('text/xml');
      http_request.overrideMimeType('text/html');
    }
  } else if (window.ActiveXObject) { // IE
  	try {
    	http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
     	try {
      	http_request = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch (e) {}
    }
  }
  
  if (!http_request) {
  	alert('Cannot create XMLHTTP instance');
    return false;
  }
      
	http_request.onreadystatechange = alertContents;
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);
}

/************************************************************************************************************************/

function switchlabors(number) {
		switch(number){
			case "1": number=225;break;
			case "2": number=340;break;
			case "3": number=400;break;
			case "4": number=480;break;
			case "5": number=640;break;
			default: number=0;
		}
		a="<font color='130d57' size='-1' face='Verdana,Arial, Helvetica, sans-serif'> x 3 hours = $"	+ number  + "*" + "</font>";

		switch(number){
			case 225: number=55;break;
			case 340: number=80;break;
			case 400: number=90;break;
			case 480: number=105;break;
			case 640: number=120;break;
			default: number=0;
		}
		b="$"+ number + " / hour";
		z="<font color='130d57' size='-1' face='Arial, Helvetica, sans-serif'> Including MUWC Deposit: $" + number + "</font> ";
		
		document.getElementById('total').innerHTML=a;
		document.getElementById('additional').innerHTML=b;
		document.getElementById('MUWC').innerHTML=z;
}

function radio_button_checker(fr)	{
	// set var radio_choice to false
	var radio_choice = false;
	// Loop from zero to the one minus the number of radio button selections
	for (counter = 0; counter < fr.card.length; counter++){
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (fr.card[counter].checked)
			radio_choice = true; 
	}
	if (!radio_choice){
		// If there were no selections made display an alert box 
		document.getElementById("err").innerHTML = document.getElementById("err").innerHTML +	"<ul style='color:red;font-size:11px'><li> Select card type </li></ul>";
		return (false);
	}
	return (true);
}


