// JavaScript Document

//This is a open Windows Used for Contact Forms and Help Links
function openBrWindow(theURL,winName) { //v2.0
    var width = 650;
	var height = 400;
	var y = (screen.height - height) / 2;
	var x = (screen.width - width) / 2;
	var features = "width=" + width + ",height=" + height + ",top=" + y + ",left=" + x + ", status, scrollbars";
  //window.open(theURL,winName,features);
	newwindow = window.open(theURL,winName,features);
	if (window.focus) {newwindow.focus()}

}

//This is a open Windows to View and Print Spot Rate
function openSPWindow(theURL,winName) { //v2.0
    var width = 650;
	var height = 400;
	var y = (screen.height - height) / 2;
	var x = (screen.width - width) / 2;
	var features = "width=" + width + ",height=" + height + ",top=" + y + ",left=" + x + ", status, scrollbars";
//  window.open(theURL,winName,features);
  	newwindow = window.open(theURL,winName,features);
	if (window.focus) {newwindow.focus()}
}

//This is a open Windows to Forwarder Air Tariffs
function openATWindow(theURL,winName) { //v2.0
    var width = 650;
	var height = 400;
	var y = (screen.height - height) / 2;
	var x = (screen.width - width) / 2;
	var features = "width=" + width + ",height=" + height + ",top=" + y + ",left=" + x + ", status, scrollbars";
//  window.open(theURL,winName,features);
	newwindow = window.open(theURL,winName,features);
	if (window.focus) {newwindow.focus()}
}

//This is a open Email Confirmation 
function openEMWindow(theURL,winName) { //v2.0
    var width = 400;
	var height = 200;
	var y = (screen.height - height) / 2;
	var x = (screen.width - width) / 2;
	var features = "width=" + width + ",height=" + height + ",top=" + y + ",left=" + x + ", status, scrollbars";
//  window.open(theURL,winName,features);
	newwindow = window.open(theURL,winName,features);
	if (window.focus) {newwindow.focus()}
}

//This is a open Email Confirmation 
function openNew(theURL,winName) { //v2.0
    var width = 650;
	var height = 400;
	var y = (screen.height - height) / 2;
	var x = (screen.width - width) / 2;
	var features = "width=" + width + ",height=" + height + ",top=" + y + ",left=" + x + ", status, scrollbars ";
//  window.open(theURL,winName,features);
  	newwindow = window.open(theURL,winName,features);
	if (window.focus) {newwindow.focus()}
}

function OpenCalc(i) {
	var openkey = i;
	var Unit = document.frmRequest.MorF.value;
	var noPieces = document.frmRequest.NoOfPieces.value;
	//hidden fields data
	var cValue1 = document.frmRequest.cValue1.value;
	var cValue2 = document.frmRequest.cValue2.value;
	var cValue3 = document.frmRequest.cValue3.value;
	var cValue4 = document.frmRequest.cValue4.value;
	var cValue5 = document.frmRequest.cValue5.value;
	var cValue6 = document.frmRequest.cValue6.value;
	var cValue7 = document.frmRequest.cValue7.value;
	var cValue8 = document.frmRequest.cValue8.value;
	var cValue9 = document.frmRequest.cValue9.value;
	var cValue10 = document.frmRequest.cValue10.value;

	//document.frmRequest.Click.value = 1;
	
	var width = 650;
	var height = 500;
	var y = (screen.height - height) / 2;
	var x = (screen.width - width) / 2;
	var url = "cubic_calc.php?NoPieces=" + noPieces + "&Unit=" + Unit + "&openky=" + openkey + "&cValue1=" + cValue1 + "&cValue2=" + cValue2 +  "&cValue3=" + cValue3 + "&cValue4=" + cValue4 +  "&cValue5=" + cValue5 + 
	"&cValue6=" + cValue6 + "&cValue7=" + cValue7 + "&cValue8=" + cValue8 + "&cValue9=" + cValue9 + "&cValue10=" + cValue10;
	var options = "width=" + width + ",height=" + height + ",top=" + y + ",left=" + x + ",scrollbars,status";
	
	if (noPieces>=1) {
		newwindow = window.open( url, "calc", options );
		if (window.focus) {newwindow.focus()}
	}
	else
	{
		alert('Number of pieces could not be Zero.');
	}

}

//Function That check The Calculated Fields in Shipper_Addspotrate, Forwarder_Addspotrate and Adding new Shipments
function checkSubmit() {
	var NPieces = document.frmRequest.NPieces.value
	var CubeUnit = document.frmRequest.CubeUnit.value
	var calCube = document.frmRequest.calCube.value
	var Cube = document.frmRequest.Cube.value
	var Click = document.frmRequest.Click.value

	var NoOfPieces = document.frmRequest.NoOfPieces.value
	var MorF = document.frmRequest.MorF.value

	if (Click==1) {
		//----------------------
		if (MorF=='M') {
		var uForm = 'Metres';
		}
		else
		{
		var uForm = 'Feet';
		}
		
		if (CubeUnit=='M') {
		var uCal = 'Metres';
		}
		else
		{
		var uCal = 'Feet';
		}

		//----------------------
		if ((NPieces==NoOfPieces) && (CubeUnit==MorF) && (Cube==calCube)  ) {
		document.frmRequest.Submit.disabled = false;
//		document.frmRequest.submit();
		}
		else
		{
		document.frmRequest.Submit.disabled = true;
		if (CubeUnit!=MorF) {
			alert('Calculator in Cubic ' + uCal + ', Form in Cubic ' + uForm + ', Units Must Match');
		}
		if (NPieces!=NoOfPieces) {
			alert('Calculator has ' + NPieces + ' Pieces, Form has ' + NoOfPieces + ' , Pieces must Match');
		}
		if (Cube!=calCube) {
			alert('Calculator has ' + calCube + ' Cubic ' + uCal + ', Form has ' + Cube + ' Cubic ' + uForm + ', Cube must Match');
		}


//		alert(NPieces+"-"+NoOfPieces+" "+CubeUnit+"-"+MorF);
		}

	}
	else
	{
	document.frmRequest.Submit.disabled = false;
//		document.frmRequest.submit();
	}

}
