
var ds = new Array()
var da = new Array()
var ln = new Array()
var it = new Array()
var rg = new Array()
var dp = new Array()
var ci = new Array()
var cp = 0
var cpdk = 0
var price = 0
var fee = 0
var amount = 0

function q(p1, p2, p3, p4, p5) {
	switch (funcname) {
		case 'ds':
			ds.p(p1,p2,p3,p4)
			break;
		case 'ln':
			ln.p(p1,p2)
			break;
		case 'da':
			da.p(p1,p2,p3)
			break;
		case 'in':
			it.p(p1,p2)
			break;
		case 'rg':
			rg.p(p1)
			break;
		case 'dp':
			dp.p(p1,p2)
			break;
		case 'ci':
			ci.p(p1,p2)
			break;
		default:
			break;
	}
}

ds.p = function(cpdk,dest,dcd,ctry) {
	this[this.length] = {
		'cpdk'	: cpdk,
		'dest'	: dest,
		'dcd'	: dcd,
		'ctry'	: ctry
	}
} 

rg.p = function (region) {
	this[this.length] = region
}

da.p = it.p = function(cpdk,date,ctype) {
	this[this.length] = {
		'cpdk'	: cpdk,
		'date'	: date,
		'ctype' : ctype
	}
} 

ln.p = dp.p = ci.p = function(lid, length) {
	this[this.length] = {
		'lid'		: lid,
		'length'	: length
	}
}

function getSelname(nm,rst,ac) {
	var br = 'OT';
	return '<select name="S'+nm+'" class="clean" '+(br=='NN'?'onFocus="if (this.disabled) {this.blur()}"':'')+' onChange="val(\'S'+nm+'\',this.options[this.selectedIndex].value,this.options[this.selectedIndex].text)"'+(ac==1?'':' disabled')+'><option value="" class="choose">--- Choose ---</option>'+rst+'</select>'
}

ds.toString = function (nm) {
	var result = ''
	for (i=0;i<this.length;i++) {
		result+='<option class="dest" value="'+this[i].dcd+'_'+this[i].cpdk+'">'+this[i].dest+'</option>'
	}
	return getSelname(nm,result,1)
}

da.toString = rg.toString = ln.toString = dp.toString = ci.toString = function (nm) {
	var result = ''
	
	for (i=0;i<this.length;i++) {
		result += '<option class="dest" value="'+this[i].lid+'">'+this[i].length+'</option>'
	}
	return getSelname(nm,result)
}

function scanval(arr,idx) {
	arr = arr.split(',')
	for (i=0;i<arr.length;i++) {
		tmp = arr[i].split('_')
		if (tmp[0]==idx) {return tmp[1]+'_'+tmp[2];}
	}
	return ''
}

function cheat() {
	val('Sregion', '-1', '-1')
}

function val(selbox,val,data) {

	var selboxes = ['Sdests','Sdates','Slength','Sdeps','Scity']
	var realvals = ['destination','date','length','departure','interview']
	var i = selboxes.length - 1;
	//loop through all the dropdowns and set some defaults
	while (i>=0 && selboxes[i] != selbox) {
		eval('document.booking.'+selboxes[i]).options.length = 0;
		eval('document.booking.'+selboxes[i]).options[0] = new Option('--- Choose ---','');
		eval('document.booking.'+selboxes[i]).options[0].className = 'choose'
		eval('document.booking.'+selboxes[i]).selectedIndex = 0;
		eval('document.booking.'+selboxes[i]).disabled = true;
		eval('document.booking.'+realvals[i]).value = ''
		i--;
	}
	
	//and the number buttons beside the checkboxes
	for (i=0;i<selboxes.length;i++) {
			eval('document.no'+(i+1)).src = '/_imgs/hsy/reserve/box_grey'+(i+1)+'.gif'
	}
	
	//enable or disable the number buttons
	for (i=0;i<selboxes.length;i++) {
		if (selbox==selboxes[i]) {
			for (j=-1;j<i;j++) {
					eval('document.no'+(j+2)).src = '/_imgs/hsy/reserve/checkbox_grey.gif';
			}
			if (selbox!='Scity') {
				eval('document.no'+(i+2)).src = '/_imgs/hsy/reserve/box_orange'+(i+2)+'.gif'
			}
		}
	}

    var intakeDate = new Array()
    
    intakeDate[0] = 'January 2010' + ''  // jan 2010
    intakeDate[1] = 'July 2010' + ''  // jul 2010
    intakeDate[2] = 'August 2010' + ''  // aug 2010
    intakeDate[3] = 'September 2010' + ''  // sep 2010
    intakeDate[4] = 'November 2010' + ''  // nov 2010
    intakeDate[5] = 'December 2010' + ''  // dec 2010
    intakeDate[6] = 'January 2011' + ''  // jan 2011
    intakeDate[7] = 'April 2011' + ''  // apr 2011
    intakeDate[8] = 'July 2011' + ''  // july 2011
    intakeDate[9] = 'August 2011' + ''  // aug 2011
    intakeDate[10] = 'September 2011' + '' // sep 2011
    intakeDate[11] = 'December 2011' + '' // dec 2011
    intakeDate[12] = 'February 2011' + '' // feb 2011

	switch (selbox) {
		case 'Sdests':
			if (val=='') {break;}
			val=val.split("_")
			cpdk=val[1]+''
			var ctr = 1
			
			val[0] == 'uk'? choiceUK = true : choiceUK = false
			val[0] == 'ireland'? choiceIE = true : choiceIE = false
			val[0] == 'japan'? choiceJP = true : choiceJP = false
			val[0] == 'france' ? choiceFR = true : choiceFR = false
			val[0] == 'germany' ? choiceDE = true : choiceDE = false
			val[0] == 'canada' ? choiceCA = true : choiceCA = false
			val[0] == 'frenchcanada' ? choiceFC = true : choiceFC = false
			val[0] == 'usa' ? choiceUS = true : choiceUS = false
			val[0] == 'australia' ? choiceAU = true : choiceAU = false
			val[0] == 'newzealand' ? choiceNZ = true : choiceNZ = false
			val[0] == 'costarica' ? choiceCR = true : choiceCR = false
			val[0] == 'hongkong' ? choiceHK = true : choiceHK = false
			val[0] == 'thailand' ? choiceTH = true : choiceTH = false
					
			
                for (i=0;i<intakeDate.length;i++) { 

				        if(choiceUK){ // For UK

				            if(i == 2 || i == 9) // Only show August
				            {
			                    document.booking.Sdates.options[ctr] = new Option(intakeDate[i]+'', intakeDate[i]+'')
			                    document.booking.Sdates.options[ctr].className = 'dest'
				            }
				            //needs to be moved to region choices CL
				            
				            else
				            {
				                document.booking.Sdates.options[ctr] = new Option('empty', 'empty')
				                
				            }
				        }
				        else if(choiceIE){ // For Ireland
				        
		                    if(i == 2 || i == 9) // Only show August
		                    {
	                            document.booking.Sdates.options[ctr] = new Option(intakeDate[i]+'', intakeDate[i]+'')
	                            document.booking.Sdates.options[ctr].className = 'dest'
		                    } 
				            else
				            {
				                document.booking.Sdates.options[ctr] = new Option('empty', 'empty')
				                		                    
		                    }
				        }
				        else if(choiceUS) { // for USA (non region)
				            
				            
				            
		                    if(i == 2  || i == 6 || i == 9)
		                    {
	                            document.booking.Sdates.options[ctr] = new Option(intakeDate[i]+'', intakeDate[i]+'')
	                            document.booking.Sdates.options[ctr].className = 'dest'
		                    } 
				            else
				            {
				                document.booking.Sdates.options[ctr] = new Option('empty', 'empty')
				                		                    
		                    }
		                    
				        }
				        else if(choiceCA || choiceFC) { // for Canada (non region)
				        
		                    if(i == 2  || i == 6 || i == 9)
		                    {
	                            document.booking.Sdates.options[ctr] = new Option(intakeDate[i]+'', intakeDate[i]+'')
	                            document.booking.Sdates.options[ctr].className = 'dest'
		                    } 
				            else
				            {
				                document.booking.Sdates.options[ctr] = new Option('empty', 'empty')
				                		                    
		                    }
				        }
				        else if(choiceAU || choiceNZ) { // for Australia or NZ (non region)
				        
		                    if(i == 1  || i == 6 || i == 8)
		                    {
	                            document.booking.Sdates.options[ctr] = new Option(intakeDate[i]+'', intakeDate[i]+'')
	                            document.booking.Sdates.options[ctr].className = 'dest'
		                    } 
				            else
				            {
				                document.booking.Sdates.options[ctr] = new Option('empty', 'empty')
				                		                    
		                    }   
				        }
				        else if(choiceFR || choiceDE) { // France and Germany (non region)
		                    if(i == 2  || i == 6 || i == 9)
		                    {
	                            document.booking.Sdates.options[ctr] = new Option(intakeDate[i]+'', intakeDate[i]+'')
	                            document.booking.Sdates.options[ctr].className = 'dest'
		                    } 
				            else
				            {
				                document.booking.Sdates.options[ctr] = new Option('empty', 'empty')
				                		                    
		                    }
				        }
				        else if(choiceCR) { // Costa Rica (non region)
				        
		                    if(i == 1  || i == 6 || i == 8)
		                    {
	                            document.booking.Sdates.options[ctr] = new Option(intakeDate[i]+'', intakeDate[i]+'')
	                            document.booking.Sdates.options[ctr].className = 'dest'
		                    } 
				            else
				            {
				                document.booking.Sdates.options[ctr] = new Option('empty', 'empty')
				                		                    
		                    }
				        }
				        else if(choiceJP) { // Japan (non region)
				        
		                    if(i == 3  || i == 7 || i == 10)
		                    {
	                            document.booking.Sdates.options[ctr] = new Option(intakeDate[i]+'', intakeDate[i]+'')
	                            document.booking.Sdates.options[ctr].className = 'dest'
		                    } 
				            else
				            {
				                document.booking.Sdates.options[ctr] = new Option('empty', 'empty')
				                		                    
		                    }
				        }
				        else if(choiceHK) { // Hong Kong (non region)
				        
		                    if(i == 2  || i == 6 || i == 9)
		                    {
	                            document.booking.Sdates.options[ctr] = new Option(intakeDate[i]+'', intakeDate[i]+'')
	                            document.booking.Sdates.options[ctr].className = 'dest'
		                    } 
				            else
				            {
				                document.booking.Sdates.options[ctr] = new Option('empty', 'empty')
				                		                    
		                    }
				        }
				        
				        
				        else
				        {
				        	document.booking.Sdates.options[ctr] = new Option(intakeDate[i]+'', intakeDate[i]+'')
				            document.booking.Sdates.options[ctr].className = 'dest'
				        }
				        ctr++;
				        

			    }

			    
			document.booking.Sdates.disabled = (val=='');
			
			document.booking.destination.value = val[0]+'_'+data
			
			cleanupDates();
			
			break;
			
		
		case 'Sregion':
			var ctr = 1
			for (i=0;i<intakeDate.length;i++) {
			
			    if(choiceUS){
			        
			            if (i == 2 || i == 6 || i == 9) {
				            document.booking.Sdates.options[ctr] = new Option(intakeDate[i]+'', intakeDate[i]+'')
				            document.booking.Sdates.options[ctr].className = 'dest'					        
				            ctr++
			            }
			        
			        else
			        {
	                    document.booking.Sdates.options[ctr] = new Option('empty', 'empty')
	                    	
			        }			        
			    }
			    
			    else if(choiceCA || choiceFC){
			        
			            if (i == 2 || i == 6 || i == 9) {
				            document.booking.Sdates.options[ctr] = new Option(intakeDate[i]+'', intakeDate[i]+'')
				            document.booking.Sdates.options[ctr].className = 'dest'					        
				            ctr++
			            }
			        
			        else
			        {
	                    document.booking.Sdates.options[ctr] = new Option('empty', 'empty')
	                    	
			        }
			    }
			    else if(choiceAU || choiceNZ){
			        
			            if (i == 1 || i == 6 || i == 8) {
				            document.booking.Sdates.options[ctr] = new Option(intakeDate[i]+'', intakeDate[i]+'')
				            document.booking.Sdates.options[ctr].className = 'dest'					        
				            ctr++
			            }
			        
			        else
			        {
	                    document.booking.Sdates.options[ctr] = new Option('empty', 'empty')
	                    	
			        }
			    }
			    else if(choiceUK || choiceIE) {
			        
			            if (i == 2 || i == 9) {
				            document.booking.Sdates.options[ctr] = new Option(intakeDate[i]+'', intakeDate[i]+'')
				            document.booking.Sdates.options[ctr].className = 'dest'					        
				            ctr++
			            }
			        
			        else
			        {
	                    document.booking.Sdates.options[ctr] = new Option('empty', 'empty')
	                    	
			        }
			    }
			    else if(choiceFR || choiceDE) {
			        
			            if (i == 2 || i == 6 || i == 9) {
				            document.booking.Sdates.options[ctr] = new Option(intakeDate[i]+'', intakeDate[i]+'')
				            document.booking.Sdates.options[ctr].className = 'dest'					        
				            ctr++
			            }
			        
			        else
			        {
	                    document.booking.Sdates.options[ctr] = new Option('empty', 'empty')
	                    	
			        }
			    			    
            }

			    else if(choiceCR) {	
			        
			            if (i == 1 || i == 6 || i == 8) {
				            document.booking.Sdates.options[ctr] = new Option(intakeDate[i]+'', intakeDate[i]+'')
				            document.booking.Sdates.options[ctr].className = 'dest'					        
				            ctr++
			            }
			        
			        else
			        {
	                    document.booking.Sdates.options[ctr] = new Option('empty', 'empty')
	                    	
			        }
			    			    
            }
            
			    else if(choiceJP) {	
			        
			            if (i == 3 || i == 7 || i == 10) {
				            document.booking.Sdates.options[ctr] = new Option(intakeDate[i]+'', intakeDate[i]+'')
				            document.booking.Sdates.options[ctr].className = 'dest'					        
				            ctr++
			            }
			        
			        else
			        {
	                    document.booking.Sdates.options[ctr] = new Option('empty', 'empty')
	                    	
			        }
			    			    
            }            
            else if(choiceHK) {	
			        
			            if (i == 2 || i == 6 || i == 9) {
				            document.booking.Sdates.options[ctr] = new Option(intakeDate[i]+'', intakeDate[i]+'')
				            document.booking.Sdates.options[ctr].className = 'dest'					        
				            ctr++
			            }
			        
			        else
			        {
	                    document.booking.Sdates.options[ctr] = new Option('empty', 'empty')
	                    	
			        }
			    			    
            }
            else if(choiceTH) {	
			        
			            if (i == 999){ // 
			            //do nothing
			            }
			        
			        else
			        {
	                    document.booking.Sdates.options[ctr] = new Option('empty', 'empty')
	                    	
			        }
			    			    
            }            
            else {
			        //should anything be here ?
			        /*if (i != 0 && i != 1 && i != 3 && i != 5 && i != 6) {
			            document.booking.Sdates.options[ctr] = new Option(intakeDate[i]+'', intakeDate[i]+'')
				        document.booking.Sdates.options[ctr].className = 'dest'			    
				        ctr++
				    }*/
			    }
			}
			
			document.booking.Sdates.disabled = (val=='');
			document.booking.region.value = data;
            
            cleanupDates();
			
			break;
			
		case 'Sdates':	
			var ctr = 1
			for (i=0;i<ln.length;i++) {
			    //if HSY DE show half school year for January 2009 for US, CA, French CA, FR, Costa Rica
		        if (cpdk == 1209 || cpdk == 1205 || cpdk == 1206 || cpdk == 5386) {
		            if (document.booking.Sdates.options[document.booking.Sdates.options.selectedIndex].value == 'January 2009' || document.booking.Sdates.options[document.booking.Sdates.options.selectedIndex].value == 'January 2010') {
		                if (ln[i].length != 'Full Year') { //if halfyear, print
				            document.booking.Slength.options[ctr] = new Option(ln[i].length,ln[i].lid)
				            document.booking.Slength.options[ctr].className = 'dest'
				            ctr++
				        }
				    }else{ //print all school year lengths

				        document.booking.Slength.options[ctr] = new Option(ln[i].length,ln[i].lid)
				            document.booking.Slength.options[ctr].className = 'dest'
				            ctr++
				    }
				
				}else{ //remaining countries
				    if ((choiceUK) && (ln[i].length != 'Half Year')) {
				    //if uk and full year, print
		                document.booking.Slength.options[ctr] = new Option(ln[i].length,ln[i].lid)
			            document.booking.Slength.options[ctr].className = 'dest'
			            ctr++
				    }else if (!choiceUK) { //if not UK, print

				        document.booking.Slength.options[ctr] = new Option(ln[i].length,ln[i].lid)
				        document.booking.Slength.options[ctr].className = 'dest'
				        ctr++
				    }
				}
			}
			document.booking.Slength.disabled = (val=='');
			document.booking.date.value = data;
			break;

		case 'Slength':
			var ctr = 1
			for (i=0; i<dp.length; i++) {
				if (dp[i].lid == cpdk) {
					document.booking.Sdeps.options[ctr] = new Option(dp[i].length,dp[i].lid)
					document.booking.Sdeps.options[ctr].className = 'dest'
					ctr++
				}
			}
			document.booking.Sdeps.disabled = (val=='')

			document.booking.length.value = data;
			break;

		case 'Sdeps':
			var ctr = 1
			for (i=0; i<ci.length; i++) {
				if (ci[i].lid == cpdk) {
					document.booking.Scity.options[ctr] = new Option(ci[i].length,ci[i].lid)
					document.booking.Scity.options[ctr].className = 'dest'
					ctr++
				}
			}
			document.booking.Scity.disabled = (val=='')
			document.booking.departure.value = data;
			break;
			
		case 'Scity':
			document.booking.interview.value = data
			break;

		default:
			break;
	}

	
}

function cleanupDates()
{
	for(j=document.booking.Sdates.options.length-1;j>=0;j--)
	{
	    if(document.booking.Sdates.options[j].value == 'empty'){     
	        document.booking.Sdates.remove(j);
	    }
	}
}

function Validate() {
	retval = true;
	if (document.booking.destination.value+'' == '' || document.booking.destination.value+'' == 'undefined' ||
		document.booking.date.value+'' == ''		|| document.booking.date.value+'' == 'undefined'		||
		document.booking.length.value+'' == ''	|| document.booking.length.value+'' == 'undefined' ||
		document.booking.Scity.value+'' == ''		|| document.booking.departure.value+'' == 'undefined'		||
		document.booking.interview.value+'' == ''	)
		{

		retval = false;
	}
	if (retval) {document.booking.submit();}
}

function getSelIndex(dd,val,txt) {
	drop = eval('document.booking.'+dd)
	retval = 0
	var i;
	for (i=0; i<drop.options.length; i++) {
		if (drop.options[i].value==val && drop.options[i].text==txt) {
			retval = i
		}
	}
	return retval
}

function initialise(de,rg,da,le,dp,ci,Sde,Srg,Sda,Sle,Sdp,Sci) {
	var data = ['de','da','le','dp','ci']
	var pars = ['Sde','Sda','Sle','Sdp','Sci']
	var sels = ['Sdests','Sdates','Slength','Sdeps','Scity']
	for (i=1;i<sels.length;i++) {
		eval('document.booking.'+sels[i]).disabled = true;
	}

	if (Sde != 'undefined' && Sde != '0' && Sde != '') {
		for (ix=0;ix<sels.length;ix++) {
			
			var parm = eval(pars[ix])
			var datum = eval(data[ix])
			var name = sels[ix]
			if (name=="Sregion" || (parm!='undefined' && parm!='')) {
				eval('document.booking.'+name).selectedIndex = getSelIndex(name,parm,datum)
				val(name,parm,datum)
			}
		}
	} else {
		document.booking.Sdests.selectedIndex = 0;
		document.booking.date.value			= ''	
		document.booking.length.value		= ''
		document.booking.interview.value	= ''
		document.booking.region.value		= ''
		document.booking.departure.value	= ''
		document.booking.destination.value	= ''
	}
}

function t(w,h) {
	document.write('<img src="/_imgs/ui/trans.gif" width="'+w+'" height="'+h+'">')
}

function writit(text,id) {
	if (document.getElementById) {
		x = document.getElementById(id);
		x.innerHTML = text;
	} else if (document.all) {
		x = document.all[id];
		x.innerHTML = text;
	} else if (document.layers) {
		x = eval(id);
		x.document.open();
		x.document.write(text);
		x.document.close();
	}
}

