//
//
//      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)
{
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)
{
    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)
			    CtrlEnable();
			else
			    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){
	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"]);

		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(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;
		}
	}
}

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)
//**********************************************
function cUpdateFormField(sActionURL, sFieldName1, sFieldType1, sFieldName2, sFieldResultName, 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 == sFormID +'$'+ 'cancelinsure' || sFieldName1 == sFormID +'$'+ 'medicalinsure' || sFieldName1 == sFormID +'$'+ 'internship')
	{
		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
		if((sFieldName1=="BookNow_programme")||(sFieldName1=="PartnerBooking_programme") || (sFieldName1=="Quote_programme")){
		    Parameters["startdate"] = GetSelectValue(sFormID + "_startdate");
			result=jaxAction(sActionURL, Parameters, School, 'GetPrice'); //get a result from the sP page
		}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)

		//	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 = "";

		if(sTmpResult !="0.00"){
			sCurrency = result.substring(0,3);
			result = cleanString(result.substring(4));
			result = sCurrency + ' ' + result; //GBP appears if no price returned 
		}else{
			result = cleanString(result.substring(4));
		}

		object.value = result;
		enrbox = document.getElementById(sFormID + '_enrprice');		
		totalbox = document.getElementById(sFormID + '_totalprice');

		if(sFieldResultName == 'price1')
		{
			GetPrices(1);
			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");
			enr=jaxAction(sActionURL, eParameters, eSchool, 'GetAccomPrice');
			enr = enr.substring(4);
			enrbox.value = sCurrency + ' ' + enr;

			//***Accomodation List - calls getAccomItems from Framework.js
			res = getAccomItems(sActionURL, Parameters, School, 'A'); //get a result from the sP page
			//Added by Manoj to remove the extra spaces coming in dropdown
			res = Trim(res);
			
			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
			res = Trim(res);
			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');
			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
			res = Trim(res);
			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);
			//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);
			
		}
		else
		{
			rV = "0.00";
		}

		if(sCurrency == "")
		{
			if(!IsFloat(totalbox.value))
			{
				sCurrency = totalbox.value.substring(0,3);				
			}
		}
			var total = parseFloat(enrV) + total + parseFloat(rV);
			totalbox.value = sCurrency + ' ' + total;
			if(totalbox.value.indexOf('.') == -1)
				totalbox.value = totalbox.value + '.00';
			
		
	}
}

/*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));
		if(i>sPriceInd)
			pField.value = '0.00';
	}
	return total;
}

function UpdateWPAmount(sFieldName)
{
	sFieldValue = GetSelectValue(sFieldName);
	//alert(sFieldValue);
	sField = document.getElementById(sFieldName);
	amountField = document.getElementById('amount');
	//alert(document.getElementById('totalamount').value + "*" + document.getElementById('enrprice').value);
	if(sFieldValue == 'full')
		amountField.value = document.getElementById('totalamount').value.substring(4);
	else
		amountField.value = document.getElementById('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);
	
	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(sDuration != "null")
	{
		document.getElementById(sFormID + "_duration").value = sDuration;
		cUpdateFormField(sActionURL, sFormID + "_programme", "select", sFormID + "_duration", "price1", sFormID);
	}
	if(sStartDate != "null" && sStartDate != "1/1/1")
	{
		document.getElementById(sFormID + "_startdate").value = sStartDate;
		cSetHiddenValue(sFormID + "_startdate", 'select', 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";
	}
	
	//alert(sFieldName2);
	
	/*if(sFieldType1 == 'radio')
		alert(sFieldValue1);*/

	var hiddenVal;
    hiddenVal = document.getElementById(sFieldName2);
    
    //alert(sFormID + "_h" + sFieldName1);
    if(hiddenVal != null)
		hiddenVal.value = sFieldValue1;
}
//Trim function added by Manoj
// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function Trim( value ) 
{
//alert(value);	
	return LTrim(RTrim(value));
	
}

