//jquery document.ready function
$(function(){

	//alert("jquery ready!");

        var cook = readCookie('q');
        //alert(cook);

        if (cook != null) {
                var questions = cook.split(",");
       		//alert("q1= " + questions[1] );
       		//alert("qb1= " + questions[24+1] );
       		//alert("qw1= " + questions[32+1] );

		//alert( questions);

		//initialize sliders from cookie
		document.mcq1.slider0.selectedIndex = questions[1]-1;
		document.mcq1.slider1.selectedIndex = questions[2]-1;
		document.mcq1.slider2.selectedIndex = questions[3]-1;
		document.mcq1.slider3.selectedIndex = questions[4]-1;
		document.mcq1.slider4.selectedIndex = questions[5]-1;
		document.mcq1.slider5.selectedIndex = questions[6]-1;

		document.mcq2.slider0.selectedIndex = questions[7]-1;
		document.mcq2.slider1.selectedIndex = questions[8]-1;
		document.mcq2.slider2.selectedIndex = questions[9]-1;
		document.mcq2.slider3.selectedIndex = questions[10]-1;
		document.mcq2.slider4.selectedIndex = questions[11]-1;
		document.mcq2.slider5.selectedIndex = questions[12]-1;

		document.mcq3.slider0.selectedIndex = questions[13]-1;
		document.mcq3.slider1.selectedIndex = questions[14]-1;
		document.mcq3.slider2.selectedIndex = questions[15]-1;
		document.mcq3.slider3.selectedIndex = questions[16]-1;
		document.mcq3.slider4.selectedIndex = questions[17]-1;
		document.mcq3.slider5.selectedIndex = questions[18]-1;

		document.mcq4.slider0.selectedIndex = questions[19]-1;
		document.mcq4.slider1.selectedIndex = questions[20]-1;
		document.mcq4.slider2.selectedIndex = questions[21]-1;
		document.mcq4.slider3.selectedIndex = questions[22]-1;
		document.mcq4.slider4.selectedIndex = questions[23]-1;
		document.mcq4.slider5.selectedIndex = questions[24]-1;
		
		createSliders();
		
		for (i=1; i<25; i++ ) {
			q[i] = questions[i];
		}
		
		//alert( gup('profile') );
                if ( gup('profile') == "y" && questions[24] !=0 ) {
			showProfile();
		}else{
	                show('test1a');
		}

	}else{
		//alert ("cookie is null!");
		createSliders()
		show('test1');
	}
});

var slider00;
var slider01;
var slider02;
var slider03;
var slider04;
var slider05;
var slider06;
var slider07;
var slider08;
var slider09;
var slider10;
var slider11;
var slider12;
var slider13;
var slider14;
var slider15;
var slider16;
var slider17;
var slider18;
var slider19;
var slider20;
var slider21;
var slider22;
var slider23;

//var scriptName = "process.aspx"
var tgt_ = "" //target div for .net script
var q = new Array(24);
//var qb = new Array(8);
//var qw = new Array(8);
var qb = new Array(0,0,0,0,0,0,0,0,0);
var qw = new Array(0,0,0,0,0,0,0,0,0);

function createXMLHttp() {
	var aVer = ["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHTTP"];
  	 // put IE check here
	for (i=0;i<aVer.length ;i++ ) {
		try {
			var XMLHttp = new ActiveXObject(aVer[i]);
			return XMLHttp;
		}
		catch (oError) {
		//do Nothing
		}
	}
	throw new Error("MSXML not installed");
}

function createRequestObject() {
    	var ro;
    	var browser = navigator.appName;
    	if(browser == "Microsoft Internet Explorer"){

		ro = createXMLHttp()

    	}else{
        	ro = new XMLHttpRequest();
    	}
    	return ro;
}

var http = createRequestObject();

getProfile1 = function(tgt, db){

tgt_ = tgt;

//for (i=1; i<25; i++ ) {
//	q[i] = "1";
//}

//for (i=1; i<9; i++ ) {
//	qb[i] = "1";
//	qw[i] = "3";
//}

createCookie('q', "X" + "," + q[1] + "," + q[2] + "," + q[3] + "," + q[4] + "," + q[5] + "," + q[6] + "," + q[7] + "," + q[8] + "," + q[9] + "," + q[10] + "," + q[11] + "," + q[12] + "," + q[13] + "," + q[14] + "," + q[15] + "," + q[16] + "," + q[17] + "," + q[18] + "," + q[19] + "," + q[20] + "," + q[21] + "," + q[22] + "," + q[23] + "," + q[24] + "," + qb[1] + "," +  qb[2] + "," + qb[3] + "," +  qb[4] + "," + qb[5] + "," + qb[6] + "," + qb[7] + "," + qb[8] + "," + qw[1] + "," + qw[2] + "," + qw[3] + "," + qw[4] + "," + qw[5] + "," + qw[6] + "," + qw[7] + "," + qw[8], 0);

        urlstring = "?tgt="+tgt+"&db="+db+"&q1="+q[1]+"&q2="+q[2]+"&q3="+q[3]+"&q4="+q[4]+"&q5="+q[5]+"&q6="+q[6]+"&q7="+q[7]+"&q8="+q[8]+"&q9="+q[9]+"&q10="+q[10]+"&q11="+q[11]+"&q12="+q[12]+"&q13="+q[13]+"&q14="+q[14]+"&q15="+q[15]+"&q16="+q[16]+"&q17="+q[17]+"&q18="+q[18]+"&q19="+q[19]+"&q20="+q[20]+"&q21="+q[21]+"&q22="+q[22]+"&q23="+q[23]+"&q24="+q[24]+"&qb1="+qb[1]+"&qw1="+qw[1]+"&qb2="+qb[2]+"&qw2="+qw[2]+"&qb3="+qb[3]+"&qw3="+qw[3]+"&qb4="+qb[4]+"&qw4="+qw[4]+"&qb5="+qb[5]+"&qw5="+qw[5]+"&qb6="+qb[6]+"&qw6="+qw[6]+"&qb7="+qb[7]+"&qw7="+qw[7]+"&qb8="+qb[8]+"&qw8="+qw[8];
	//alert(urlstring);
	http.open('get',  "getProfile1.aspx" + urlstring, true);
//        http.open('get',  "getProfile1.aspx" +"?q1="+q[1]+"&q2="+q[2]+"&q3="+q[3]+"&q4="+q[4]+"&q5="+q[5]+"&q6="+q[6]+"&q7="+q[7]+"&q8="+q[8]+"&q9="+q[9]+"&q10="+q[10]+"&q11="+q[11]+"&q12="+q[12]+"&q13="+q[13]+"&q14="+q[14]+"&q15="+q[15]+"&q16="+q[16], true);
	http.onreadystatechange = displayMessage2;
	http.send(null);
}

displayMessage2 = function(){

	if (http.readyState == 4) {
		if(http.status != 200){
			alert(http.status);
		}
                document.getElementById(tgt_).innerHTML= http.responseText;
        }
}

createSliders = function() {
		slider00 = $('select#slider00').selectToUISlider().hide();
	        slider01 = $('select#slider01').selectToUISlider().hide();
	        slider02 = $('select#slider02').selectToUISlider().hide();
	        slider03 = $('select#slider03').selectToUISlider().hide();
	        slider04 = $('select#slider04').selectToUISlider().hide();
	        slider05 = $('select#slider05').selectToUISlider().hide();
	        slider06 = $('select#slider06').selectToUISlider().hide();
	        slider07 = $('select#slider07').selectToUISlider().hide();
	        slider08 = $('select#slider08').selectToUISlider().hide();
	        slider09 = $('select#slider09').selectToUISlider().hide();
	        slider10 = $('select#slider10').selectToUISlider().hide();
	        slider11 = $('select#slider11').selectToUISlider().hide();
	        slider12 = $('select#slider12').selectToUISlider().hide();
	        slider13 = $('select#slider13').selectToUISlider().hide();
	        slider14 = $('select#slider14').selectToUISlider().hide();
	        slider15 = $('select#slider15').selectToUISlider().hide();
	        slider16 = $('select#slider16').selectToUISlider().hide();
	        slider17 = $('select#slider17').selectToUISlider().hide();
	        slider18 = $('select#slider18').selectToUISlider().hide();
	        slider19 = $('select#slider19').selectToUISlider().hide();
	        slider20 = $('select#slider20').selectToUISlider().hide();
	        slider21 = $('select#slider21').selectToUISlider().hide();
	        slider22 = $('select#slider22').selectToUISlider().hide();
	        slider23 = $('select#slider23').selectToUISlider().hide();
}

/********************************************************************************
Copyright (C) 1999 Thomas Brattli
This script is made by and copyrighted to Thomas Brattli at www.bratta.com
Visit for more great scripts. This may be used freely as long as this msg is intact!
I will also appriciate any links you could give me.
********************************************************************************/
//Default browsercheck, added to all scripts!
function checkBrowser(){
	this.ver=navigator.appVersion
	this.dom=document.getElementById?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
	return this
}
bw=new checkBrowser()
//Shows the div
function show(div,nest){
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	obj.display='block'
}
//Hides the div
function hide(div,nest){
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	obj.display='none'
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function checkProceed(frm, indx) {

        q[indx] = document[frm].slider0.selectedIndex+1;
        q[indx+1] = document[frm].slider1.selectedIndex+1;
        q[indx+2] = document[frm].slider2.selectedIndex+1;
        q[indx+3] = document[frm].slider3.selectedIndex+1;
        q[indx+4] = document[frm].slider4.selectedIndex+1;
        q[indx+5] = document[frm].slider5.selectedIndex+1;
}

function myBodyOnload() {
	
	//alert("myBodyOnload");
	//writeCSS('http://www.raf.mod.uk/careers/');

}

function showProfile(log) {
        if (log == undefined) { log = 0; }
        if (log != 1) { log = 0; }
        //alert(log);
        document.getElementById('test3a').innerHTML="<p><br>Generating personality profile, please wait ...</p>";
        show('test3a');
//        alert("qw8=" & qw[8]);
	getProfile1('test3a',log);
}

function gup( name )
{
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}

<!-- Begin Sitestat4 Flash code -->
function ns_send(ns_tag){
  
  return; // ************* debug

  var ns_flash="http://uk.sitestat.com/raf/rafcareers/s?"+ns_tag;
  document.ns_p.src=ns_flash;
}
<!-- End Sitestat4 Flash code -->