﻿// JScript File
var CertificateRequired = false;
var ISFRequired = false;
var isISFValid = false;
var LoadFromTemplate = false;
var dialogParams = new Object();
var RequiredFieldsId = new Array('CreatedBy','EimskipOffice','EmailAddress','ShipperName','ConsignerName','ShipperAddress','ConsignerAddress','ShipperZIPCode','ShipperCity','ConsignerCity','ShipperCountry','ConsignerCountry','ConsignerZIPCode','ShipperEmail','ConsignerEmail','ShipperPhone','ConsignerPhone','marks0','description0','kgs0','cbm0','Incoterms','Incoterms');

function TakeOutBackground() {
    //var event = e || window.event;
    var target = event.target || event.srcElement;
    //alert(target.id);
    var obj = document.getElementById(target.id);
    if (obj.value.length > 0) {
        obj.style.backgroundColor = '#ffffff';
    }
}

function ValidateCargoTemperature() {
    var TemperatureControled = document.getElementById('TemperatureControlledCargo');
    var CargoTemperature = document.getElementById('CargoTemperature');
    var Validator = document.getElementById('CargoTemperatureValidator');
    
    if (TemperatureControled.checked && CargoTemperature.value == "") {
        Validator.style.visibility = 'visible';
        return false;
    } else {
        return true;
    }
}

function validateRequiredFields() {
    var isValid = false;
    var missedFields = 0;
    for (var i=0; i<RequiredFieldsId.length; i++) {
        var obj = document.getElementById(RequiredFieldsId[i]);
        //alert(RequiredFieldsId[i]+":"+obj);
        //obj.style.backgroundColor = 'red';
        if (obj.value.length == 0) {
            obj.style.backgroundColor = 'rgb(255,170,170)';    
            obj.attachEvent("onblur", TakeOutBackground);
            missedFields++;
        } else {
            obj.style.backgroundColor = 'white';
        }
    }
    
    /*
    if (ISFRequired) {
        alert('Please fill out Importer Security Filling');
        isValid = false;
        return isValid;
    }
    */
    
    if (missedFields > 0) {
        alert('Pleas fill out all required fields (*)');
        
        isValid = false;
        return isValid;
    }
    
    return isValid;
}

function createPopup(src, target, width, height, params) {
	var target = target || "PopupWindow";
	dialogParams = params;
	var top = (screen.height-height)/2;
	var left = (screen.width-width)/2;
	popupWindow = window.open(src, target, "toolbar=no. location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyright=no, top="+top+", left="+left+", width="+width+", height="+height+"");
	popupWindow.focus();
	
	return popupWindow;
}

var Offices = new Array();
Offices[1] = "EIMSKIP Korngörðum 2 | 104 Reykjavík | Viðskiptaþjónusta sími 525 7800 | Höfuðstöðvar sími 525 7000 | Fax 525 7009";
Offices[2] = "EIMSKIP Korngörðum 2 | 104 Reykjavík | Viðskiptaþjónusta sími 525 7800 | Höfuðstöðvar sími 525 7000 | Fax 525 7009";
Offices[3] = "Eimskip Transport BV | Bijdorpplein 13-19 | 2992 LB Barendrecht | The Netherlands | Phone: +31(0)180 644144";
Offices[4] = "Eimskip-Faroe Ship Denmark | Østhavnsvej 37 A, | Containerterminal Øst | 8000 Aarhus C | Denmark | Phone: + 45 7020 1602";
Offices[5] = "Eimskip Deutschland Brandsende 6 D 20095 Hamburg Germany Phone: +49 40 32 33 30 0 Website: www.eimskip.de";
Offices[6] = "EIMSKIP UK Ltd. | Middleplatt Road | Immingham, NE Lincolnshire DN40 1AH | United Kingdom | Phone: + 44 1469 550 200";
Offices[7] = "EIMSKIP Sortland | P.O.Box 13 | N-8401 Sortland | Phone +47 76 11 15 50 | Fax +47 76 11 15 90";
Offices[8] = "EIMSKIP Fredrikstad | P.O.Box 904 | N-1670 Kråkerøy | Phone 69382830 | Fax 69382849";
Offices[9] = "Hf Eimskipafelag islands | P.O Box 7055 | SE-250 07 Helsingborg | Phone + 46 42 175580 | Fax + 46 42 175597";
Offices[10] = "EIMSKIP Canada Inc. | 33 Pippy Place, Suite 305 | St. John´s NL A1B 3X2 | Tel: +1 709 754 7227 | Fax: +1 709 754 7999";
Offices[11] = "Eimskip USA Inc. | One Columbus Center | Suite 500 | Virginia Beach, VA 23462-6784 | Tel: +1 757 627 4444 | Fax: +1 757 627 9367";

var HelpTexts = new Array();
HelpTexts['cd'] = "When Eimskip collects cargo to customer and the address " +
              "where the cargo should be collected at is NOT the same "+
              "as the Shipper´s address above, please register the "+
               " relevant collection Address, City and Country.";
               
HelpTexts['mn'] = "It is important to register Marks and numbers for the cargo being transported."+
"<br>&nbsp;1) For Containers please register:"+
"<br>&nbsp;a) Container number"+
"<br>&nbsp;b) Seal number"+
"<br>For loose cargo and cargo on pallets (LCL cargo) please register the real markings and labels on the unit(s). "+
"<br>If you have many units containing various cargo types and packaging then please identify the cargo in below fields."+
"<br>If you are transporting NEW cars/vehicles please register "+
"	<br>&nbsp;a) Chassi number "+
"	<br>&nbsp;b) Case number for new vehicles"+
"If you are transporting second hand / personal  cars/vehicles please register "+
"	<br>&nbsp;a) Chassi number "+
"	<br>&nbsp;b) Registration number (if the vehicle has registration number)";

HelpTexts['description'] = "Please register:"+
"   <br>&nbsp;1)  Precise and clear description of the cargo being transported."+
"   <br>&nbsp;2)  Type of packaging e.g.: Pallet, piece box, crate etc."+
"   <br>&nbsp;3)  Number of units<br>"+
"If you have many units containing various cargo types and packaging then please identify the cargo in  below fields."+
"	<br>&nbsp;4) If cargo has to be transported as temperature controlled cargo please identify for each line below:"+
"	<br>&nbsp;a) The specific temperature in °C "+
"	<br>&nbsp;b) Ventilation <br>"+
"Please note that some commodity types do normally not need temperature controlled transport but due to weather conditions 1) high heat during sommer time, 2) low heat during winter time you may have to request temperature controlled transport to secure that your cargo will not be damaged during transport. Please not examples below of cargo types that are heat sensitive."+
"	<br>&nbsp;a) Oil for cooking"+
"	<br>&nbsp;b) Various Chocolate types"+
"	<br>&nbsp;c) Various drinks and  food stuffs in glass packaging:  Wine, Beer, Soft drinks/soda"+
"	<br>&nbsp;d) Oil for cooking"+
"	<br>&nbsp;e) Paint"+
"	<br>&nbsp;f ) Various glue types";


HelpTexts['special'] = "Please register clear instructions for special handling of cargo during transport e.g.:"+
"<br>When shipping Dangerous cargo/Hazardus cargo please register the folowing details:"+
	"<br>&nbsp;a) Proper shipping name"+
	"<br>&nbsp;b) Hazardus class"+
	"<br>&nbsp;c) UN number"+
"<br>Please note that Shipper is required to deliver Dangerous Cargo Certificate with the cargo, "+
"<br>if the certificate is not handed in with cargo, transport can not be operated."+
"<br>When shipping Oversized cargo please register the following details:"+
"<br>1) Overheight"+
"<br>2) Overwidth "+
           "<br>&nbsp; a) left"+
           "<br>&nbsp; b) right"+
"<br>3) Overlength"+
            "a) front"+
            "b) aft"+
"<br>If you have special requirements for "+
"<br>1) securing of cargo"+
"<br>2) loading of cargo "+
"<br>please identify your requirements clearly."+
"<br>If cargo has to be transported in an open container units e.g. Open top container "+
"<br>or Flat rack, but cargo needs to be handled with extra care due to being sensitive "+
"<br>to weather conditions e.g. temperature, rain or snow and therefore has to be stored inside.  "+
"<br>Please make sure to inform clearly your requirements for secial handling of cargo during "+
"<br>the whole transport process of cargo to avoid cargo damage. Please make sure at "+
"<br>all times to pack/cover, secure and load or request from Eimskip relevant packing/covering,"+ 
"<br>securing and loading of sensitive cargo which needs special handling.";

HelpTexts['kg'] = "Please register Gross weigh in kilograms for the cargo/container being transported.  "+
                  "Gross weight is the total weight being transported: 'Cargo + packaging + pallet(s)."+
                  "The same correct Gross weight  should also be registered on the Cargo invoice."+
                  "If Gross weight is not used it can cause delay in the transport process due to corrections "+
                  "that have to made when clearing cargo at Customs Authorities. Weight information "+
                  "have to be the same on the Sea waybill/Bill of lading as on the Cargo invoice, otherwise "+
                  "Customs Authorities will NOT accept clearance of cargo.";
var ItemsIndex = 0;
function AddItem() {
    var JunctionsIndex =  document.getElementById("JunctionsIndex"); 
    ItemsIndex++;
    JunctionsIndex.value = ItemsIndex;   
    var tableElement = document.getElementById('JunctionsList');
    var rowCount = tableElement.rows.length;
    var tableRow = tableElement.insertRow(rowCount-1);
    
    var cell = tableRow.insertCell(0);
    cell.width = "94";
    cell.style.borderRight = '1px dotted #808080';
    cell.style.paddingTop = '0px';
    cell.style.paddingLeft = '2px';
    cell.style.paddingRight = '2px';
    cell.style.paddingBottom = '0px';
    
    var TextBox = document.createElement("input");
    TextBox.className = 'j_marks';
    TextBox.type = 'text';
    TextBox.name = "marks"+ItemsIndex;
    //TextBox.value = ItemsIndex;
    cell.appendChild(TextBox);
    var cell = tableRow.insertCell(1);
    cell.width = "418";
    cell.style.borderRight = '1px dotted #808080';
    cell.style.paddingTop = '0px';
    cell.style.paddingLeft = '2px';
    cell.style.paddingRight = '2px';
    cell.style.paddingBottom = '0px';
    var TextBox = document.createElement("input");
    TextBox.className = 'j_description';
    TextBox.type = 'text';
    TextBox.name = "description"+ItemsIndex;
    //TextBox.value = ItemsIndex;
    cell.appendChild(TextBox);
    var cell = tableRow.insertCell(2);
    cell.width = "90";
    cell.style.borderRight = '1px dotted #808080';
    cell.style.paddingTop = '0px';
    cell.style.paddingLeft = '2px';
    cell.style.paddingRight = '2px';
    cell.style.paddingBottom = '0px';
    var TextBox = document.createElement("input");
    TextBox.className = 'j_kgs';
    TextBox.type = 'text';
    TextBox.name = "kgs"+ItemsIndex;
    //TextBox.value = ItemsIndex;
    cell.appendChild(TextBox);
    var cell = tableRow.insertCell(3);
    cell.width = "90";
    cell.style.paddingTop = '0px';
    cell.style.paddingLeft = '2px';
    cell.style.paddingRight = '2px';
    cell.style.paddingBottom = '0px';
    var TextBox = document.createElement("input");
    TextBox.className = 'j_cbm';
    TextBox.type = 'text';
    TextBox.name = "cbm"+ItemsIndex;
    //TextBox.value = ItemsIndex;
	TextBox.title = ItemsIndex;
    cell.appendChild(TextBox);
    var cell = tableRow.insertCell(4);
    cell.width = "28";
    cell.innerHTML = '<a href="javascript:void(0);" onclick="RemoveItem(this.parentNode.parentNode.rowIndex);" title="Remove this row"><img src="images/application_form_delete.png" border="0" alt="0" title="Remove this row" /></a>';
}

function RemoveItem(rowIndex) {
    if (rowIndex == 1) {
        alert("You can\'t to remove all items.");
    } else {
        var tableElement = document.getElementById('JunctionsList');
        var rowCount = tableElement.rows.length;
        tableElement.deleteRow(rowIndex);
    }
}

function OfficeContacts(obj) {
    var label = document.getElementById("office_contacts");
    if (obj != null && obj.value != "") {
        var text = Offices[obj.selectedIndex];
    } else {
        var text = Offices[1];
    }
    label.innerHTML = text;
}

function OpenTemplateUploadDialog() {
    createPopup("TemplateUpload.aspx", "TeplateUpload", 320, 200, null);
}

function OpenSuccessDialog() {
    createPopup("Thankyou.htm", "Thankyou", 250, 150, null);
}

function CreateSuccessDialog(w, h) {
    var width = w;
    var height = h;
    var top = (screen.height-height)/2;
	var left = (screen.width-width)/2;
    document.getElementById("SuccessDialog").style.top = top+"px";
    document.getElementById("SuccessDialog").style.left = left+"px";
}

function ValidateSI() {
    if (ValidateISF() && ValidateCertifate()) {
        return true;
    } else {
        return false;
    }
}

function ValidateISF() {
    if (ISFRequired) {
        alert('Please fill out Importer Security Filling');
        OpenISFWindow();
        return false;
    } else {
        return true;
    }
}

function ValidateCertifate() {
    if (CertificateRequired) {
        alert('Please fill out Catch Sertificate form');
        OpenCertificateWindow();
        return false;
    } else {
        return true;
    }
}

function CheckISFCountry(obj, openDialog) {
    if (obj.value == "United States") {
        ISFRequired = true;
        document.getElementById("isfLink").style.display = "block";
        if (openDialog) {
            OpenISFWindow();
        }
    } else {
        ISFRequired = false;
        document.getElementById("isfLink").style.display = "none";
    }
    document.getElementById("txtISFRequired").value = ISFRequired;
}

function OpenISFWindow() {
    createPopup("isf.aspx", "ISF", 810, 750, null);
}

function CheckShipperCountry(obj, openDialog) {
    //alert(obj.value);
    if (obj.value == "Iceland" || obj.value == "Faroe Islands" ||obj.value == "Norway" || obj.value == "Canada" || obj.value == "United States") {
        CertificateRequired = true;
        var link = document.getElementById("certificateLink");
        //alert(link);
        link.style.display = "block";
        if (openDialog) {
            OpenCertificateWindow();
        }
    } else {
        CertificateRequired = false;
        document.getElementById("certificateLink").style.display = "none";
    }
    document.getElementById("txtCertificateRequired").value = CertificateRequired;
}

function OpenCertificateWindow() {
    createPopup("certificate.aspx","Certificate",520,380, null);
}
