// JavaScript Document
// Global Variables

// Initializing: store data in arrays
// 1. Country Data:
// naming will not have plurals
var iTotalPrice=0;
var iBasicCost= 3;
var arrsubject = new Array ("Arts", "Accounting", "Business", "Chemistry", "Computer Science", "Education", "English", "Economics", "Finance", "Human Resources", "Information Technology", "Law", "Literature", "Management", "Marketing", "Movie Review", "Math", "Medicine",  "Nursing", "philosophy", "Physics", "Political Science", "Psychology", "Science", "Sociology", "Social Work", "Statistics", "Tourism");
var arrsubjectPrice = new Array (3, 10, 3, 5, 5, 2, 5, 3, 7, 3, 3, 2, 3, 3, 5, 5, 4, 2, 5, 3, 3, 5, 2, 2, 5, 2);
var arrDeadline = new Array ("60 Days", "30 Days", "21 Days", "14 Days", "10 Days", "7 Days", "5 Days", "3 Days", "2 Days",  "24 Hours");
var arrDeadlinePrice = new Array (5,6,7,8,9, 11,13,16,18,22);
var arrAcademicLevel = new Array ("High School", "Undergraduate", "Graduate", "Post Graduate");
var arrAcademicLevelPrice = new Array (1,3,6,9,12);
var arrGrade = new Array ("A+", "A", "B+", "B", "C");
var arrGradePrice = new Array (10,8,6,4,3);
var arrNumberofPages = new Array ("1 Page - 250 words", "2 Pages - 500 words", "3 Pages - 750 words", "4 Pages - 1000 words", "5 Page - 1250 words", "6 Pages - 1500 words", "7 Pages - 1750 words", "8 Pages - 2000 words", "9 Page - 2250 words", "10 Pages - 2500 words", "11 Pages - 2750 words", "12 Pages - 3000 words", "13 Page - 3250 words", "14 Pages - 3500 words", "15 Pages - 3750 words", "20 Pages - 5000 words", "25 Page - 6250 words", "30 Pages - 7500 words", "35 Pages - 8750 words", "40 Pages - 10000 words", "50 Pages - 12500 words", "60 Pages - 15000 words", "70 Pages - 17500 words", "80 Pages - 20000 words", "90 Pages - 22500 words", "100 Pages - 25000 words");
var arrNumberofPagesPrice = new Array (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 20, 25, 30, 35, 40, 50, 60, 70, 80, 90, 100);

var arrType = new Array ("Admission/Application Essay", "Annotated Bibliography", "Article Writing", "Article Critique", "Book Review", "Coursework", "Critical Writing", "Dissertation", "Editing/Proof Reading", "Essay", "Ghost Writing", "Online Testing", "PowerPoint Presentation", "Programming", "Quantitative Analysis", "Qualitative Analysis", "Report", "Research Paper", "Research Proposal", "Resume Writing", "Term Paper", "Thesis");
var arrStyle = new Array ("APA", "MLA", "Chicago", "Harvard", "Turabian"); 
var arrLanguage = new Array ("American English", "British English", "English as Foreign Language (EFL/ESL)");
var arrNumberofQuotes = new Array ("0", "1", "2", "3", "4", "5", "10", "15", "20", "30", "50", "70","100" );
var SwregStatement = "https://usd.swreg.org/cgi-bin/s.cgi?s=115803&p=115803-1&vp=";

function InitForm ()
{
	FillsubjectSelect();
    FillTypeSelect();
	FillAcademicLevelSelect();
	FillDeadlineSelect();
	FillGradeSelect();
//alert ("fillgrade");	
	FillStyleSelect();
	FillLanguageSelect();	
	FillNumberofPagesSelect();
	FillNumber_of_QuotesSelect();	
	InitDefaultValuesinSelects();
//  alert (" calculator2.js Init Form"); // for debugging purposes
	CalculatePrice();
}

function FillsubjectSelect()
{
//  alert (" Fill subject Select"); // for debugging purposes
    // Local Variables
    var arraycounter1;  
    
    var selsubject = document.getElementById("selsubject"); // Get country select Id
    if (selsubject.length > 0) return; // To ensure it is only run only once when form loads

    for (arraycounter1 in arrsubject)  // loop through countries array
    {
        var HOptNew = document.createElement('option'); // Create new option to be inserted
        HOptNew.text = arrsubject[arraycounter1];  // set text of option to be inserted
        HOptNew.value = arrsubject[arraycounter1]; // set value of option to be inserted
        try     { selsubject.add(HOptNew,null);} // standards compliant    
          catch(ex)    {    selsubject.add(HOptNew);} // IE only 
    }
//    arrCountries = arrCountries.slice (1); // remove the first element in array "All Countries"
//alert ("endfillsubject");
}

function FillTypeSelect()
{
//  alert (" Fill Type Select"); // for debugging purposes
    // Local Variables
    var arraycounter1;  
    
    var selType = document.getElementById("selType"); // Get country select Id
    if (selType.length > 0) return; // To ensure it is only run only once when form loads

    for (arraycounter1 in arrType)  // loop through countries array
    {
        var HOptNew = document.createElement('option'); // Create new option to be inserted
        HOptNew.text = arrType[arraycounter1];  // set text of option to be inserted
        HOptNew.value = arrType[arraycounter1]; // set value of option to be inserted
        try     { selType.add(HOptNew,null);} // standards compliant    
          catch(ex)    {    selType.add(HOptNew);} // IE only 
    }
//    arrCountries = arrCountries.slice (1); // remove the first element in array "All Countries"
}

function FillAcademicLevelSelect()
{
//  alert (" Fill AcademicLevel Select"); // for debugging purposes
    // Local Variables
    var arraycounter1;  
    
    var selAcademicLevel = document.getElementById("selAcademicLevel"); // Get country select Id
    if (selAcademicLevel.length > 0) return; // To ensure it is only run only once when form loads

    for (arraycounter1 in arrAcademicLevel)  // loop through AcademicLevel array
    {
        var HOptNew = document.createElement('option'); // Create new option to be inserted
        HOptNew.text = arrAcademicLevel[arraycounter1];  // set text of option to be inserted
        HOptNew.value = arrAcademicLevel[arraycounter1]; // set value of option to be inserted
        try     { selAcademicLevel.add(HOptNew,null);} // standards compliant    
          catch(ex)    {    selAcademicLevel.add(HOptNew);} // IE only 
    }
//    arrAcademicLevel = arrAcademicLevel.slice (1); // remove the first element in array "All AcademicLevel"
}

function FillDeadlineSelect()
{
//  alert (" Fill Deadline Select"); // for debugging purposes
    // Local Variables
    var arraycounter1;  
    
    var selDeadline = document.getElementById("selDeadline"); // Get country select Id
    if (selDeadline.length > 0) return; // To ensure it is only run only once when form loads

    for (arraycounter1 in arrDeadline)  // loop through countries array
    {
        var HOptNew = document.createElement('option'); // Create new option to be inserted
        HOptNew.text = arrDeadline[arraycounter1];  // set text of option to be inserted
        HOptNew.value = arrDeadline[arraycounter1]; // set value of option to be inserted
        try     { selDeadline.add(HOptNew,null);} // standards compliant    
          catch(ex)    {    selDeadline.add(HOptNew);} // IE only 
    }
//    arrCountries = arrCountries.slice (1); // remove the first element in array "All Countries"
}

function FillGradeSelect()
{
//  alert (" Fill Grade Select"); // for debugging purposes
    // Local Variables
    var arraycounter1;  
    
    var selGrade = document.getElementById("selGrade"); // Get country select Id
    if (selGrade.length > 0) return; // To ensure it is only run only once when form loads

    for (arraycounter1 in arrGrade)  // loop through countries array
    {
        var HOptNew = document.createElement('option'); // Create new option to be inserted
        HOptNew.text = arrGrade[arraycounter1];  // set text of option to be inserted
        HOptNew.value = arrGrade[arraycounter1]; // set value of option to be inserted
        try     { selGrade.add(HOptNew,null);} // standards compliant    
          catch(ex)    {    selGrade.add(HOptNew);} // IE only 
    }
}

function FillStyleSelect()
{
//  alert (" Fill Style Select"); // for debugging purposes
    // Local Variables
    var arraycounter1;  
    
    var selStyle = document.getElementById("selStyle"); // Get country select Id
    if (selStyle.length > 0) return; // To ensure it is only run only once when form loads

    for (arraycounter1 in arrStyle)  // loop through countries array
    {
        var HOptNew = document.createElement('option'); // Create new option to be inserted
        HOptNew.text = arrStyle[arraycounter1];  // set text of option to be inserted
        HOptNew.value = arrStyle[arraycounter1]; // set value of option to be inserted
        try     { selStyle.add(HOptNew,null);} // standards compliant    
          catch(ex)    {    selStyle.add(HOptNew);} // IE only 
    }
}

function FillLanguageSelect()
{
//  alert (" Fill Language Select"); // for debugging purposes
    // Local Variables
    var arraycounter1;  
    
    var selLanguage = document.getElementById("selLanguage"); // Get country select Id
    if (selLanguage.length > 0) return; // To ensure it is only run only once when form loads

    for (arraycounter1 in arrLanguage)  // loop through countries array
    {
        var HOptNew = document.createElement('option'); // Create new option to be inserted
        HOptNew.text = arrLanguage[arraycounter1];  // set text of option to be inserted
        HOptNew.value = arrLanguage[arraycounter1]; // set value of option to be inserted
        try     { selLanguage.add(HOptNew,null);} // standards compliant    
          catch(ex)    {    selLanguage.add(HOptNew);} // IE only 
    }
}

function FillNumberofPagesSelect()
{
//  alert (" Fill NumberofPages Select"); // for debugging purposes
    // Local Variables
    var arraycounter1;  
    
    var selNumberofPages = document.getElementById("selNumberofPages"); // Get country select Id
    if (selNumberofPages.length > 0) return; // To ensure it is only run only once when form loads

    for (arraycounter1 in arrNumberofPages)  // loop through countries array
    {
        var HOptNew = document.createElement('option'); // Create new option to be inserted
        HOptNew.text = arrNumberofPages[arraycounter1];  // set text of option to be inserted
        HOptNew.value = arrNumberofPages[arraycounter1]; // set value of option to be inserted
        try     { selNumberofPages.add(HOptNew,null);} // standards compliant    
          catch(ex)    {    selNumberofPages.add(HOptNew);} // IE only 
    }
}

function FillNumber_of_QuotesSelect()
{
    // Local Variables
    var arraycounter1;  
    
    var selNumberofQuotes = document.getElementById("selNumberofQuotes"); // Get country select Id
    if (selNumberofQuotes.length > 0) return; // To ensure it is only run only once when form loads

    for (arraycounter1 in arrNumberofQuotes)  // loop through countries array
    {
        var HOptNew = document.createElement('option'); // Create new option to be inserted
        HOptNew.text = arrNumberofQuotes[arraycounter1];  // set text of option to be inserted
        HOptNew.value = arrNumberofQuotes[arraycounter1]; // set value of option to be inserted
        try     { selNumberofQuotes.add(HOptNew,null);} // standards compliant    
          catch(ex)    {    selNumberofQuotes.add(HOptNew);} // IE only 
    }
//  alert (" Fill NumberofQuotes Select"); // for debugging purposes
}

function InitDefaultValuesinSelects()
{
  var selsubject = document.getElementById("selsubject");   // get div object
  selsubject.selectedIndex = 9;
  var selType = document.getElementById("selType");   // get div object
  selType.selectedIndex = 9;
  var selDeadline = document.getElementById("selDeadline");   // get div object
  selDeadline.selectedIndex = 5;
  var selAcademicLevel = document.getElementById("selAcademicLevel");   // get div object
  selAcademicLevel.selectedIndex = 1;
  var selGrade = document.getElementById("selGrade");   // get div object
  selGrade.selectedIndex = 2;
  var selNumberofPages = document.getElementById("selNumberofPages");   // get div object
  selNumberofPages.selectedIndex = 0;
  var selNumberofQuotes = document.getElementById("selNumberofQuotes");   // get div object
  selNumberofQuotes.selectedIndex = 1;
  var selStyle = document.getElementById("selStyle");   // get div object
  selStyle.selectedIndex = 0;
  var selLanguage = document.getElementById("selLanguage");   // get div object
  selLanguage.selectedIndex = 1;
}

function CalculatePrice()
{
  var selsubject = document.getElementById("selsubject");   
  var selectedsubjectIndex = selsubject.selectedIndex;
  var isubjectPrice = arrsubjectPrice[selectedsubjectIndex];

  var selDeadline = document.getElementById("selDeadline");   
  var selectedDeadlineIndex = selDeadline.selectedIndex;
  var iDeadlinePrice = arrDeadlinePrice[selectedDeadlineIndex];
//  alert (iDeadlinePrice);

  var selAcademicLevel = document.getElementById("selAcademicLevel");   
  var selectedAcademicLevelIndex = selAcademicLevel.selectedIndex;
  var iAcademicLevelPrice = arrAcademicLevelPrice[selectedAcademicLevelIndex];

  var selGrade = document.getElementById("selGrade");   
  var selectedGradeIndex = selGrade.selectedIndex;
  var iGradePrice = arrGradePrice[selectedGradeIndex];

  var selNumberofPages = document.getElementById("selNumberofPages");   
  var selectedNumberofPagesIndex = selNumberofPages.selectedIndex;
  var iNumberofPages = arrNumberofPagesPrice[selectedNumberofPagesIndex];
//  alert (iNumberofPages);
  
  iTotalPrice = iBasicCost+isubjectPrice+iDeadlinePrice+iAcademicLevelPrice+iGradePrice;
  iTotalPrice = iTotalPrice * iNumberofPages;
  document.getElementById("lblPrice").innerHTML =iTotalPrice+ " $";
  document.getElementById("hidden_price").value =iTotalPrice+"";
  
  
    // for UK SWREG SERVER
//  SwregStatement = "https://gbp.swreg.org/cgi-bin/s.cgi?s=53087&p=53087-22&vp=";
//  iTotalPrice = iTotalPrice * 0.66;
 
// SwregStatement = "https://www.paypal.com/cgibin/webscr?cmd=_xclick&business=support@qualityresearch.org.uk&item_name=Custom+Writing&quantity=1&currency_code=USD&amount=";

  var iorderid = document.getElementById("orderid").value;
  var icustomerid = document.getElementById("customerid").value;  

SwregStatement = "https://www.paypal.com/cgibin/webscr?cmd=_xclick&business=support@qualityresearch.org.uk&item_name=Custom+Writing&quantity=1&currency_code=USD";
 
 strorderid = "&item_number=" + iorderid;
 strcustomerid = "&custom=" + icustomerid;	 
 strprice   = "&amount=" + iTotalPrice;
  
//  document.getElementById("to_swreg").value =SwregStatement + iTotalPrice;
  document.getElementById("to_swreg").value =SwregStatement + strorderid + strcustomerid + strprice;
//  alert (SwregStatement + strorderid + strcustomerid + strprice);
}

function GoToURL()
{
	
}

function GoToSwreg ()
{
	CalculatePrice();
	SwregStatement = SwregStatement + iTotalPrice;
	location.href = SwregStatement;
	return false;
}
