// JavaScript Document
function UpdateAll() {

// Set prices

// General Document

// English > Albanian
var enToalGeneral = 0.06;
// Albanian > English
var alToenGeneral = 0.065;
// Italian > Albanian
var itToalGeneral = 0.06;
// Albanian > Italian
var alToitGeneral = 0.065;
// Italian > English
var itToenGeneral = 0.07;
// English > Italian
var enToitGeneral = 0.075;

// Journalistic Document

// English > Albanian
var enToalJournalistic = 0.06;
// Albanian > English
var alToenJournalistic = 0.065;
// Italian > Albanian
var itToalJournalistic = 0.06;
// Albanian > Italian
var alToitJournalistic = 0.065;
// Italian > English
var itToenJournalistic = 0.07;
// English > Italian
var enToitJournalistic = 0.075;

// Literary Document

// English > Albanian
var enToalLiterary = 0.06;
// Albanian > English
var alToenLiterary = 0.065;
// Italian > Albanian
var itToalLiterary = 0.06;
// Albanian > Italian
var alToitLiterary = 0.065;
// Italian > English
var itToenLiterary = 0.07;
// English > Italian
var enToitLiterary = 0.075;

// Legal Document

// English > Albanian
var enToalLegal = 0.065;
// Albanian > English
var alToenLegal = 0.065;
// Italian > Albanian
var itToalLegal = 0.065;
// Albanian > Italian
var alToitLegal = 0.065;
// Italian > English
var itToenLegal = 0.075;
// English > Italian
var enToitLegal = 0.075;

// Religious Document

// English > Albanian
var enToalReligious = 0.065;
// Albanian > English
var alToenReligious = 0.065;
// Italian > Albanian
var itToalReligious = 0.065;
// Albanian > Italian
var alToitReligious = 0.065;
// Italian > English
var itToenReligious = 0.07;
// English > Italian
var enToitReligious = 0.07;

// Philosophic Document

// English > Albanian
var enToalPhilosophic = 0.065;
// Albanian > English
var alToenPhilosophic = 0.065;
// Italian > Albanian
var itToalPhilosophic = 0.065;
// Albanian > Italian
var alToitPhilosophic = 0.065;
// Italian > English
var itToenPhilosophic = 0.075;
// English > Italian
var enToitPhilosophic = 0.075;

// Economic Document

// English > Albanian
var enToalEconomic = 0.065;
// Albanian > English
var alToenEconomic = 0.065;
// Italian > Albanian
var itToalEconomic = 0.065;
// Albanian > Italian
var alToitEconomic = 0.065;
// Italian > English
var itToenEconomic = 0.075;
// English > Italian
var enToitEconomic = 0.075;

// Advertisement Document

// English > Albanian
var enToalAdvertisement = 0.065;
// Albanian > English
var alToenAdvertisement = 0.065;
// Italian > Albanian
var itToalAdvertisement = 0.065;
// Albanian > Italian
var alToitAdvertisement = 0.065;
// Italian > English
var itToenAdvertisement = 0.075;
// English > Italian
var enToitAdvertisement = 0.075;

// Scientific Document

// English > Albanian
var enToalScientific = 0.07;
// Albanian > English
var alToenScientific = 0.07;
// Italian > Albanian
var itToalScientific = 0.07;
// Albanian > Italian
var alToitScientific = 0.07;
// Italian > English
var itToenScientific = 0.075;
// English > Italian
var enToitScientific = 0.075;

// Technical Document

// English > Albanian
var enToalTechnical = 0.07;
// Albanian > English
var alToenTechnical = 0.07;
// Italian > Albanian
var itToalTechnical = 0.07;
// Albanian > Italian
var alToitTechnical = 0.07;
// Italian > English
var itToenTechnical = 0.075;
// English > Italian
var enToitTechnical = 0.075;

// Traslation and Proofreading surcharge in percentage
var transAndProofSurcharge = 30;

// One Day Sooner surcharge in percentage
var oneDaySoonerSurcharge = 20;

// Sunday/Holiday Service surcharge in percentage
var sundayHolidaySurcharge = 30;

// 24 hour weekday rush service surcharge in percentage
var weekRushSurcharge = 40;

// Saturday 24 hour rush service surcharge in percentage
var saturdayRushSurcharge = 50;

// Sunday/Holiday 24 hour rush service surcharge in percentage
var sundayHolidayRushSurcharge = 60;

// Number of words
var sourceLang = document.getElementById("SourceDDL").value;
// Number of pages
var tagertLang = document.getElementById("TargetDDL").value;

// Number of words
var numPages = document.getElementById("PagesTextBox").value;
// Number of pages
var numWords = document.getElementById("WordsTextBox").value;

if(numWords > 2000) {
	if(document.getElementById("Sooner_5_RB").checked == true || document.getElementById("Sooner_6_RB").checked == true || document.getElementById("Sooner_7_RB").checked == true) {
		document.getElementById("Sooner_0_RB").checked = true;
	}
	document.getElementById("Sooner_5_RB").disabled = true;
	document.getElementById("Sooner_6_RB").disabled = true;
	document.getElementById("Sooner_7_RB").disabled = true;
}else{
	document.getElementById("Sooner_5_RB").disabled = false;
	document.getElementById("Sooner_6_RB").disabled = false;
	document.getElementById("Sooner_7_RB").disabled = false;
}

// Document Type
var docType = document.getElementById("SubjectDDL").value;

// Grand Total
var gtotal = 0;

if(sourceLang == tagertLang) {
	alert("Source and Target languages should be different");
	return false;
}

if(sourceLang == "Albanian" && tagertLang == "English") {
	if(docType == "General") {
		gtotal = alToenGeneral * numWords;	
	}else if(docType == "Journalistic"){
		gtotal = alToenJournalistic * numWords;
	}else if(docType == "Literary"){
		gtotal = alToenLiterary * numWords;
	}else if(docType == "Legal"){
		gtotal = alToenLegal * numWords;
	}else if(docType == "Religious"){
		gtotal = alToenReligious * numWords;
	}else if(docType == "Philosophic"){
		gtotal = alToenPhilosophic * numWords;
	}else if(docType == "Economic"){
		gtotal = alToenEconomic * numWords;
	}else if(docType == "Advertisement"){
		gtotal = alToenAdvertisement * numWords;
	}else if(docType == "Scientific"){
		gtotal = alToenScientific * numWords;
	}else if(docType == "Technical"){
		gtotal = alToenTechnical * numWords;
	}
}else if(sourceLang == "English" && tagertLang == "Albanian"){
	if(docType == "General") {
		gtotal = enToalGeneral * numWords;	
	}else if(docType == "Journalistic"){
		gtotal = enToalJournalistic * numWords;
	}else if(docType == "Literary"){
		gtotal = enToalLiterary * numWords;
	}else if(docType == "Legal"){
		gtotal = enToalLegal * numWords;
	}else if(docType == "Religious"){
		gtotal = enToalReligious * numWords;
	}else if(docType == "Philosophic"){
		gtotal = enToalPhilosophic * numWords;
	}else if(docType == "Economic"){
		gtotal = enToalEconomic * numWords;
	}else if(docType == "Advertisement"){
		gtotal = enToalAdvertisement * numWords;
	}else if(docType == "Scientific"){
		gtotal = enToalScientific * numWords;
	}else if(docType == "Technical"){
		gtotal = enToalTechnical * numWords;
	}
}else if(sourceLang == "Italian" && tagertLang == "Albanian"){
	if(docType == "General") {
		gtotal = itToalGeneral * numWords;	
	}else if(docType == "Journalistic"){
		gtotal = itToalJournalistic * numWords;
	}else if(docType == "Literary"){
		gtotal = itToalLiterary * numWords;
	}else if(docType == "Legal"){
		gtotal = itToalLegal * numWords;
	}else if(docType == "Religious"){
		gtotal = itToalReligious * numWords;
	}else if(docType == "Philosophic"){
		gtotal = itToalPhilosophic * numWords;
	}else if(docType == "Economic"){
		gtotal = itToalEconomic * numWords;
	}else if(docType == "Advertisement"){
		gtotal = itToalAdvertisement * numWords;
	}else if(docType == "Scientific"){
		gtotal = itToalScientific * numWords;
	}else if(docType == "Technical"){
		gtotal = itToalTechnical * numWords;
	}
}else if(sourceLang == "Albanian" && tagertLang == "Italian"){
	if(docType == "General") {
		gtotal = alToitGeneral * numWords;	
	}else if(docType == "Journalistic"){
		gtotal = alToitJournalistic * numWords;
	}else if(docType == "Literary"){
		gtotal = alToitLiterary * numWords;
	}else if(docType == "Legal"){
		gtotal = alToitLegal * numWords;
	}else if(docType == "Religious"){
		gtotal = alToitReligious * numWords;
	}else if(docType == "Philosophic"){
		gtotal = alToitPhilosophic * numWords;
	}else if(docType == "Economic"){
		gtotal = alToitEconomic * numWords;
	}else if(docType == "Advertisement"){
		gtotal = alToitAdvertisement * numWords;
	}else if(docType == "Scientific"){
		gtotal = alToitScientific * numWords;
	}else if(docType == "Technical"){
		gtotal = alToitTechnical * numWords;
	}
}else if(sourceLang == "Italian" && tagertLang == "English"){
	if(docType == "General") {
		gtotal = itToenGeneral * numWords;	
	}else if(docType == "Journalistic"){
		gtotal = itToenJournalistic * numWords;
	}else if(docType == "Literary"){
		gtotal = itToenLiterary * numWords;
	}else if(docType == "Legal"){
		gtotal = itToenLegal * numWords;
	}else if(docType == "Religious"){
		gtotal = itToenReligious * numWords;
	}else if(docType == "Philosophic"){
		gtotal = itToenPhilosophic * numWords;
	}else if(docType == "Economic"){
		gtotal = itToenEconomic * numWords;
	}else if(docType == "Advertisement"){
		gtotal = itToenAdvertisement * numWords;
	}else if(docType == "Scientific"){
		gtotal = itToenScientific * numWords;
	}else if(docType == "Technical"){
		gtotal = itToenTechnical * numWords;
	}
}else if(sourceLang == "English" && tagertLang == "Italian"){
	if(docType == "General") {
		gtotal = enToitGeneral * numWords;	
	}else if(docType == "Journalistic"){
		gtotal = enToitJournalistic * numWords;
	}else if(docType == "Literary"){
		gtotal = enToitLiterary * numWords;
	}else if(docType == "Legal"){
		gtotal = enToitLegal * numWords;
	}else if(docType == "Religious"){
		gtotal = enToitReligious * numWords;
	}else if(docType == "Philosophic"){
		gtotal = enToitPhilosophic * numWords;
	}else if(docType == "Economic"){
		gtotal = enToitEconomic * numWords;
	}else if(docType == "Advertisement"){
		gtotal = enToitAdvertisement * numWords;
	}else if(docType == "Scientific"){
		gtotal = enToitScientific * numWords;
	}else if(docType == "Technical"){
		gtotal = enToitTechnical * numWords;
	}
}


tempDays = numWords / 2000;
tempDays = Math.ceil(tempDays);

if(document.getElementById('Sooner_3_RB').checked){
	gtotal += (gtotal * 20) / 100;
	serviceType2 = "1 day sooner";
	daysToAdd = tempDays + 1;
	deliveryDate = addDays(daysToAdd);
}else if(document.getElementById('Sooner_4_RB').checked){
	gtotal += (gtotal * 30) / 100;
	serviceType2 = "Sunday/Holiday Service (in 3-5 working days)";
	daysToAdd = tempDays + 2;
	deliveryDate = addDays(daysToAdd);
}else if(document.getElementById('Sooner_5_RB').checked){
	gtotal += (gtotal * 40) / 100;
	serviceType2 = "24-Hour Weekday Rush Service";
	daysToAdd = tempDays;
	deliveryDate = addDays(daysToAdd);
}else if(document.getElementById('Sooner_6_RB').checked){
	gtotal += (gtotal * 50) / 100;
	serviceType2 = "Saturday 24-Hour Rush Service";
	daysToAdd = tempDays;
	deliveryDate = addDays(daysToAdd);
}else if(document.getElementById('Sooner_7_RB').checked){
	gtotal += (gtotal * 60) / 100;
	daysToAdd = tempDays;
	deliveryDate = addDays(daysToAdd);
	serviceType2 = "Sunday/Holiday 24-Hour Rush Service";
}else{
	gtotal = gtotal;
	serviceType2 = "Usual service, usual price";
	daysToAdd = tempDays + 2;
	deliveryDate = addDays(daysToAdd);
}

var tempGtotal = gtotal;
var tempGtotalWithSurcharge = (tempGtotal * 30) / 100;
tempGtotalWithSurcharge = tempGtotalWithSurcharge + tempGtotal;
if(document.getElementById('OPS_RB').checked){
	gtotal += (gtotal * 30) / 100;
	serviceType1 = "Translation and Proofreading";
}else{
	serviceType1 = "Translation only";
}

var pricePerPage = gtotal / numPages;
if(isFloat(pricePerPage)) {
	pricePerPage = pricePerPage.toFixed(2);
}
var pricePerWord = gtotal / numWords;
if(isFloat(pricePerWord)) {
	pricePerWord = pricePerWord.toFixed(2);
}


var todaysDate = addDays(0);

var tempPricePerPage = tempGtotal / numPages;
var tempPricePerWord = tempGtotal / numWords;
if(isFloat(tempPricePerPage)) {
	tempPricePerPage = tempPricePerPage.toFixed(2);
}
if(isFloat(tempPricePerWord)) {
	tempPricePerWord = tempPricePerWord.toFixed(2);
}

var tempPricePerPageWithSurcharge = tempGtotalWithSurcharge / numPages;
var tempPricePerWordWithSurcharge = tempGtotalWithSurcharge / numWords;
if(isFloat(tempPricePerPageWithSurcharge)) {
	tempPricePerPageWithSurcharge = tempPricePerPageWithSurcharge.toFixed(2);
}
if(isFloat(tempPricePerWordWithSurcharge)) {
	tempPricePerWordWithSurcharge = tempPricePerWordWithSurcharge.toFixed(2);
}

if(isFloat(gtotal)) {
	gtotal = gtotal.toFixed(2);
}

document.getElementById('tempPerPageWords').innerHTML = "&euro;" + tempPricePerPage + " Per Page (Approximately &euro;" +tempPricePerWord+ " Per Word)";
document.getElementById('tempPerPageWordsWithSurcharge').innerHTML = "&euro;" + tempPricePerPageWithSurcharge + " Per Page (Approximately &euro;" +tempPricePerWordWithSurcharge+ " Per Word)";
document.getElementById('TotalPriceSpan_2').innerHTML = "&euro;" + gtotal;
document.getElementById('VolumeSpan_2').innerHTML = numPages + " Page(s) (Roughly " +numWords+ " Words)";
document.getElementById('TotalPricePerPageWordSpan_2').innerHTML = "&euro;" + pricePerPage + " Per Page (Roughly &euro;" +pricePerWord+ " Per Word)";
document.getElementById('TodayDateSpan_2').innerHTML = todaysDate;
document.getElementById('TypeOfServiceSpan_2').innerHTML = serviceType1 +"<br>"+ serviceType2;
document.getElementById('DeliveryDateSpan_2').innerHTML = deliveryDate;
document.getElementById('total').value = gtotal;
return false;
}

function isFloat(num) {
	if ( !isNaN(num) ) {
		if ( /\.0+$/.test(num) ) {
			return true;
		}
		else {
			return parseInt(num) != parseFloat(num) ? true : false;
		}
	}
	else {
		return false;
	}
}
	
function UpdateWordsPages(field) {
	
	// Number of words per page
	var numWordsPerPage = 300;
	
	var fieldValue = document.getElementById(field).value;
	
	
	
	if(isNaN(fieldValue) || fieldValue == "") {
	document.getElementById('PagesWordsErrorSpan').innerHTML = "Invalid number of pages or words.<br>Please correct to get valid results.";
}else{
	document.getElementById('PagesWordsErrorSpan').innerHTML = "";
		if(field == "PagesTextBox") {
				var words = fieldValue * numWordsPerPage;
				if(isFloat(words)) {
					words = words.toFixed(2);
				}
				document.getElementById("WordsTextBox").value = words;
			}else{
				var pages = fieldValue / numWordsPerPage;
				if(isFloat(pages)) {
					pages = pages.toFixed(2);
				}
				document.getElementById("PagesTextBox").value = pages;
			}
	}
}

function addDays(days) {
DaysToAdd=days;

var now=new Date();
var newdate=new Date();
var newtimems=newdate.getTime()+(DaysToAdd*24*60*60*1000);
newdate.setTime(newtimems);
var dateString=newdate.toLocaleString();
return dateString;
}

function checkForm(){
	if(document.getElementById("AgreementCB").checked == false) {
			alert("You need to agree with terms and conditions to place order.");
			return false;
		}else{
			document.getElementById("orfForm").action = "https://www.2checkout.com/checkout/purchase";
			document.getElementById("orfForm").submit();
			return true
			}
}