var currentVideoSub = 'videoInfo';
var currentCPD = 'cpdLogin';
var ltcStatus = 0;
var vscStatus = 0;
var etcStatus = 0;
var currentSorted = 1;
var currentPage = 0;
var currentProjectMenu = 1;
var slideImage = 'image1';
var intervalId;
var homeIntervalId;
var currentSlide = 1;
var totalSlides = 0;



function goBack(){
	//parent.history.back();
        window.history.back(-1);
}


function filterBlog(type){
    
          
           $.ajax({
               type: "GET",
               url:"/ajax/setBlogFilter",
               data:"filter="+type,
               error:function (xhr, ajaxOptions, thrownError){
                    alert(thrownError);
                },
               success: function(qResult){
                  window.location.reload();

         }});
           
         
      
}

function checkCompanyByEmail(email){
    //console.log(email);
     $.ajax({
           type: "GET",
           url:"/ajax/checkCompanyByEmail",
           data:"email="+email,
           error:function (xhr, ajaxOptions, thrownError){
                alert(thrownError);
            },
           success: function(qResult){
               if(jQuery.trim(qResult) !=""){
                   
                    $("#table1button").hide();
                    $("#table1button").slideDown();

                     $("#table2").slideUp();
                    $("#companyHolder").html("<b>"+jQuery.trim(qResult)+"</b>");
               }else{
                  
                   $("#companyHolder").html("<input type=\"hidden\" name=\"companyId\" id=\"companyId\" value=\"0\" />");
                
                   
               }

     }});
}

function rolloverProjectMenu(imageUrl, imageNumber){
    $("#projectMenu_"+imageNumber).attr('src',imageUrl);
}
function rolloutProjectMenu(imageUrl, imageNumber){
    if(imageNumber!=currentProjectMenu){
        $("#projectMenu_"+imageNumber).attr('src',imageUrl);
    }
}
function slideHomeImage(slides,urls){
    var newSlideImage;
    
    if(slideImage == "image1"){
        newSlideImage = "image2";
    }else{
        newSlideImage = "image1";
    }
    $("#"+slideImage).fadeOut('slow', function() {
    // Animation complete.


    });

    $("#"+newSlideImage).html("<a href=\""+urls[currentSlide]+"\"><img src=\""+slides[currentSlide]+"\" border=\"0\" /></a>");
    $("#"+newSlideImage).fadeIn('slow', function() {
        slideImage = newSlideImage;
    });
    if(currentSlide == totalSlides-1){
        currentSlide = 0;
    }else{
        currentSlide++;
    }
}
function slideProjectImage(imageUrl){
    //console.log(currentProjectMenu);
    if(currentProjectMenu == 0){

        $("#projectMenu_5").attr('src','/media/images/projectImageMenu_5.png');
    }
    if(currentProjectMenu == 4){
         $("#projectMenu_5").attr('src','/media/images/projectImageMenu_5_o.png');
         $("#projectMenu_"+(currentProjectMenu)).attr('src','/media/images/projectImageMenu_'+(currentProjectMenu)+'.png');
         currentProjectMenu = 0;
    }else{
        $("#projectMenu_"+(currentProjectMenu)).attr('src','/media/images/projectImageMenu_'+(currentProjectMenu)+'.png');
        currentProjectMenu++;
    }
    
   
   
    changeProjectImage(imageUrl,currentProjectMenu);


}

function stopSlideProjectImage(imageUrl,imageNumber){
    clearInterval(intervalId);
    changeProjectImage(imageUrl,imageNumber);

}
function changeProjectImage(imageUrl,imageNumber){
    $("#projectMenu_"+currentProjectMenu).attr('src','/media/images/projectImageMenu_'+currentProjectMenu+'.png');
    currentProjectMenu = imageNumber;
    var newSlideImage;
    if(slideImage == "image1"){
        newSlideImage = "image2";
    }else{
        newSlideImage = "image1";
    }
    $("#"+slideImage).fadeOut('slow', function() {
    // Animation complete.
        
        
    });
    $("#"+newSlideImage).html("<img src=\"/"+imageUrl+"\" />");
    $("#"+newSlideImage).fadeIn('slow', function() {
        slideImage = newSlideImage;
    });
    //console.log($("#projectMenu_"+imageNumber).attr('src'));
    $("#projectMenu_"+imageNumber).attr('src','/media/images/projectImageMenu_'+imageNumber+'_o.png');

}
function resetCompanyCheckButton(){
    if($("#table1button").css("display")=="none"){
        $("#table1button").slideDown();
    }
}

function checkNewUser(){
	var status = 1;
	var message = 'Please fill all fields in.';

        if($("#cpdregtitle").val().length == 0){
		status = 0;
	}
	if($("#cpdregforename").val().length == 0){
		status = 0;
	}
        if($("#cpdregsurname").val().length == 0){
		status = 0;
	}
	/*if($("#cpdregusername").val().length == 0){
		status = 0;
	}
	if($("#cpdregpassword").val().length == 0){
		status = 0;
	}
	if($("#cpdregrepassword").val().length == 0){
		status = 0;
	}
	if($("#cpdregpassword").val()!= $("#cpdregrepassword").val()){
		status = 0;
		message = 'The passwords you have entered do not match. Please try again.';
	}
*/
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        var address = $("#cpdregusername").val();
        if(reg.test(address) == false){
		status = 0;
		message = 'The email address is not valid.';
	}else{
            checkCompanyByEmail(address);
        }

	if(status == 1){

		return(false);
	}else{
		alert(message);
		return(false);
	}
}


function displayCourseResources(id){
    if($("#courseRes_"+id).css("display")=="none"){
        $.ajax({
               type: "GET",
               url:"/ajax/getCourseResources",
               data:"cid="+id,
               error:function (xhr, ajaxOptions, thrownError){
                    alert(thrownError);
                },
               success: function(qResult){
                   $("#courseRes_"+id).html(qResult).slideDown();

         }});
    }else{
        $("#courseRes_"+id).slideUp();
    }
}

function openLoginWindow(){
    $("#fadePage").fadeIn('fast');
    $("#loginWindow").fadeIn('fast');
}

function closeWindow(){
    $("#fadePage").hide();
    $("#loginWindow").hide();
}
function closeQuestion(){
    $("#fadePage").hide();
    $("#questionWindow").hide();

}
function closeCertificate(){
    $("#fadePage").hide();
    $("#certificateWindow").hide();

}
function questionPassed(vid,cid){
    closeQuestion();
   vidRefresh(cid);
}
function questionFailed(vid,cid){
    closeQuestion();
    vidRefresh(cid);
     question(vid,cid);
}

function certificate(uid,cid){
     $("#fadePage").fadeIn('fast');
     $("#certificateWindow").fadeIn('fast');

     $.ajax({
           type: "GET",
           url:"/ajax/getCertificate",
           data:"cid="+cid+"&uid="+uid,
           error:function (xhr, ajaxOptions, thrownError){
                alert(thrownError);
            },
           success: function(qResult){
               $("#certificateContent").html(qResult).fadeIn('fast');

     }});
}

function question(vid,cid){
    $("#fadePage").fadeIn('fast');
    $("#questionWindow").fadeIn('fast');

    $.ajax({
           type: "GET",
           url:"/ajax/getQuestionnaire",
           data:"cid="+cid+"&vid="+vid,
           error:function (xhr, ajaxOptions, thrownError){
                alert(thrownError);
            },
           success: function(qResult){
               $("#questionContent").html(qResult).fadeIn('fast');
            

     }});
}

function processQuestionnaire(){
   $.ajax({
          type: 'POST',
          url: "/ajax/processQuestionnaire",
          data: $("#questionForm").serialize(),
          success: function(data, textStatus, XMLHttpRequest){
            
             $("#questionContent").html(data).fadeIn('fast');
          }
    });
    return(false);
}

function selectintout(divId){
    
    if($("#"+divId+" input").attr('checked')){
       
        $("#"+divId).addClass('intouton');
    }else{
      
         $("#"+divId).removeClass('intouton');
    }
}

function switchOffDiv(divId){
	$("#"+divId).fadeOut('fast');
}

function hideDiv(divId){
	$("#"+divId).fadeOut('fast');	
}
function showDiv(divId){
	$("#"+divId).fadeIn('fast');	
}

function toggleDiv(divId){
	$("#"+divId).toggle();	
}

function pagerNext(){
	if(currentPage < totalPageCount-1){ 							
		sortVideoList(currentSorted, ++currentPage);
		$("#currentPage").html(currentPage+1);
		$("#currentPage2").html(currentPage+1);
	}
}

function pagerPrev(){
	if(currentPage > 0){ 									
		sortVideoList(currentSorted, --currentPage);
		$("#currentPage").html(currentPage+1);
		$("#currentPage2").html(currentPage+1);
	}
}



function forceDivClose(divId){
	$('#'+divId).fadeOut('fast');
}

function vidRefresh(id){
   
    $.ajax({
		   type: "GET",
		   url:"/ajax/getVideoList",
		   data:"catId="+id,

		   error:function (xhr, ajaxOptions, thrownError){

                            alert(thrownError);
                    },

	   	   success: function(videos){

                       $("#columnThreeContent").html(videos);
                      // $("#columnOne li").removeClass('menuon');
                        $("#columnTwo li").removeClass('menuon');
                        $("#cat_"+id).addClass('menuon');
                       // console.log($("#cat_"+id).attr("class"));


	 }});
     
}


function setupVideoPlayer(flvCode,ipad,videoTitle){

        
       function cuePoint(){
                var time;
                var image;
        }
        var cuePoints = new Array();
        var cueBufferStore = new Array();

      
        var netUrl = "rtmp://mydeo.fcod.llnwd.net/a584/o24/32sqb/";

        var provider = "rtmp";
        
      //  console.log('loadedPlayer');
       if(ipad==true){
            document.getElementById("ipadPlayer").style.display = 'block';
            document.getElementById("videoPlayer").style.display = 'none';

            $f("ipadPlayer",
                {src:"/media/javascript/flowplayer/flowplayer.commercial-3.2.7.swf"},{
                    key:'#$8bf7a140cbe3351a5e5',
                 onLoad: function() {

                 }
                  }).ipad();
       }else{
           $f('videoPlayer', {src:"/media/javascript/flowplayer/flowplayer.commercial-3.2.7.swf", wmode:'transparent'},  {

                key:'#$8bf7a140cbe3351a5e5',
                onLoad: function() {

                    //console.log('loadedPlayer');
                },
                onPause: function(){
                    this.pause();
                },
                // don't start automcatically
                clip: {
                        autoPlay: true,
                        autoBuffering: true ,
                        fullscreen: true,
                        backgroundColor: '#FFFFFF'
                        
                },
                canvas:  {
                    // configure background properties
                    backgroundColor: '#FFFFFF',

                    // remove default canvas gradient
                    backgroundGradient: 'none'

	
                },



                        // disable default controls
                   plugins: {
                       // remove this to display default player.

                       controls: {
                                url: 'flowplayer.controls-3.2.5.swf',

                                backgroundColor: "#000",
                                backgroundGradient: "none",
                                sliderColor: '#FFFFFF',
                                sliderBorder: '1.5px solid rgba(160,160,160,0.7)',
                                volumeSliderColor: '#FFFFFF',
                                volumeBorder: '1.5px solid rgba(160,160,160,0.7)',
                                autoHide: true,
                                timeColor: '#ffffff',
                                durationColor: '#d1d1d1',
                                fullscreen: true,
                                tooltipColor: 'rgba(255, 255, 255, 0.7)',
                                tooltipTextColor: '#000000'
                        },

                   // here is our rtpm plugin configuration

                          rtmp: {
                                url: '/media/javascript/flowplayer/flowplayer.rtmp-3.1.3.swf',netConnectionUrl: 'rtmp://mydeo.fcod.llnwd.net/a584/o24/32sqb/'

                                // netConnectionUrl defines where the streams are found
                                //netConnectionUrl: 'rtmp://cyzy7r959.rtmphost.com/flowplayer'

                          }

                        } ,

                        playlist: [
                            { //clip2
                          
                          url: 'rtmp://mydeo.fcod.llnwd.net/a584/o24/32sqb/inclusive/preroll', //doesn't need .flv suffix
                          autoPlay: true,
                          scaling: 'orig',
                         
                         bufferLength: 1
                          
                          
                        },
                           { //clip 1
                          provider: provider,
                          netConnectionUrl: netUrl,
                          url: flvCode, //doesn't need .flv suffix
                          autoPlay: true,
                          autoBuffering: true,
                          
                          isPostroll:true,
                          onStart: function (clip) {
                                    try{
                                           
                                           // $("#playerInfoMenu").hide();
                                            _gaq.push(['_trackEvent', 'Videos', 'Start', videoTitle]);
                                       } catch(err) {}
                          }
                          
                        }
                        
                        
                        
                         
                        
                        
                        // more clips
                  ]


                // install HTML controls inside element whose id is "hulu"  // remove this to display default player.
            });
       }
        $f().play();


}
function catRefresh(id,cId){
        
	$.ajax({
		   type: "GET",
		   url:"/ajax/getCategories",
		   data:"catId="+id,
		 
		   error:function (xhr, ajaxOptions, thrownError){
				
                            alert(thrownError);
                    },

	   	   success: function(categories){
                      
                        $("#columnTwoContent").html(categories);
                       
                        $("#columnOne li").removeClass('c1menuon');
                        $("#columnTwo li").removeClass('menuon');
                        $("#cat_"+id).addClass('c1menuon');
                        // console.log($("#cat_"+id).attr("class"));
                        if(cId ==null){
                            if($("#columnTwoContent ul").children().size() > 0){
                                var firstEl = $("#columnTwoContent li:first-child").attr("id");
                                // console.log(firstEl);
                                var firstElId = firstEl.replace("cat_","");

                                vidRefresh(firstElId);
                            }
                        }else{
                            vidRefresh(cId);
                        }
				
	 }});
    
	
}



function alertBoxContinue(){
	$("#alertBox").fadeOut();	
	$.scrollTo( $('#videoControls'),800 );
}

function backtoVideoList()
{
	document.location.href='/';	
}

function sortVideoList(type, pos){
	//$("#videoSorted").fadeIn('fast').html("<img src=\"../../media/images/loader.gif\" /> Loading... ");	
	$.ajax({
		   type: "GET",
		   url:"/ajax/getSortedVideo",
		   data:"type="+type+"&pos="+pos,
		  
		   error:function (xhr, ajaxOptions, thrownError){
				
				$("#videoSorted").html("<p>A problem has occured. Please try re-loading the page.</p>");
			},

	   	   success: function(videos){
				$("#videoSorted").html(videos);
				
					//console.log(videos);
				
				
	 }});
	
}

function searchByCat(id){
	var d = new Date();
	var t = d.getTime();
	$.ajax({
		   type: "GET",
		   url:"/ajax/getCategorisedVideo",
		   data:"catId="+id+"&cache="+t,
		  
		   error:function (xhr, ajaxOptions, thrownError){
				
				alert(thrownError);
			},

	   	   success: function(videos){
			  
			  	searchOff('vsc'); 
				searchOff('ltc');
				searchOff('etc');
				document.getElementById("vsc").style.display = 'none';
				document.getElementById("ltc").style.display = 'none';
				document.getElementById("etc").style.display = 'none';
				$("#videoItemsNew").fadeOut('fast');
				$("#videoItemsPop").fadeOut('fast');
				  //$("#historyItems").fadeOut('fast');
				$("#videoItems").fadeIn('fast').html(videos);
				
				$("#RSMVideoList").fadeIn('fast');
                                $("#rsmVideoHome_top").fadeIn('fast');

				
					//console.log(videos);
				
				
	 }});
	
}

function searchByCPD(){
	var d = new Date();
	var t = d.getTime();
	$.ajax({
		   type: "GET",
		   url:"/ajax/getCPDVideo",
		   data:"catId=0&cache="+t,

		   error:function (xhr, ajaxOptions, thrownError){

				alert(thrownError);
			},

	   	   success: function(videos){

			  	searchOff('vsc');
				searchOff('ltc');
				searchOff('etc');
				document.getElementById("vsc").style.display = 'none';
				document.getElementById("ltc").style.display = 'none';
				document.getElementById("etc").style.display = 'none';
				$("#videoItemsNew").fadeOut('fast');
				$("#videoItemsPop").fadeOut('fast');
				  //$("#historyItems").fadeOut('fast');
				$("#videoItems").fadeIn('fast').html(videos);

				$("#RSMVideoList").fadeIn('fast');
                                $("#rsmVideoHome_top").fadeIn('fast');


					//console.log(videos);


	 }});

}

function showPopup(action, userid) {
	$('#popup').animate({
    	opacity: 0.7
	});
	document.getElementById('popup').style.display = 'block';
	$('#window').fadeIn('fast');
	return false;
}
function closePopup() {
	$('#popup').fadeOut('fast');
	$('#window').fadeOut('fast');
}


function searchVideos()
{
    var searchString = $("#videoSearch1").val();
   // console.log("search terms"+searchString);
	if(searchString != ''){
		$.ajax({
		   type: "POST",
		   url:"/ajax/getSearchVideo",
		   data:"searchTerms="+searchString,
		  
		   error:function (xhr, ajaxOptions, thrownError){
				
				alert("error = "+thrownError);
			},

	   	   success: function(videos){
			  
			    	
				
				$("#videoItems").fadeIn('fast').html(videos);
				if(searchString != ''){
				  $("#historyItems").fadeOut('fast');
				  $("#videoItemsNew").fadeOut('fast');
				  $("#videoItemsPop").fadeOut('fast');
				  
				}else{
				  backtoVideoList();
				}
				$("#RSMVideoList").fadeIn('fast');
                                $("#rsmVideoHome_top").fadeIn('fast');
					//console.log(videos);
				
				
	 	}});
	}else{
		 backtoVideoList();
	}
	return (false);
}



function checkLogin(form){
	
	document.getElementById("memberLoading").style.display = 'block';
	$.ajax({
	   type: "POST",
	   url: "/ajax/memberLogin",
	   data: "username="+form.username.value+"&password="+form.password.value,
	   cache: false,
	   async:false,
	   dataType:'json',
	   error: function(e, textStatus, errorThrown){
        alert("error:" + e+':'+textStatus+':'+errorThrown);
       }, 
	   success: function(res, textStatus, XMLHttpRequest){
		   	
			// console.log(res.data[0].type+':'+res.responseText+':'+textStatus+':'+XMLHttpRequest);
			 if(res.data[0].type == '1'){
				 $('#loggedin').fadeIn('fast');
				 $('#loggedout').fadeOut('fast');
				 $("#memberLoading").fadeOut('fast');
				 closePopup();
				 $.scrollTo( $('#videoInfoLinks'),800 );
			 }else{
				 $("#memberLoading").fadeOut('fast');
				 alert('Incorrect login details');	 
			 }
	   }
	});
	
	/*
	 $('#loggedin').fadeIn('fast');
	 $('#loggedout').fadeOut('fast');
	 closePopup();
	*/
	return (false);		
}

function videoTabView(divId){
	//alert(divId+":"+videoId+":"+cpdAccountStatus);
	
	$('#'+divId+'_menu').addClass('active');
	$('#'+currentVideoSub+'_menu').removeClass('active');	

	$('#'+currentVideoSub).hide();
	currentVideoSub = divId;
	$('#'+divId).fadeIn('slow');
	
	
}

function cpdAccountMenu(divId,videoId){
	// turn off cpdAccount

	document.location.href="/videoPlayer/?vid="+videoId+"&submenu=cpd&cpdStage="+divId+"&cpdAccount=1&cpdpq=1";
	
	/*
	$('#'+divId+'_link').addClass('active');
	$('#'+divId+'_list').addClass('active');
	$('#'+currentCPD+'_link').removeClass('active');
	$('#'+currentCPD+'_list').removeClass('active');	
	$('#'+currentCPD).hide();
	currentCPD = divId;
	$('#'+divId).fadeIn('fast');
	*/
}

function cpdMenu(divId,videoId){
		
		$('#aboutCPD').hide();
		$('#faq').hide();
		$.ajax({
			   type: "GET",
			   url:"/ajax/checkLoginStatus/?video_id="+videoId,
			   error:function (xhr, ajaxOptions, thrownError){
					
					alert(thrownError);
				},
	
			   success: function(loginStatus){
					var status = jQuery.trim(loginStatus);
					
					if(status!=0 ){
						if(status == divId){
							$('#'+divId+'_li').addClass('active');
							$('#'+divId+'_li').effect("pulsate", { times:3 }, 1000);
							//$('#'+divId+'_list').addClass('active');
							$('#'+currentCPD+'_li').removeClass('active');
							//$('#'+currentCPD+'_list').removeClass('active');	
							$('#'+currentCPD).hide();
							currentCPD = divId;
							$('#'+divId).fadeIn('fast');
							//$.scrollTo( $('#videoInfoLinks'),800 );
						}else{
							if(divId == 'cpdAccount'){
								$('#cpd_colLeft').hide();
								$('#cpd_colRight').hide();
								
								
								$('#cpdAccount').fadeIn('fast');
								
							}else{
                                                            alert('You must complete the current step before moving on');
                                                        }
						}
					}else{
						alert('You must login to access this content');	
					}
						
					
		 }});
	
	
}

function cpdMenu2(divId){
	
	$('#'+divId+'_li').addClass('active');
	$('#'+divId+'_li').effect("pulsate", { times:3 }, 1000);
	//$('#'+divId+'_list').addClass('active');
	$('#'+currentCPD+'_li').removeClass('active');
	//$('#'+currentCPD+'_list').removeClass('active');
	$('#cpdLogin').hide();
	$('#'+currentCPD).hide();
	currentCPD = divId;
	$('#'+divId).fadeIn('fast');	
}



function checkcpdEval()
{
	var status = 1;	
	var btn1 = $("input[name=eval1]");
	var btn2 = $("input[name=eval2]");
	var btn3 = $("input[name=eval3]");
	var btn4 = $("input[name=eval4]");
	var patt ='/undefined/i';
	var tempStat = 0;	
	if(patt.match($("input[name=eval1]:checked").val()) != 'undefined'){
		//status = 1;	
	}else{
		status = 0;	
	}
	if(patt.match($("input[name=eval2]:checked").val()) != 'undefined'){
		//status = 1;	
	}else{
		status = 0;		
	}
	if(patt.match($("input[name=eval3]:checked").val()) != 'undefined'){
		//status = 1;	
	}else{
		status = 0;		
	}
	if(patt.match($("input[name=eval4]:checked").val()) != 'undefined'){
		//status = 1;	
	}else{
		status = 0;		
	}
	
	if(status == 1){
		return(true);	
	}else{
		alert('You need to evaluate all questions of this module.');	
		return(false);		
	}
	
}

function checkcpdLogin()
{
	var status = 1;

	if($("#cpdloginconfirm:checked").val() != 'on'){
		status = 0; 	
	}
	/*if($("#cpdloginname").val().length == 0){
		status = 0; 	
	}
    */
	if($("#cpdloginusername").val().length == 0){
		status = 0;	
	}
	if($("#cpdloginpassword").val().length == 0){
		status = 0;	
	}
	if(status == 1){
		$("#cpdmemberLoading").fadeIn('fast');
		return(true);	
	}else{
		alert('Please fill all fields in.');
		return(false);		
	}
	
}

function checkcpdNotes(){
	var status = 1;
	
	var string1 = $("#note1").val();
	var count1 = (1+ string1.split(" ").length);
	
	var string2 = $("#note2").val();
	var count2 = (1+ string2.split(" ").length);
	
	var string3 = $("#note3").val();
	var count3 = (1+ string3.split(" ").length);
	/*
	if(string1.length < 100 || string1 == ""){
		status = 0; 	
	}
	if(string2.length < 100 || string2 == ""){
		status = 0;	
	}
	if(string3.length < 100 || string3 == ""){
		status = 0;
	}
	*/
	if(count1 < 50){
		status = 0; 	
	}
	if(count2 < 50 ){
		status = 0;	
	}
	if(count3 < 50 ){
		status = 0;
	}
	
	if(status == 1){
		return(true);	
	}else{
		alert('You need to write a minimum of 50 words in each panel.');	
		return(false);		
	}
}
function checkcpdQuestions(){
	var status = 0;
	var tempStat = 0;
	var patt ='/undefined/i';
	
	
	for (var i = 0; i < $("#questions").attr("count"); i++) {
														
		tempStat = 0;	
		if(patt.match($("#answer_"+i+"_a:checked").val()) != 'undefined'){	
			
			tempStat = 1;
		}
		if(patt.match($("#answer_"+i+"_b:checked").val()) != 'undefined'){	
			
			tempStat = 1;
		}
		if(patt.match($("#answer_"+i+"_c:checked").val()) != 'undefined'){	
			
			tempStat = 1;
		}
		if(patt.match($("#answer_"+i+"_d:checked").val()) != 'undefined'){	
			
			tempStat = 1;	
		}
		
		if(tempStat == 0){
			alert("You must answer all questions");	
			return(false);	
		}else{
				
		}
		
	}
	
	return(true);	
}

function printCPDCertificate(server){
	var certCont = $("#certificate").html();	
	var oNewDoc = window.open('','RecipeWindow','width=600,height=450');
	oNewDoc.document.open();
    oNewDoc.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\"><head><title>RSM accreditated CPD Module Certificate</title><link rel=\"stylesheet\" type=\"text/css\" href=\""+server+"media/css/rsmstyle.css\" /><link rel=\"stylesheet\" type=\"text/css\" href=\""+server+"media/css/print.css\" /></head><body style=\"background-image:none;background-color:#fff;\" onload=\"window.print();\"><div id=\"certificate\">"+certCont+"</div></body></html>");
    oNewDoc.document.close();


}

function loadCPDPage(divId)
{
	$('#cpdLogin').hide();
	$('#cpdPreQuestion').hide();
	$('#cpdPostQuestion').hide();
	$('#viewLecture').hide();
	$('#cpdNotes').hide();
	$('#cpdEval').hide();
	$('#cpdCertificate').hide();
	
	$('#'+divId).fadeIn('fast');	
	
}


// JavaScript Document
/*
function init(){
	//new Resizable('columnOne', {constraint:'horizontal', onResize:updateColOne});
	//new Resizable('header', {constraint:'vertical'});
	
	//preloadImages();
	//enableDraggableItems();
	//preloadMenuList();
	//enableSortableList();
}
*/



function ajaxFormProcess(processPage)
{
	new Ajax.Request(processPage, {
			method: "post",
			parameters:$('menuItem').serialize(true), 
			onComplete:function(transport){
				new Effect.Fade('item_'+transport.responseText);
				messageDisplay(1);
				new Effect.Fade('pageSettings');
			}, 
			evalScripts:true
	});
	
}

function ajaxFormProcessAdd(processPage)
{
	new Ajax.Request(processPage, {
			method: "post",
			parameters:$('menuItem').serialize(true), 
			onComplete:function(transport){
			
				//new Effect.Fade('item_'+transport.responseText);
				new Effect.Fade('pageSettings');
				pageDisplay(transport.responseText);
				
			},
			evalScripts:true
	});
	
}

function messageDisplay(messageId)
{
	// <![CDATA[	
	
	var ajax;
	var d = new Date();
	var t = d.getTime();
	$('pageForms').style.display = 'block';
	$('pageForms').innerHTML = '<br /><img src="images/loader.gif" /> Loading...';
	ajax =  new Ajax.Updater(
		 'pageForms',  
		 'ajax/formMessage.php?t='+t+'&id='+messageId);
	// ]]>
}
function enableSortableList()
{
	
	Sortable.create('items_list0',{tree:true,dropOnEmpty: false, containment: 'items_list0', constraint: false,scrollSensitivity:0,scrollSpeed:0,ghosting:true,hoverclass:'menuHover',
		onChange:function(a,b,c) { },
		onUpdate: function() {
			new Ajax.Request("ajax/saveSort.php", {
			method: "post",
			parameters: { data: Sortable.serialize('items_list0') }
		});
	}});
}

function preloadImages()
{
	image1 = new Image();
	image1.src = "images/liArrow2.gif";
	image2 = new Image();
	image2.src = "images/message2.gif";
	image3 = new Image();
	image3.src = "images/deletePage2.gif";
	image4 = new Image();
	image4.src = "images/pageSettings2.gif";
	image5 = new Image();
	image5.src = "images/addSubMenu2.gif";
	image6 = new Image();
	image6.src = "images/deletePage.gif";
	image7 = new Image();
	image7.src = "images/pageSettings.gif";
	
}

function preloadMenuList(id)
{
	
	var listObj = $('items_list'+id);
	var childCount = listObj.childNodes.length;
	
	var listOptions= '';
	for(var i=0;i<childCount;i++){
		//startPos = listObj.childNodes[i].id.indexOf('_')+1;
		
		//menuId = listObj.childNodes[i].id.substr(startPos);
		//alert(listObj.childNodes[i].innerHTML);
		//listOptions += menuId +' ';
		//openMenuList(menuId,'tertiaryMenuItems_'+menuId);
	}
	
	
	//alert(listOptions);
	//enableSortableList();
}

function redirect(url)
{
	document.location.href=url;
}

function deleteSubMenu(pageid)
{
	// <![CDATA[	
	
	var ajax;
	var d = new Date();
	var t = d.getTime();
	$('pageForms').style.display = 'block';
	$('pageForms').innerHTML = '<br /><img src="images/loader.gif" /> Loading...';
	ajax =  new Ajax.Updater(
		 'pageForms',  
		 'ajax/menuDelete.php?t='+t,{
			method: "post",
			parameters: { 'pageid': pageid },
			asynchronous:true, onComplete:showPageForms});
	// ]]>
	
}


function addSubMenu(pageid)
{
	// <![CDATA[	
	
	var ajax;
	var d = new Date();
	var t = d.getTime();
	$('pageForms').style.display = 'block';
	$('pageForms').innerHTML = '<br /><img src="images/loader.gif" /> Loading...';
	ajax =  new Ajax.Updater(
		 'pageForms',  
		 'ajax/pageForms.php?t='+t,{
			method: "post",
			parameters: { 'pageid': pageid },
			asynchronous:true, onComplete:showPageForms});
	// ]]>	
	
}

function showPageForms()
{
	new Effect.Appear('pageForms');
}

function pageDisplay(pageid)
{
	
	$.ajax({
		   type: "POST",
		   url: "index.php/ajax/retrieve",
		   data: "id="+pageid,
		   success: function(msg){
		     
		     $('#columnTwo').html(msg);
		   }
	});
	// <![CDATA[	
	/*
	var ajax;
	var d = new Date();
	var t = d.getTime();
	new Effect.Appear('columnTwo');
	ajax =  new Ajax.Updater(
		 'columnTwo',  
		 'ajax/pageContent.php?t='+t,{
			method: "post",
			parameters: { 'pageid': pageid },
			asynchronous:true});
	// ]]>	
	*/
}

var currentSubMenu = '';
var subMenus = new Array();
var subMenuIterator = 0;
var workingMenu ='';

function toggleListMenu(id, divName)
{
	var divId = divName+id;
	//togglePageDetails(id, divId);
	// <![CDATA[
	
	if(workingMenu != divId){
		workingMenu = divId;
		currentSubMenu = subMenuIterator;
		subMenus[subMenuIterator++] = divId; 
		var subMenuIndex = subMenus.indexOf(divId);
		if(subMenuIndex == -1){
			if($(divId).style.display == 'none'){
				showSubMenu();
			}else{
				setTimeout(allowMenuProcess,1001);
				new Effect.BlindUp(divId);
				
			}
		}else{
			currentSubMenu = subMenuIndex;
			if($(divId).style.display == 'none'){
				
				showSubMenu();
			}else{
				setTimeout(allowMenuProcess,1001);
				new Effect.BlindUp(divId);
				
			}
		}
		
	
	}else{
		//alert('just bloody wait');	
	}
	// ]]>	
}


function togglePageDetails(pageId, divId)
{
	
	// <![CDATA[
	
		pageDisplay(pageId);
		var ajax;
		var d = new Date();
		var t = d.getTime();
		var subMenuIndex = subMenus.indexOf(divId);
		
		if($(divId).style.display == 'none'){
			/*
			ajax =  new Ajax.Updater(
				 divId,        		// DIV id must be declared before the method was called
				 'ajax/menu.php?parentId='+parentId+'&t='+t,{method:'get',asynchronous:true, onComplete:showSubMenu});
			*/
			new Effect.BlindDown(divId);
		}else{
			
			new Effect.BlindUp(divId);
			
		}

	
	
	// ]]>	
}

function openMenuList(parentId, divId){
	// <![CDATA[
	
	if(workingMenu != divId){
		workingMenu = divId;
		var ajax;
		var d = new Date();
		var t = d.getTime();
		var subMenuIndex = subMenus.indexOf(divId);
		if(subMenuIndex == -1){
			if($(divId).style.display == 'none'){
				
				ajax =  new Ajax.Updater(
					 divId,        		// DIV id must be declared before the method was called
					 'ajax/menu.php?parentId='+parentId+'&t='+t,{method:'get',asynchronous:true, onComplete:showSubMenu});
			}else{
				setTimeout(allowMenuProcess,1001);
				new Effect.BlindUp(divId);
				
			}
		}else{
			currentSubMenu = subMenuIndex;
			if($(divId).style.display == 'none'){
				
				showSubMenu();
			}else{
				setTimeout(allowMenuProcess,1001);
				new Effect.BlindUp(divId);
				
			}
		}
		currentSubMenu = subMenuIterator;
		subMenus[subMenuIterator++] = divId; 
	
	}else{
		//alert('just bloody wait');	
	}
	// ]]>	
}

function allowMenuProcess()
{
	//alert(workingMenu);
	workingMenu = '';	
}


function showSubMenu()
{
	setTimeout(allowMenuProcess,1001);	
	new Effect.BlindDown(subMenus[currentSubMenu]);
	
}


function toggleRightMenu()
{
	if($('columnTwo').style.width =='5px'){
		$('rightMenuControl').style.backgroundImage = 'url(images/rightMenuControl.gif)';
		$('rightSide').style.display = 'block';
		$('columnTwo').style.width = "346px";
		$('columnOne').style.width = "551px";
		$('map').style.width = "570px";
	}else{
		$('rightMenuControl').style.backgroundImage = 'url(images/rightMenuControl_.gif)';
		$('rightSide').style.display = 'none';
		$('columnTwo').style.width = "5px";
		$('map').style.width = "878px";
		$('columnOne').style.width = "878px";
	}
	
}

function successHideRightSide()
{
	alert($('rightSide').style.display);
}




function updateColOne(resizable, event){
	var delta = resizable.currentDelta();
	$('columnTwo').style.width = (970 - delta[0]-55)+"px";
	$('columnOne').innerHTML = delta[0];
}

function redirect(url){
	document.location.href=url;	
}

function primaryMenu(id)
{
	// <![CDATA[	
	
	var ajax;
	var d = new Date();
	var t = d.getTime();
	
	ajax =  new Ajax.Updater(
		 "pageContent",        		// DIV id must be declared before the method was called
		 'ajax/pageContent.php?id='+id+'&t='+t,{method:'get',asynchronous:true, onSuccess:showPage});

	// ]]>
}

var sMenu = 1;
var tMenu =1;
var tParent = null;
var currentPage = null;
var currentSMenu = null;
var currentSBG = null;
var currentSC = null;

function setMenuOn(){
	sMenu = 1;	
}

function setTMenuOn(){
	tMenu = 1;	
}
 
function rollover(divId){
	//$('header').innerHTML = divId +':'+tParent;
	if(divId != tParent && divId != currentSMenu){
		$(divId).style.backgroundColor = '#d1d1d1';
		$(divId).style.color = '#FFF';
	}
	
}
function rollout(divId){
	if(currentSMenu != divId){
		$(divId).style.backgroundColor = '#f8f8f8';
		$(divId).style.color = '#333';
	}
	parentId = null;
}

function rollover2(divId, parentId){
	tParent = parentId;
	if(divId != currentSMenu){
		
		$(divId).style.backgroundColor = '#d1d1d1';
		$(divId).style.color = '#FFF';
	}
}
function rollout2(divId){
	
	tParent = null;
	if(currentSMenu != divId){
		$(divId).style.backgroundColor = '#FFFFFF';
		$(divId).style.color = '#5b5b5b';
	}
}

function closeSubMenu(pId){
	
	if($('tert_'+pId).style.display == ''){
		
		new Effect.BlindUp('tert_'+pId);
	}
	
}

function secondaryMenu(pId, sId, obj){	
	// <![CDATA[
	if($('tert_'+pId)){	
		if($('tert_'+pId).style.display == 'none'){	
			
			new Effect.Appear('tert_'+pId);
			new Effect.Fade('arrow_'+pId);
		}
	}
	setTimeout ( "setMenuOn()",500);
	
	
	
	if(sMenu == 1){
		if(currentSMenu != null){
			$(currentSMenu).morph("background-color:"+currentSBG+";color:"+currentSC+";");
		}
		currentSMenu = 'secondLi_'+pId;
		currentSBG = "#f8f8f8";
		currentSC = "#333";
		$('secondLi_'+pId).morph("background-color:#ababab;color:#FFF;");	
		
		var ajax;
		var d = new Date();
		var t = d.getTime();
		
		ajax =  new Ajax.Updater(
			 "pageContent",        		// DIV id must be declared before the method was called
			 'ajax/pageContent.php?pId='+pId+'&sId='+sId+'&t='+t,{method:'get',asynchronous:true, onSuccess:showPage, onFailure:showError});
	
		sMenu = 0;	
	}
	// ]]>
}

function tertiaryMenu(pId, sId, obj){	
	// <![CDATA[
	if($('tert_'+pId)){			
		new Effect.Appear('tert_'+pId);
	}
	setTimeout ( "setMenuOn()",1000);
	
	
	if(sMenu == 1){
		if(currentSMenu != null){
			$(currentSMenu).morph("background-color:"+currentSBG+";color:"+currentSC+";");
		}
		currentSMenu = 'secondLi_'+pId;
		currentSBG = "#FFFFFF";
		currentSC = "#5b5b5b";
		$('secondLi_'+pId).morph("background-color:#ababab;color:#FFF;");
		
		var ajax;
		var d = new Date();
		var t = d.getTime();
		
		ajax =  new Ajax.Updater(
			 "pageContent",        		// DIV id must be declared before the method was called
			 'ajax/pageContent.php?pId='+pId+'&sId='+sId+'&t='+t,{method:'get',asynchronous:true, onSuccess:showPage, onFailure:showError});
	
		sMenu = 0;	
	}
	// ]]>
}

function showError(req){
	$('pageContent').innerHTML = req.responseText+"<br />Please try again";
}

function showPage(){

	if($('pageContent')){
		
	//	new Effect.Appear('pageContent');	
	}
	
}

function showJournal(id){
	$('journal_'+id).morph("height:100%");
	
}
function divOn(div)
{	
	document.getElementById(div).style.display = 'block';	
}


$(function() {
				
        if(jQuery.browser.msie){
            if(parseFloat(jQuery.browser.version) < 8){
                $.getScript("/media/javascript/iefix.js");            
            }
        }
  
});
