//
//
//      Site specific commands
//
//
/*startHighlight = function(){
if (document.all && document.getElementById)
{  
navRoot = document.getElementById("DataGrid1");
// Get a reference to the TBODY element 
tbody = navRoot.childNodes[0];
for (i = 0; i < tbody.childNodes.length; i++)
{
node = tbody.childNodes[i];
if (node.nodeName == "TR")
{
node.onmouseover=function()
{
this.className = "over";                
}
node.onmouseout=function()
{
this.className = this.className.replace("over", "");
}
}
}
}
}*/
//window.onload = startHighlight;

function CheckDateSelection(sFormID) {

    if (GetSelectValue(sFormID + "_startdate") == "") {
        alert(document.getElementById('Date_Error_h').value);
        return false;
    }
    return true;
}

function winOpen(sCVLocation) {
    window.open(sCVLocation, 'cv');
}
/**********************
**code
************************/
function ResetWeeks(sFormID) {

    //sFormID = "ctl00_PageContentPlaceHolder_" + sFormID;
    document.getElementById(sFormID + "_duration").options[0].selected = true;
    document.getElementById(sFormID + '_duration' + '_h').value = "";

    document.getElementById("price1").value = "0.00";
    document.getElementById("price2").value = "0.00";
    document.getElementById("price3").value = "0.00";
    document.getElementById("price5").value = "0.00";
    document.getElementById("price6").value = "0.00";
    document.getElementById("price7").value = "0.00";
    document.getElementById(sFormID + '_enrprice').value = '0.00';
    document.getElementById(sFormID + '_totalprice').value = '0.00';

    removeOptions(document.getElementById(sFormID + '_accommodation1'));
    document.getElementById(sFormID + '_accommodation1' + '_h').value = "";
    removeOptions(document.getElementById(sFormID + '_accommodation2'));
    document.getElementById(sFormID + '_accommodation2' + '_h').value = "";
    removeOptions(document.getElementById(sFormID + '_airporttransfer'));
    document.getElementById(sFormID + '_airporttransfer' + '_h').value = "";
    removeOptions(document.getElementById(sFormID + '_ucpservice'));
    document.getElementById(sFormID + '_ucpservice' + '_h').value = "";
    removeOptions(document.getElementById(sFormID + '_accommduration'));
    document.getElementById(sFormID + '_accommduration' + '_h').value = "";


    document.getElementById(sFormID + "_internship_yes").checked = false;
    document.getElementById(sFormID + "_internship_no").checked = false;
    document.getElementById(sFormID + '_internship' + '_h').value = "";

    document.getElementById(sFormID + "_medicalinsure_yes").checked = false;
    document.getElementById(sFormID + "_medicalinsure_no").checked = false;
    document.getElementById(sFormID + '_medicalinsure' + '_h').value = "";


}
function FillSelectDates(sActionURL, sFieldName1, sFieldType1, sFieldResultName, sFormID) {
    //alert(sFormID);
    var Parameters = new Array();
    var sFieldValue1;
    if (sFieldType1 == 'select')
        sFieldValue1 = GetSelectValue(sFieldName1);
    if (sFieldType1 == 'radio')
        sFieldValue1 = GetRadioVal(sFieldName1);
    //cSetHiddenValue(sFieldName1, 'select', sFormID);
    if (sFieldValue1 != "") {
        Parameters["itemcode"] = sFieldValue1;

        //    alert("sFieldValue" + sFieldValue1);
        School = new Array();
        School["schoolcode"] = GetSelectValue(sFormID + "_school");
        //alert(School["schoolcode"] + " " + Parameters["itemcode"]);
        var startdates, dates, theSel
        startdates = jaxAction(sActionURL, Parameters, School, 'GetStartDates') //get a result from the sP page
        if (startdates != 0) {
            //alert("Inside");
            CtrlEnable();
        }
        else {
            //alert("Outside");
            CtrlDisable();
        }

        dates = startdates.split('|');

        theSel = document.getElementById(sFormID + '_startdate');

        //alert("theSel=" + theSel.id);

        removeOptions(theSel);
        var dateStr;
        for (ind in dates) {
            if (dates[ind] != "0") {
                dateStr = dates[ind].substring(0, dates[ind].indexOf('/')) + "/" + dates[ind].substring(dates[ind].indexOf('/') + 1, dates[ind].lastIndexOf('/')) + "/" + dates[ind].substr(dates[ind].lastIndexOf('/') + 1, 4);
                theSel.options[theSel.length] = new Option(dateStr, dateStr);
            }
        }
        hidCon = document.getElementById(sFormID + '_startdate' + '_h');
        hidCon.value = "";

    }


}
// Send form field name and value to a given action

//UpdateFormSelect('UpdatePrice.aspx', 'BookNow_accommodation1', 'select', 'BookNow_accommduration')"

function cUpdateFormSelect(sActionURL, sFieldName1, sFieldType1, sFieldResultName, sFormID) {

    /*if ((sFormID == "BookNow") || (sFormID == "PartnerBooking") || (sFormID == "Quote")) {
        sFormID = "ctl00_PageContentPlaceHolder_" + sFormID;
    }
    else {
        sFormID = sFormID;
    }*/
    var Parameters = new Array();
    var sFieldValue1;
    if (sFieldType1 == 'select')
        sFieldValue1 = GetSelectValue(sFieldName1);
    if (sFieldType1 == 'radio')
        sFieldValue1 = GetRadioVal(sFieldName1);
    cSetHiddenValue(sFieldName1, 'select', sFormID);
    //alert("sFieldValue" + sFieldValue1);
    if (sFieldValue1 != "") {
        Parameters["itemcode"] = sFieldValue1;

        //   alert("sFieldValue" + sFieldValue1);
        School = new Array();
        School["schoolcode"] = GetSelectValue(sFormID + "_school");
        //alert(School["schoolcode"] + " " + Parameters["itemcode"]);

        if (sFieldName1 == sFormID + '_accommodation1') {

            result = jaxAction(sActionURL, Parameters, School, 'GetAccomWeeks'); //get a result from the sP page
        } else {
            result = jaxAction(sActionURL, Parameters, School, 'GetWeeks'); //get a result from the sP page

            FillSelectDates(sActionURL, sFieldName1, sFieldType1, sFieldResultName, sFormID);
        }
        //alert(sFieldName1);
        //alert(result);
        //alert(sFieldResultName);
        /*Takes the result from the db - if 0 then print out 0-49, if 0-23 (eg), or fixed length*/
        result = cleanString(result);
        //alert(result);
        var maxweeks = 0;
        var startweek = 1;
        if (result.indexOf("-") > -1) {
            var divider = result.indexOf("-");
            //alert(divider);
            //	sWeeks = result;
            startweek = result.substring(0, divider);
            maxweeks = result.substring(divider + 1);
            //alert(maxweeks);
            result = "";
        } else if (result == "0") {
            maxweeks = 49;
            result = "";
        }
        for (var i = parseInt(startweek); i <= parseInt(maxweeks); i++) {
            result += i + "|";
        }
        if (result.indexOf("|") > -1) {
            result = result.slice(0, -1)
        }

        weeks = result.split('|'); //covers all scenarios

        /*now print out the options*/
        theSel = document.getElementById(sFieldResultName);
        removeOptions(theSel);

        var nTemp = 1;
        for (ind in weeks) {
            if (weeks[ind] != "0" && weeks[ind] != "")
                theSel.options[nTemp] = new Option(weeks[ind] + ' weeks', weeks[ind]);
            nTemp = nTemp + 1;
        }
    }

    if (sFieldName1 == sFormID + '_accommodation1') {
        LongTermCourseWeeks(sFormID);
    }
}

function LongTermCourseWeeks(cFormID) {
    //alert(cFormID);
    //alert(GetSelectValue(cFormID + "_programme"));
    if (GetSelectValue(cFormID + "_programme") == "ASINT") {
        o = document.getElementById(cFormID + "_accommduration");
        removeOptions(o);
        o.options[1] = new Option("21" + ' weeks', "21");

    }

    if (GetSelectValue(cFormID + "_programme") == "ASGEN") {
        o = document.getElementById(cFormID + "_accommduration");
        removeOptions(o);
        o.options[1] = new Option("21" + ' weeks', "21");

    }

    if (GetSelectValue(cFormID + "_programme") == "ASINT6") {
        o = document.getElementById(cFormID + "_accommduration");
        removeOptions(o);
        o.options[1] = new Option("25" + ' weeks', "25");

    }

    if (GetSelectValue(cFormID + "_programme") == "ASGEN6") {
        o = document.getElementById(cFormID + "_accommduration");
        removeOptions(o);
        o.options[1] = new Option("25" + ' weeks', "25");

    }

    if (GetSelectValue(cFormID + "_programme") == "AYINT") {
        o = document.getElementById(cFormID + "_accommduration");
        removeOptions(o);
        o.options[1] = new Option("33" + ' weeks', "33");

    }

    if (GetSelectValue(cFormID + "_programme") == "AYGEN") {
        o = document.getElementById(cFormID + "_accommduration");
        removeOptions(o);
        o.options[1] = new Option("33" + ' weeks', "33");

    }



}

function removeOptions(theSel) {
    var i;
    for (i = theSel.length - 1; i >= 1; i--) {
        theSel.remove(i);
    }
}

/*Clean out the squares*/
function cleanString(sText) {
    var ValidChars = "0123456789|.-";
    var Char;
    var retString = "";

    for (i = 0; i < sText.length; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) != -1) {
            retString += Char;
        }
    }
    return retString;
}

function deleteOptions(selectObject) {
    if (selectObject.options.length != 0) {
        for (i = 1; i < selectObject.options.length; i++) {
            selectObject.options[i] = null
        }
    }
}

//**********************************************
//Airport Transfer - TSILS
//BookNow:CancelINsurance - CIILS
//BookNow:MedicalInsurance - MIILS
//BookNow:Internship - INT4ILS
//UCPServices(University Placement Scheme) - FEUPIAY
//INT4ILS - Internship - fixed cost(unit 1)
//**********************************************
// UpdateFormField('UpdatePrice.aspx', 'BookNow_programme', 'select', 'BookNow_duration', 'price1')
function cUpdateFormField(sActionURL, sFieldName1, sFieldType1, sFieldName2, sFieldResultName, sFormID) {
    //alert(sFormID);

    /*if ((sFormID == "BookNow") || (sFormID == "PartnerBooking") || (sFormID == "Quote")) {
        sFormID = "ctl00_PageContentPlaceHolder_" + sFormID;
    }
    else {
        sFormID = sFormID;
    }*/

    var Parameters = new Array();
    var sFieldValue1;
    var sFieldValue2;
    var total = 0.00;
    if (sFieldType1 == 'select')
        sFieldValue1 = GetSelectValue(sFieldName1);
    if (sFieldType1 == 'radio')
        sFieldValue1 = GetRadioVal(sFieldName1);
    sFieldValue2 = GetSelectValue(sFieldName2);

    if (sFieldName1 == sFormID + '_airporttransfer' || sFieldName1 == sFormID + '_ucpservice') {
        cSetHiddenValue(sFieldName1, 'select', sFormID);
    }
    //else if (sFieldName1.match(sFormID + ":") != null) {
    else if (sFieldType1 == 'radio') {
        cSetHiddenValue(sFieldName1, 'radio', sFormID);
    }
    else {
        cSetHiddenValue(sFieldName2, 'select', sFormID);
    }
    if (sFieldValue1 != "" && sFieldValue2 != "") {
        Parameters["itemcode"] = sFieldValue1;
        //***reset these form fields to only bring back price for 1 week
        /*if((sFieldName1 == sFormID + '_airporttransfer') || (sFieldName1 == sFormID + '_ucpservice') 
        || (sFieldName1 == sFormID + ':cancelinsure') || (sFieldName1 == sFormID + ':internship'))*/
        if (sFieldName1 == sFormID + '_airporttransfer')
            Parameters["weeks"] = '1';
        else
            Parameters["weeks"] = sFieldValue2;

        School = new Array();
        School["schoolcode"] = GetSelectValue(sFormID + "_school");

        //check to see which weeks drop down is doing the call - for Course use GetPrice
        //changed by saurabh for Quote
        //alert(sFieldName1);
        //alert("sActionUrl=" + sActionURL + "  ItemCode = " + Parameters["itemcode"] + " ; weeks=" + Parameters["weeks"] + "  ;schoolcode=" + School["schoolcode"] + "  ; startdate = " + GetSelectValue(sFormID + "Quote_startdate"));
        if ((sFieldName1 == "ctl00_PageContentPlaceHolder_BookNow_programme") || (sFieldName1 == "ctl00_PageContentPlaceHolder_PartnerBooking_programme") || (sFieldName1 == "ctl00_PageContentPlaceHolder_Quote_programme")) {
            Parameters["startdate"] = GetSelectValue(sFormID + "_startdate");
            result = jaxAction(sActionURL, Parameters, School, 'GetPrice'); //get a result from the sP page
            //alert("sFieldName1=" + sFieldName1 + "sFieldValue1=" + sFieldValue1 + " result=" + result);
        }
        else {
            Parameters["startdate"] = GetSelectValue(sFormID + "_startdate");
            result = jaxAction(sActionURL, Parameters, School, 'GetAccomPrice'); //get a result from the sP page
            //alert("sFieldName1=" + sFieldName1 + "sFieldValue1=" + sFieldValue1 + " result=" + result);
        }

        object = document.getElementById(sFieldResultName)
        //alert(object);
        //	sCurrency = result.substring(0,3);
        //	result = cleanString(result.substring(4));
        //	result = sCurrency + ' ' + result; //GBP appears if no price returned 

        var sTmpResult = cleanString(result.substring(4));
        var sCurrency = "";
        //alert(sTmpResult);

        if (sTmpResult != "0.00") {

            sCurrency = result.substring(0, 3);
            result = cleanString(result.substring(4));
            //alert("Inside sTmpResult 1 -"+result);
            result = sCurrency + ' ' + result; //GBP appears if no price returned 
            //alert("Inside sTmpResult - 2"+result);

        }
        else {

            //result = cleanString(result.substring(4));
            //alert("Outside sTmpResult -"+result);
        }
        //alert(result);
        object.value = result;

        enrbox = document.getElementById(sFormID + '_enrprice');
        totalbox = document.getElementById(sFormID + '_totalprice');

        //alert("Total" + totalbox);
        //alert("sFormID" + sFormID);
        if (sFieldResultName == 'price1') {
            GetPrices(1);
            //alert("Total Value " +totalbox.value);
            totalbox.value = '0.00';
            enrbox.value = '0.00';
            /* Commented by saurabh
            startdates=jaxAction(sActionURL, Parameters, School, 'GetStartDates'); //get a result from the sP page

           if(startdates != 0)
            CtrlEnable();
            else
            CtrlDisable();
            */
            //*******Get Enrolment fee here and popuulate the box at the bottom********
            eParameters = new Array();
            eParameters["itemcode"] = 'FEEILS';
            eParameters["weeks"] = "1";
            eParameters["startdate"] = GetSelectValue(sFormID + "_startdate");
            eSchool = new Array();
            eSchool["schoolcode"] = GetSelectValue(sFormID + "_school");

            //alert(sFormID+" "+eSchool["schoolcode"]);
            enr = jaxAction(sActionURL, eParameters, eSchool, 'GetAccomPrice');
            enr = enr.substring(4);
            enrbox.value = sCurrency + ' ' + enr;
            //alert(enrbox.value);
            //***Accomodation List - calls getAccomItems from Framework.js
            res = getAccomItems(sActionURL, Parameters, School, 'A'); //get a result from the sP page

            totalbox.value = '0.00';
            accoms = res.split('|');
            /* Commented by saurabh		
            dates = startdates.split('|');
            */
            var hidCon;
            theSel = document.getElementById(sFormID + '_accommodation1');
            removeOptions(theSel);
            theSel2 = document.getElementById(sFormID + '_accommodation2');
            removeOptions(theSel2);

            hidCon = document.getElementById(sFormID + '_accommodation1' + '_h');
            hidCon.value = "";
            hidCon = document.getElementById(sFormID + '_accommodation2' + '_h');
            hidCon.value = "";
            for (ind in accoms) {
                if (accoms[ind] != "0") {
                    aoption = accoms[ind].split('^');
                    theSel.options[theSel.length] = new Option(aoption[1], aoption[0]);
                    theSel2.options[theSel2.length] = new Option(aoption[1], aoption[0]);
                }
            }

            res = getItems(sActionURL, Parameters, School, 'T'); //get a result from the sP page
            airportt = res.split('|');
            theSel = document.getElementById(sFormID + '_airporttransfer');
            removeOptions(theSel);

            for (ind in airportt) {
                if (airportt[ind] != "0") {
                    toption = airportt[ind].split('^');
                    theSel.options[theSel.length] = new Option(toption[1], toption[0]);
                }
            }
            hidCon = document.getElementById(sFormID + '_airporttransfer' + '_h');
            //alert(hidCon);
            hidCon.value = "";


            Parameters = new Array();
            Parameters["itemcode"] = 'FEUP%';
            School = new Array();
            School["schoolcode"] = GetSelectValue(sFormID + "_school");
            res = getItemCodes(sActionURL, Parameters, School); //get a result from the sP page

            itemcs = res.split('|');
            theSel = document.getElementById(sFormID + '_ucpservice');
            removeOptions(theSel);

            for (ind in itemcs) {
                if (itemcs[ind] != "0") {
                    toption = itemcs[ind].split('^');
                    theSel.options[theSel.length] = new Option(toption[1], toption[0]);
                }
            }
            hidCon = document.getElementById(sFormID + '_ucpservice' + '_h');
            hidCon.value = "";
            /* Commented by saurabh
            theSel = document.getElementById(sFormID + '_startdate');
			
//alert("theSel=" + theSel.id);

            removeOptions(theSel);
            var dateStr;
            for(ind in dates)
            {
            if(dates[ind] != "0")
            {
            dateStr = dates[ind].substring(0, dates[ind].indexOf('/')) + "/" + dates[ind].substring(dates[ind].indexOf('/')+1, dates[ind].lastIndexOf('/')) + "/" + dates[ind].substr(dates[ind].lastIndexOf('/')+1,4);
            theSel.options[theSel.length] = new Option(dateStr, dateStr);
            }
            }
			
			hidCon = document.getElementById(sFormID + '_startdate' + '_h');
            hidCon.value = "";
            */
            theSel = document.getElementById(sFormID + '_accommduration');
            removeOptions(theSel);

            hidCon = document.getElementById(sFormID + '_accommduration' + '_h');
            hidCon.value = "";
            document.getElementById(sFormID + "_cancelinsure_yes").checked = false;
            document.getElementById(sFormID + "_cancelinsure_no").checked = false;
            hidCon = document.getElementById(sFormID + '_cancelinsure' + '_h');
            hidCon.value = "";
            document.getElementById(sFormID + "_medicalinsure_yes").checked = false;
            document.getElementById(sFormID + "_medicalinsure_no").checked = false;
            hidCon = document.getElementById(sFormID + '_medicalinsure' + '_h');
            hidCon.value = "";
            document.getElementById(sFormID + "_internship_yes").checked = false;
            document.getElementById(sFormID + "_internship_no").checked = false;
            hidCon = document.getElementById(sFormID + '_internship' + '_h');
            hidCon.value = "";

        }
        if (sFieldResultName == 'price2') {
            total = GetPrices(2);
            //totalbox.value = sCurrency + ' ' + total;


            theSel = document.getElementById(sFormID + '_airporttransfer');
            theSel.value = "";
            hidCon = document.getElementById(sFormID + '_airporttransfer' + '_h');
            hidCon.value = "";
            document.getElementById(sFormID + "_cancelinsure_yes").checked = false;
            document.getElementById(sFormID + "_cancelinsure_no").checked = false;
            hidCon = document.getElementById(sFormID + '_cancelinsure' + '_h');
            hidCon.value = "";
            document.getElementById(sFormID + "_medicalinsure_yes").checked = false;
            document.getElementById(sFormID + "_medicalinsure_no").checked = false;
            hidCon = document.getElementById(sFormID + '_medicalinsure' + '_h');
            hidCon.value = "";
            document.getElementById(sFormID + "_internship_yes").checked = false;
            document.getElementById(sFormID + "_internship_no").checked = false;
            hidCon = document.getElementById(sFormID + '_internship' + '_h');
            hidCon.value = "";
            theSel = document.getElementById(sFormID + '_ucpservice');
            theSel.value = "";
            hidCon = document.getElementById(sFormID + '_ucpservice' + '_h');
            hidCon.value = "";
        }
        if (sFieldResultName == 'price3') {
            total = GetPrices(3);
            //totalbox.value = sCurrency + ' ' + total;
            document.getElementById(sFormID + "_cancelinsure_yes").checked = false;
            document.getElementById(sFormID + "_cancelinsure_no").checked = false;
            hidCon = document.getElementById(sFormID + '_cancelinsure' + '_h');
            hidCon.value = "";
            document.getElementById(sFormID + "_medicalinsure_yes").checked = false;
            document.getElementById(sFormID + "_medicalinsure_no").checked = false;
            hidCon = document.getElementById(sFormID + '_medicalinsure' + '_h');
            hidCon.value = "";
            document.getElementById(sFormID + "_internship_yes").checked = false;
            document.getElementById(sFormID + "_internship_no").checked = false;
            hidCon = document.getElementById(sFormID + '_internship' + '_h');
            hidCon.value = "";
            theSel = document.getElementById(sFormID + '_ucpservice');
            theSel.value = "";
            hidCon = document.getElementById(sFormID + '_ucpservice' + '_h');
            hidCon.value = "";
        }
        if (sFieldResultName == 'price4') {
            total = GetPrices(4);
            //totalbox.value = sCurrency + ' ' + total;
            document.getElementById(sFormID + "_medicalinsure_yes").checked = false;
            document.getElementById(sFormID + "_medicalinsure_no").checked = false;
            hidCon = document.getElementById(sFormID + '_medicalinsure' + '_h');
            hidCon.value = "";
            document.getElementById(sFormID + "_internship_yes").checked = false;
            document.getElementById(sFormID + "_internship_no").checked = false;
            hidCon = document.getElementById(sFormID + '_internship' + '_h');
            hidCon.value = "";
            theSel = document.getElementById(sFormID + '_ucpservice');
            theSel.value = "";
            hidCon = document.getElementById(sFormID + '_ucpservice' + '_h');
            hidCon.value = "";
        }
        if (sFieldResultName == 'price5') {
            total = GetPrices(5);
            //alert("Total -"+total);
            //totalbox.value = sCurrency + ' ' + total;
            theSel = document.getElementById(sFormID + '_ucpservice');
            theSel.value = "";
            hidCon = document.getElementById(sFormID + '_ucpservice' + '_h');
            hidCon.value = "";
        }
        if (sFieldResultName == 'price6') {
            total = GetPrices(6);
            //totalbox.value = sCurrency + ' ' + total;
            document.getElementById(sFormID + "_internship_yes").checked = false;
            document.getElementById(sFormID + "_internship_no").checked = false;
            hidCon = document.getElementById(sFormID + '_internship' + '_h');
            hidCon.value = "";
        }
        if (sFieldResultName == 'price7') {
            total = GetPrices(7);
            //totalbox.value = sCurrency + ' ' + total;
        }
        if (enrbox.value.indexOf(sCurrency) != -1)
            enrV = enrbox.value.substring(4);
        else
            enrV = enrbox.value;
        //if(totalbox.value.indexOf(sCurrency)!= -1)
        //	totV = totalbox.value.substring(4);
        //else
        //	totV = totalbox.value;
        if (result != "0.00" && result != "0") {
            rV = result.substring(4);
            //alert("Result -"+rV);

        }
        else {
            rV = "0.00";
        }

        if (sCurrency == "") {
            //alert("Total Box Value "+totalbox.value);
            if (!IsFloat(totalbox.value)) {
                sCurrency = totalbox.value.substring(0, 3);
            }
        }
        var finaltotal = roundNumber(parseFloat(enrV) + total + parseFloat(rV), 2);
        //alert("parseFloat(enrV) "+parseFloat(enrV));			
        //alert("Total1 "+finaltotal);			
        //alert("parseFloat(rV) "+ parseFloat(rV));
        //alert("Total "+total);
        totalbox.value = sCurrency + ' ' + finaltotal;
        if (totalbox.value.indexOf('.') == -1)
            totalbox.value = totalbox.value + '.00';
        //alert("Total Box Value "+totalbox.value);

    }
}

//New function to add decimal according to places

function roundNumber(num, dec) {
    var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
    return result;
}

/*Clean out the squares*/
function IsFloat(sText) {
    var ValidChars = "0123456789.";
    var Char;
    var bNumber = true;

    for (i = 0; i < sText.length; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) != -1) {
            bNumber = false;
        }
    }
    return bNumber;
}


function GetPrices(sPriceInd) {

    var total = 0.00;
    var pField;
    for (var i = 1; i < 8; i++) {
        pField = document.getElementById('price' + i);
        if (pField.value != '0.00' && pField.value != '0' && i < sPriceInd)
            total += parseFloat(pField.value.substring(4));
        //alert(pField.value.substring(4)+" , " +pField.value);
        if (i > sPriceInd)
            pField.value = '0.00';
    }

    //alert(sPriceInd);
    return total;
}

//function UpdateWPAmount(sFieldName)
//{
//	sFieldValue = GetSelectValue(sFieldName);
//	//alert("sFieldValue"+sFieldValue);
//	sField = document.getElementById(sFieldName);
//	amountField = document.getElementById('ctl00_PageContentPlaceHolder_Quote' + 'amount');
//	//alert(document.getElementById('totalamount').value + "*" + document.getElementById('enrprice').value);
//	if(sFieldValue == 'full')
//	    amountField.value = document.getElementById('ctl00_PageContentPlaceHolder_Quote' + 'totalamount').value.substring(4);
//	else
//	    amountField.value = document.getElementById('ctl00_PageContentPlaceHolder_Quote' + 'enrprice').value.substring(4);
//}

// Get value from an input tag given the ID (Automatically finds client ID from asp id)
function GetInputValue(sInputID) {
    object = document.getElementById(sInputID)
    if (object) {
        return object.value;
    } else {
        return null;
    }
}
function GetSelectText(sInputID) {
    object = document.getElementById(sInputID)
    if (object) {
        return object[object.selectedIndex].text;
    } else {
        return null;
    }
}
function GetSelectValue(sInputID) {
    //if(ClientIDArray[sInputID]) sInputID=ClientIDArray[sInputID]; // Load ID from client ID array
    //this.options(this.selectedIndex).text
    object = document.getElementById(sInputID)
    if (object) {
        return object[object.selectedIndex].value;
    } else {
        return null;
    }
}
// Get checkbox/radio from an input tag given the ID (Automatically finds client ID from asp id)
function GetCheckedValue(sInputID) {
    //if sInputID = OnDay then get?
    //if(ClientIDArray[sInputID]) sInputID=ClientIDArray[sInputID]; // Load ID from client ID array
    object = document.getElementById(sInputID)
    if (object) {
        return object.checked ? true : false;
    } else {
        return null;
    }
}


function GetRadioVal(sInputID) {
    /*object = document.getElementById(sInputID)	
    var cbGroup = object.getElementsByTagName('input');*/
    cbGroup = document.getElementsByName(sInputID);
    for (var i = 0; i < cbGroup.length; i++) {
        if (cbGroup[i].checked) {
            var rad_val = cbGroup[i].value;
            break;
        }
    }

    return rad_val;
}


/************************
*Update Front-End boxes
*************************/
/*Assuming OnDay, OnMonth, OnYear
and pass onto UpdateBodyCopy [#Date#]
*/
function concatDateTime() {
    var sDate, sTime;
    sDate = GetInputValue("OnDay") + "/" + GetInputValue("OnMonth") + "/" + GetInputValue("OnYear");
    sTime = GetInputValue("AtHour") + ":" + GetInputValue("AtMinutes");
    UpdateCopy(sDate, "D", "subject");
    UpdateCopy(sDate, "D", "body");
    UpdateCopy(sTime, "T", "subject");
    UpdateCopy(sTime, "T", "body");
}

//Fills the book now form with session values
function cBatchFill(sActionURL, sSchool, sProgramme, sDuration, sStartDate, sAccommodation1, sAccommodation2, sAccommDuration, sAirportTransfer, sCancellationInsurance, sMedicalInsurance, sUPService, sInternship, sFormID) {
    //var sSchool = "<%= Session["registration"]!=null?((Registration)Session["registration"]).School:"" %>";
    //var sProgramme = "<%= Session["registration"]!=null?((Registration)Session["registration"]).Programme:"" %>";
    //var sDuration = "<%= Session["registration"]!=null?((Registration)Session["registration"]).WeekNumber:"" %>";
    //alert(sFormID);
    //sFormID = "ctl00_PageContentPlaceHolder_" + sFormID;

    if (sSchool != "null")
        document.getElementById(sFormID + "_school").value = sSchool;
    if (sProgramme != "null") {
        document.getElementById(sFormID + "_programme").value = sProgramme;
        cUpdateFormSelect(sActionURL, sFormID + "_programme", "select", sFormID + "_duration", sFormID);
    }
    if (sStartDate != "null" && sStartDate != "1/1/1") {
        document.getElementById(sFormID + "_startdate").value = sStartDate;
        cSetHiddenValue(sFormID + "_startdate", 'select', sFormID);
    }
    if (sDuration != "null") {
        document.getElementById(sFormID + "_duration").value = sDuration;
        cUpdateFormField(sActionURL, sFormID + "_programme", "select", sFormID + "_duration", "price1", sFormID);
    }

    if (sAccommodation1 != "null") {
        document.getElementById(sFormID + "_accommodation1").value = sAccommodation1;
        cUpdateFormSelect(sActionURL, sFormID + "_accommodation1", "select", sFormID + "_accommduration", sFormID);
    }
    if (sAccommodation2 != "null") {
        document.getElementById(sFormID + "_accommodation2").value = sAccommodation2;
        cSetHiddenValue(sFormID + "_accommodation2", 'select', sFormID);
    }
    if (sAccommDuration != "null") {
        document.getElementById(sFormID + "_accommduration").value = sAccommDuration;
        cUpdateFormField(sActionURL, sFormID + "_accommodation1", "select", sFormID + "_accommduration", "price2", sFormID);
    }
    //alert(sAirportTransfer);
    if (sAirportTransfer != "null") {
        document.getElementById(sFormID + "_airporttransfer").value = sAirportTransfer;
        cUpdateFormField(sActionURL, sFormID + "_airporttransfer", "select", sFormID + "_duration", "price3", sFormID);
    }
    if (sCancellationInsurance != "null" && sCancellationInsurance != "") {
        if (sCancellationInsurance == "no")
            document.getElementById(sFormID + "_cancelinsure_no").checked = true;
        else
            document.getElementById(sFormID + "_cancelinsure_yes").checked = true;
        cUpdateFormField(sActionURL, sFormID + ":cancelinsure", "radio", sFormID + "_duration", "price4", sFormID);
    }

    if (sMedicalInsurance != "null" && sMedicalInsurance != "") {
        if (sMedicalInsurance == "no")
            document.getElementById(sFormID + "_medicalinsure_no").checked = true;
        else
            document.getElementById(sFormID + "_medicalinsure_yes").checked = true;
        cUpdateFormField(sActionURL, sFormID + ":medicalinsure", "radio", sFormID + "_duration", "price5", sFormID);
    }

    if (sUPService != "null") {
        document.getElementById(sFormID + "_ucpservice").value = sUPService;
        cUpdateFormField(sActionURL, sFormID + "_ucpservice", "select", sFormID + "_duration", "price6", sFormID);
    }

    if (sInternship != "null" && sInternship != "") {
        if (sInternship == "no") {
            document.getElementById(sFormID + "_internship_no").checked = true;
        }
        else {
            document.getElementById(sFormID + "_internship_yes").checked = true;
        }
        cUpdateFormField(sActionURL, sFormID + ":internship", "radio", sFormID + "_duration", "price7", sFormID);
    }

    //alert(sStartDate + "==" + document.getElementById("startdate").value);
    //alert(sSchool + "*" + sProgramme);	
}



function cSetHiddenValue(sFieldName1, sFieldType1, sFormID) {
    var sFieldValue1;
    //alert(sFieldName1);
    var sFieldName2 = sFieldName1 + "_h";
    //alert(sFieldName);
    if (sFieldType1 == 'select')
        sFieldValue1 = GetSelectValue(sFieldName1);
    if (sFieldType1 == 'radio') {
        sFieldValue1 = GetRadioVal(sFieldName1);
        //sFieldName2 = sFormID + "_" + sFieldName1.substring(sFieldName1.indexOf(':') + 1) + "_h";
        sFieldName2 = sFieldName1 + "_h";
        sFieldName2 = sFieldName2.toString().replace(/\$/g, "_");
    }

    //alert(sFieldName2);

    /*if(sFieldType1 == 'radio')
    alert(sFieldValue1);*/

    var hiddenVal;
    hiddenVal = document.getElementById(sFieldName2);

    //alert(sFormID + "_h" + sFieldName1);
    if (hiddenVal != null)
        hiddenVal.value = sFieldValue1;

}





