/*
This java script file includes all the functions related to surcharge.cgi 
*/

//Function to validate the input fields

function validateLocation(){
	var origin=document.searchForm.Origin.value;
	var destination=document.searchForm.Destination.value;
	var equipType=document.searchForm.EquipmentType.value;
	
	
//****Code changes for kintana#308630************************	
//**** Fuctionality to restrict a user from querying 1 month ahead and 6 months back of current date	
	
	var dateInput=document.searchForm.date.value;
			
	today=new Date();
	var mon=today.getMonth();
	var currmon=mon+2;
	var dt=today.getDate();
	var year=today.getYear();
	var dateentyr=dateInput;
	var ind=dateentyr.indexOf("/");
	var datmon=eval(dateentyr.substring(0,ind));
	var dateentmon=datmon;	        	
	var reststring=dateentyr.substring(ind+1,dateentyr.length);
	var ind1=reststring.indexOf("/");
	var dateentdt=reststring.substring(0,ind);		
	var reststring1=reststring.substring(ind1+1,reststring.length);
	var dateentyear=reststring1;
	var date_entered=dateentyr;		
	var current=mon+"/"+ dt+"/"+year;			

	if(origin == null || origin == ''){
		alert('Origin country is required.');
		return false;
	}
	if(destination == null || destination == ''){
		alert('Destination country is required.');
		return false;
	}
	if(equipType == null || equipType == ''){
		alert('Equipment type is required.');
		return false;
	}
	if(dateInput == null || dateInput == ''){
		alert('Date is required.');
		return false;
	}
	
	
	//********code to check dates ahead of 1 month*********
	
	if(dateentyear>year && dateentmon>1){
		alert('Date must not be later than 1 month or earlier than 6 months from current month');
		return false;
	}
	
	if(dateentyear==year && dateentmon>currmon){   
		alert('Date must not be later than 1 month or earlier than 6 months from current month');
			return false;
	}
			
	//********code to check backdated date in the same year*********
		
	if(dateentyear==year && mon-dateentmon>=5){
	alert('Date must not be later than 1 month or earlier than 6 months from current month');
	return false;
	}
	
	//********code to check backdated date in the previous year*********
	
	if(year-dateentyear>1){
	alert('Date must not be later than 1 month or earlier than 6 months from current month');
		return false;
	}
	
	if(dateentyear<year && (dateentmon > 1 && dateentmon < 6)){		
	alert('Date must not be later than 1 month or earlier than 6 months from current month');
	return false;
	}
	
	//********code to check backdated date of 7-12 months in the previous year*********
		
	if(dateentyear<year && mon==0 && dateentmon<7){
	alert('Date must not be later than 1 month or earlier than 6 months from current month');
	return false;
	}
	
	if(dateentyear<year && mon==1 && dateentmon<8){
	alert('Date must not be later than 1 month or earlier than 6 months from current month');
	return false;
	}
	
	if(dateentyear<year && mon==2 && dateentmon<9){
	alert('Date must not be later than 1 month or earlier than 6 months from current month');
	return false;
	}
	
	if(dateentyear<year && mon==3 && dateentmon<10){
	alert('Date must not be later than 1 month or earlier than 6 months from current month');
	return false;
	}
	
	if(dateentyear<year && mon==4 && dateentmon<11){
	alert('Date must not be later than 1 month or earlier than 6 months from current month');
	return false;
	}
	
	if(dateentyear<year && mon==5 && dateentmon<12){
	alert('Date must not be later than 1 month or earlier than 6 months from current month');
	return false;
	}
	
	if(origin == destination){
		alert('Origin and Destination should not be same.');
		return false;
	}
	return true;
}

// Function to populate the origin dropdown

function checkSelectedOrigin(){
var selectedOrigValue = document.searchForm.origin.value;
var origCountries = new Array("AFGHANISTAN","ARGENTINA","AUSTRALIA","AUSTRIA","AZERBAIJAN","BAHRAIN","BANGLADESH","BELARUS","BELGIUM",
			      "BOSNIA","BOSNIA-HERZEGOVINA","BRAZIL (EXCEPT MANAUS & VILLA DE CONDE)","BRAZIL (MANAUS & VILLA DE CONDE)",
			      "BRUNEI","BULGARIA","CAMBODIA","CANADA (VIA MONTREAL)","CANADA (VIA US EAST COAST)","CANADA (VIA WEST COAST)","CHILE",
			      "CHINA","COLOMBIA (VIA EAST COAST)","COLOMBIA (VIA WEST COAST)","COSTA RICA","CROATIA","CYPRUS","CZECH REPUBLIC","DENMARK","DJIBOUTI","DOMINICAN REPUBLIC",
			      "EAST TIMOR","ECUADOR","EGYPT (EXCEPT SOKHNA)","EGYPT (SOKHNA ONLY)","EL SALVADOR",
			      "ESTONIA","FINLAND","FRANCE (VIA FOS SUR MER)","FRANCE (VIA LE HAVRE)","GEORGIA","GERMANY, FEDERAL REPUBLIC OF",
			      "GREECE","GUAM","GUATEMALA","HONDURAS","HONG KONG","HUNGARY","ICELAND","INDIA","INDONESIA","IRAN","IRAQ","IRELAND (BELFAST ONLY)","IRELAND (EXCEPT BELFAST)",
			      "ISRAEL","ITALY","JAPAN","JORDAN (EXCEPT VIA HAIFA)","JORDAN (VIA HAIFA)","KAZAKHSTAN","KENYA","KOREA, REPUBLIC OF",
			      "KUWAIT","KYRGYZSTAN","LATVIA","LEBANON","LITHUANIA","MACAU","MALAYSIA","MALDIVES","MALTA","MAURITIUS",
			      "MEXICO","MOROCCO","MYANMAR","NETHERLANDS","NICARAGUA","NORTH CHINA","NORTHERN IRELAND","NORWAY","OMAN",
			      "PAKISTAN","PALAU","PANAMA","PERU","PHILIPPINES","POLAND","PORTUGAL","PUERTO RICO","QATAR","ROMANIA",
			      "RUSSIA (VIA FAR EAST)","RUSSIA (VIA NOVORISSIYSK)","RUSSIA (VIA ST. PETERSBURG)","SAUDI ARABIA (EXCEPT JEDDAH)","SAUDI ARABIA (JEDDAH ONLY)","SERBIA AND MONTENEGRO","SINGAPORE","SLOVAKIA",
			      "SLOVENIA","SOMALIA","SOUTH CHINA","SPAIN (VIA ALGICERAS)","SPAIN (VIA BARCELONA, VALENCIA, MALAGA)",
			      "SPAIN (VIA BILBAO, VIGO, GIJON)","SRI LANKA","SUDAN","SWEDEN","SWITZERLAND","TAIWAN","TAJIKISTAN",
			      "TANZANIA, UNITED REPUBLIC OF","THAILAND","TURKEY","UKRAINE","UNITED ARAB EMIRATES","UNITED KINGDOM",
			      "UNITED STATES (ALASKA)","UNITED STATES (VIA EAST COAST)","UNITED STATES (VIA GULF COAST)","UNITED STATES (VIA MONTREAL)",
			      "UNITED STATES (VIA WEST COAST)","URUGUAY","UZBEKISTAN","VENEZUELA","VIETNAM","VIRGIN ISLANDS","YEMEN");

document.write('<select name="Origin" style="width:344px" >');
document.write('<option selected value=""> Select Origin');
for(i=0; i<origCountries.length;i++){

if(origCountries[i] == selectedOrigValue){

document.writeln('<option value="'+origCountries[i]+'" selected= "selected">'  + origCountries[i] + '</option>');
}else{

document.writeln('<option value="'+origCountries[i]+'">'  + origCountries[i] + '</option>');
}
}
document.write("</select>");
}

// Function to populate the destination dropdown

function checkSelectedDestination(){

var selectedDestValue = document.searchForm.dest.value;

var destCountries = new Array("AFGHANISTAN","ARGENTINA","AUSTRALIA","AUSTRIA","AZERBAIJAN","BAHRAIN","BANGLADESH","BELARUS","BELGIUM",
			      "BOSNIA","BOSNIA-HERZEGOVINA","BRAZIL (EXCEPT MANAUS & VILLA DE CONDE)","BRAZIL (MANAUS & VILLA DE CONDE)",
			      "BRUNEI","BULGARIA","CAMBODIA","CANADA (VIA MONTREAL)","CANADA (VIA US EAST COAST)","CANADA (VIA WEST COAST)","CHILE",
			      "CHINA","COLOMBIA (VIA EAST COAST)","COLOMBIA (VIA WEST COAST)","COSTA RICA","CROATIA","CYPRUS","CZECH REPUBLIC","DENMARK","DJIBOUTI","DOMINICAN REPUBLIC",
			      "EAST TIMOR","ECUADOR","EGYPT (EXCEPT SOKHNA)","EGYPT (SOKHNA ONLY)","EL SALVADOR",
			      "ESTONIA","FINLAND","FRANCE (VIA FOS SUR MER)","FRANCE (VIA LE HAVRE)","GEORGIA","GERMANY, FEDERAL REPUBLIC OF",
			      "GREECE","GUAM","GUATEMALA","HONDURAS","HONG KONG","HUNGARY","ICELAND","INDIA","INDONESIA","IRAN","IRAQ","IRELAND (BELFAST ONLY)","IRELAND (EXCEPT BELFAST)",
			      "ISRAEL","ITALY","JAPAN","JORDAN (EXCEPT VIA HAIFA)","JORDAN (VIA HAIFA)","KAZAKHSTAN","KENYA","KOREA, REPUBLIC OF",
			      "KUWAIT","KYRGYZSTAN","LATVIA","LEBANON","LITHUANIA","MACAU","MALAYSIA","MALDIVES","MALTA","MAURITIUS",
			      "MEXICO","MOROCCO","MYANMAR","NETHERLANDS","NICARAGUA","NORTH CHINA","NORTHERN IRELAND","NORWAY","OMAN",
			      "PAKISTAN","PALAU","PANAMA","PERU","PHILIPPINES","POLAND","PORTUGAL","PUERTO RICO","QATAR","ROMANIA",
			      "RUSSIA (VIA FAR EAST)","RUSSIA (VIA NOVORISSIYSK)","RUSSIA (VIA ST. PETERSBURG)","SAUDI ARABIA (EXCEPT JEDDAH)","SAUDI ARABIA (JEDDAH ONLY)","SERBIA AND MONTENEGRO","SINGAPORE","SLOVAKIA",
			      "SLOVENIA","SOMALIA","SOUTH CHINA","SPAIN (VIA ALGICERAS)","SPAIN (VIA BARCELONA, VALENCIA, MALAGA)",
			      "SPAIN (VIA BILBAO, VIGO, GIJON)","SRI LANKA","SUDAN","SWEDEN","SWITZERLAND","TAIWAN","TAJIKISTAN",
			      "TANZANIA, UNITED REPUBLIC OF","THAILAND","TURKEY","UKRAINE","UNITED ARAB EMIRATES","UNITED KINGDOM",
			      "UNITED STATES (ALASKA)","UNITED STATES (VIA EAST COAST)","UNITED STATES (VIA GULF COAST)","UNITED STATES (VIA MONTREAL)",
			      "UNITED STATES (VIA WEST COAST)","URUGUAY","UZBEKISTAN","VENEZUELA","VIETNAM","VIRGIN ISLANDS","YEMEN");

document.write('<select name="Destination" style="width:344px" >');
document.write('<option selected value=""> Select Destination');
for(i=0; i<destCountries.length;i++){

if(destCountries[i] == selectedDestValue){

document.writeln('<option value="'+destCountries[i]+'" selected= "selected">'  + destCountries[i] + '</option>');
}else{

document.writeln('<option value="'+destCountries[i]+'">'  + destCountries[i] + '</option>');
}
}
document.write("</select>");
}

// New Function 



//function redirect () { 
//alert "Hi";
//go_now();
//alert "Hi2";
//}

function go_now ()   { 
alert ('Hi111');
//window.location.href = "/cgi-bin/pricing/download.cgi?file=date.txt";
window.open("download.cgi?file=date.txt");

}


// Function to populate the equipment type dropdown

function checkSelectedEqtType(){

var selectedequip = document.searchForm.eqptype.value;

var eqtType = new Array("DRY","REEFER");

document.write('<select name="EquipmentType" style="width:344px" >');
document.write('<option selected value=""> Select Equipment Type');
for(i=0; i<eqtType.length;i++){

if(eqtType[i] == selectedequip){

document.writeln('<option value="'+eqtType[i]+'" selected= "selected">'  + eqtType[i] + '</option>');
}else{

document.writeln('<option value="'+eqtType[i]+'">'  + eqtType[i] + '</option>');
}
}
document.write("</select>");

}

// Function for clear button functionality

function clearFilelds(){

document.searchForm.Origin.value = "";
document.searchForm.Destination.value = "";
document.searchForm.EquipmentType.value = "";
document.searchForm.date.value = "";
document.searchForm.action = "surcharge.cgi";
document.searchForm.submit();

}