function gotoStep(stepNumber){
	stepLinks = [document.getElementById('step0_link'), document.getElementById('step1_link'), document.getElementById('step2_link'), document.getElementById('step3_link')];
	for(i=0;i<stepLinks.length;i++){
		if(stepNumber == i){
			show('step'+i);
			stepLinks[i].className='visited step';
			if (stepLinks[i].firstChild.nodeValue[0] != "\u00BB"){
				stepLinks[i].firstChild.nodeValue = "\u00BB" + stepLinks[i].firstChild.nodeValue;
			}
			stepLinks[i].setAttribute("href", "javascript:gotoStep("+i+");");
		}else{
			hide('step'+i);
		   stepLinks[i].className = stepLinks[i].className.replace("step", "");
			if (stepLinks[i].firstChild.nodeValue[0] == "\u00BB"){
				stepLinks[i].firstChild.nodeValue = stepLinks[i].firstChild.nodeValue.substr(1);
			}
		}
	}
}

function gotoShippingInfo(shippingStep){
	switch(shippingStep){
		case "1a" :
			removeInsertedElements();
			document.getElementById('air_international_numberpieces').value = "";
			show('shippinginfo_air_international');
			hide('shippinginfo_air_domestic');
			hide('shippinginfo_ocean');
			hide('shippinginfo_surface');
			hide('submit_to_2');
			break;
		case "1b" :
			removeInsertedElements();
	  		document.getElementById('air_domestic_numberpieces').value = "";
         hide('shippinginfo_air_international');
         show('shippinginfo_air_domestic');
         hide('shippinginfo_ocean');
         hide('shippinginfo_surface');
	  		hide('submit_to_2');
         break; 
       case "1c" :
			removeInsertedElements();
			document.getElementById('ocean_numberpieces').value = "";
			document.getElementById('ocean_containerload').value = "fcl";
			hide('ocean_packingsizes');
         hide('shippinginfo_air_international');
         hide('shippinginfo_air_domestic');
         show('shippinginfo_ocean');
         hide('shippinginfo_surface');
			show('submit_to_2');
         break; 
       case "1d" :
			removeInsertedElements();
			document.getElementById('surface_numberpieces').value = "";
			document.getElementById('surface_truckload').value = "ftl";
         hide('surface_packingsizes');
			hide('shippinginfo_air_international');
         hide('shippinginfo_air_domestic');
         hide('shippinginfo_ocean');
         show('shippinginfo_surface');
			show('submit_to_2');
         break;
	}
}

function showPackingSizes(shippingType){
	root = document.getElementById('shippinginfo_'+shippingType);
	 
	removeInsertedElements();
	
   numberOfSizes = document.getElementById(shippingType+'_numberpieces').value;
   template = document.getElementById(shippingType+'_containertype');
   for(i=0;i<numberOfSizes;i++){
       newContainer = template.cloneNode(true);
       newContainer.id = newContainer.id + i;
		 newContainer.className = 'inserted';
       
       newContainerLegend = cssQuery("legend", newContainer);
       newContainerLegend[0].firstChild.nodeValue = newContainerLegend[0].firstChild.nodeValue + " " + Num2Word(i+1);
       
       newContainerElements = cssQuery("[id]", newContainer);
       for(j=0;j<newContainerElements.length;j++){
           newContainerElements[j].id = newContainerElements[j].id + i;
       }
       
       newContainerLabels = cssQuery("label", newContainer);
       for(k=0;k<newContainerLabels.length;k++){
           newContainerLabels[k].setAttribute("for", newContainerLabels[k].getAttribute("for") + i);
       }
       
       newContainerNames = cssQuery("[name]", newContainer);
       for(l=0;l<newContainerNames.length;l++){
           newContainerNames[l].setAttribute("name", newContainerNames[l].getAttribute("name") + i);
       }
       
       root.appendChild(newContainer);
   }
   show('submit_to_2');
}

function showOceanPackingSizes(containerLoad){
	if (containerLoad == 'lcl'){
		removeInsertedElements();
		document.getElementById('ocean_numberpieces').value = "";
		show('ocean_packingsizes');
		hide('submit_to_2');
	}else if (containerLoad == 'fcl'){
		removeInsertedElements();
		hide('ocean_packingsizes');
		show('submit_to_2');
	}
}

function showSurfacePackingSizes(truckLoad){
	if (truckLoad == 'ltl'){
		removeInsertedElements();
		document.getElementById('surface_numberpieces').value = "";
		show('surface_packingsizes');
		hide('submit_to_2');
	}else if (truckLoad == 'ftl'){
		removeInsertedElements();
		hide('surface_packingsizes');
		show('submit_to_2');
	}
}

function validate(){
	if(document.getElementById('contactname').value != "" && document.getElementById('telephone').value != ""){
		return true;
	}else{
		alert("Contact Name and Telephone are required.");
		return false;
	}
}

function validate_shipping_info(){
	if((document.getElementById('internationalair').checked && document.getElementById('air_international_commodity').value == "") || (document.getElementById('domesticair').checked && document.getElementById('air_domestic_commodity').value == "") || (document.getElementById('ocean').checked && document.getElementById('ocean_commodity').value == "") || (document.getElementById('surface').checked && document.getElementById('surface_commodity').value == "")){
		alert('Commodity is required.')
		return false;
	}else{
		gotoStep('2');
	}
}
