// JavaScript Document
function show_errors(text,display,error){
	
	if(error==1)
		{
			jQuery(display).html(text);
			jQuery(display).fadeIn(300).fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300);
		}
	else
		{
			jQuery(display).html('');
			jQuery(display).hide('');
		}
}
function isNumber(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}

function IsValidEmail(email){

	var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	return filter.test(email);

}
function allowedChars(input_value){
	
	var aChars = '1234567890-+() ';

	for(i=0;i<input_value.length;i++)
		{
		if (aChars.indexOf(input_value.charAt(i)) != -1) 
			{
				num = true;
			}
		else
			{
				num = false;
				break;
			}
		}
	return num;

}

jQuery(function(){


//DISPLAY THE BOOKING FOR IF Event_Id is set
//current page url
page = location.href;


	
	//LIGHTBOX
	jQuery('div.order-now').click
		(
		function ()
			{
				var offset = jQuery(this).offset();
				jQuery('div.sign-up-lightbox').fadeIn('fast');
				jQuery('div.sign-up-lightbox').css("position","absolute");
				jQuery('div.sign-up-lightbox').css("top",offset.top);
				jQuery('div.sign-up-lightbox').css("left",offset.left-200);
			}
	);
	
	
	//FORM CHECKS
	jQuery('div.input-submit img').click
		(
		function ()
			{
				var error = 0;
				
				if(jQuery('input[name="cm_name"]').is('input')){
					if(document.sign_up_form.cm_name.value == '' || document.sign_up_form.cm_name.value == 'Your name') 
						{						
						show_errors("Please enter your Name","div.error.cm_name",1);
						error++;
						}
					else
						{
						show_errors('','div.error.cm_name',0);
						}
				}
				
				if(jQuery('input[name="cm_email"]').is('input')){
					if(document.sign_up_form.cm_email.value == '' || document.sign_up_form.cm_email.value == 'Your e-mail') 
						{					
						show_errors("Please enter your e-mail address","div.error.cm_email",1);
						error++;
						}
				}
				
				if(jQuery('input[name="cm_tel"]').is('input')){
					if(document.sign_up_form.cm_tel.value == '' || document.sign_up_form.cm_tel.value == 'Your cell/land line') 
						{						
						show_errors("Please enter your Cell/Landline number","div.error.cm_tel",1);
						error++;
						}
					else
						{
						if(!allowedChars(document.sign_up_form.cm_tel.value))
							{
							show_errors("Invalid characters found. <br> Please enter a valid number","div.error.cm_tel",1);
							error++;
							}
						else
							{
							show_errors('','div.error.cm_name',0);
							}
						}
				}
				
				
				if(error == 0)
					{
					document.sign_up_form.submit();
					}	
			}
		);
	
	//ONLOAD

	if(jQuery('input[name="option"]').attr('value')==1)
		{
			jQuery('div.p-content').html( jQuery('div.course1-tab.one').html());
                        jQuery('div.p-content div.p-heading p').html( jQuery('div.pp1 div.easy-payments').children('h3').html() );
                        adjustHeight();
		}
	if(jQuery('input[name="option"]').attr('value')==2)
		{
			jQuery('div.p-content').html( jQuery('div.course2-tab.one').html());
                        jQuery('div.p-content div.p-heading p').html( jQuery('div.pp2 div.easy-payments').children('h3').html() );
		}
	if(jQuery('input[name="option"]').attr('value')==3)
		{
			jQuery('div.p-content').html( jQuery('div.course3-tab.one').html());
                        jQuery('div.p-content div.p-heading p').html( '<div class="product-image accounting"></div>' );
		}
	if(jQuery('input[name="option"]').attr('value')==4)
		{
			jQuery('div.p-content').html( jQuery('div.course4-tab.one').html());
                        jQuery('div.p-content div.p-heading p').html( jQuery('div.pp4 div.easy-payments').children('h3').html() + '<div class="product-image accounting"></div>' );
		}
	if(jQuery('input[name="option"]').attr('value')==5)
		{
			jQuery('div.p-content').html( jQuery('div.course5-tab.one').html());
                        jQuery('div.p-content div.p-heading p').html( jQuery('div.pp5 div.easy-payments').children('h3').html() );
		}

       

        if (page.indexOf('?') > 0) {
    //Split the string at the '?'s
    _get = page.split('?');
    //Split the string at the '&'s so you can get all the variables that has been set
    _get_vars = _get[1].split('&');
    //get those value's values
    _eventID = _get_vars[0].split('=');

    //alert(_eventID[0]);

    if(_eventID[0] == 'event_Id') {
        //jQuery('div.product-box').removeClass('current');
        //jQuery(this).addClass('current');
        jQuery('div.left-nav div.nav-item').removeClass('active');
        jQuery('div.tab-3').addClass('active');
        //alert(jQuery('div.booking_form').html());
        jQuery('div.p-content').html( jQuery('div.booking_form').html() );

        jQuery('div.tab-3').click(function() {
            jQuery('div.left-nav div.nav-item').removeClass('active');
            jQuery('div.tab-3').addClass('active');
            //alert(jQuery('div.booking_form').html());
            jQuery('div.p-content').html( jQuery('div.booking_form').html() );

        })
    }
}
	

        //REMOVES THE CUURENT CLASS FROM THE PRODUCT BUTTONS ON THE HOMEPAGE
        if (window.location == 'http://www.interexcel.co.za/website-design/') {
            jQuery('div.product-box.current').removeClass('current');
        }

	//CHANGE COLOR ON HOVER OVER PRODUCTS
	jQuery('div.product-box').hover(
		function()
			{				
				jQuery(this).addClass('mouseover');
			},
		function()
			{
				jQuery(this).removeClass('mouseover');
			}
		);
       jQuery('div.product-box-wide').hover(
		function()
			{
				jQuery(this).addClass('mouseover');
			},
		function()
			{
				jQuery(this).removeClass('mouseover');
			}
		);
		
	//CHANGE CURRENT ITEM	
	jQuery('div.product-box').click(
		function()
			{
                            jQuery('div.product-box').removeClass('current');
                            jQuery(this).addClass('current');
                            jQuery('div.left-nav div.nav-item').removeClass('active');
                            jQuery('div.tab-1').addClass('active');

			}
		);
		
	//CHANGE SIDE NAV TABS		
	jQuery('div.left-nav div.nav-item').click(
		function()
			{
			jQuery('div.left-nav div.nav-item').removeClass('active');
                        jQuery(this).addClass('active');
			}
		);
		
		
	//SAVE PRODUCT INFO	
	jQuery('div.tab-1').click(
		function()
			{

                        if(jQuery('input[name="option"]').attr('value')==1)
				{
					jQuery('div.p-content').html( jQuery('div.course1-tab.one').html());
                                        jQuery('div.p-content div.p-heading p').html( jQuery('div.product-box.current div.easy-payments').children('h3').html() );
                                        adjustHeight();
				}
			if(jQuery('input[name="option"]').attr('value')==2)
				{
					jQuery('div.p-content').html( jQuery('div.course2-tab.one').html());
                                        jQuery('div.p-content div.p-heading p').html( jQuery('div.product-box.current div.easy-payments').children('h3').html() );
                                        adjustHeight();
				}
			if(jQuery('input[name="option"]').attr('value')==3)
				{
					jQuery('div.p-content').html( jQuery('div.course3-tab.one').html());
                                        jQuery('div.p-content div.p-heading p').html( jQuery('div.product-box.current div.easy-payments').children('h3').html() );
                                        adjustHeight();
				}
			if(jQuery('input[name="option"]').attr('value')==4)
				{
					jQuery('div.p-content').html( jQuery('div.course4-tab.one').html());
                                        jQuery('div.p-content div.p-heading p').html( jQuery('div.product-box.current div.easy-payments').children('h3').html() );
                                        adjustHeight();
				}
			if(jQuery('input[name="option"]').attr('value')==5)
				{
					jQuery('div.p-content').html( jQuery('div.course5-tab.one').html());
                                        jQuery('div.p-content div.p-heading p').html( jQuery('div.product-box.current div.easy-payments').children('h3').html() );
                                        adjustHeight();
				}
			}
		);

           jQuery('div.tab-2').click(
		function()
			{
                        if(jQuery('input[name="option"]').attr('value')==1)
				{
					jQuery('div.p-content').html( jQuery('div.course1-tab.two').html());
                                        adjustHeight();
				}
			if(jQuery('input[name="option"]').attr('value')==2)
				{
					jQuery('div.p-content').html( jQuery('div.course2-tab.two').html());
                                        adjustHeight();
				}
			if(jQuery('input[name="option"]').attr('value')==3)
				{
					jQuery('div.p-content').html( jQuery('div.course3-tab.two').html());
                                        adjustHeight();
				}
			if(jQuery('input[name="option"]').attr('value')==4)
				{
					jQuery('div.p-content').html( jQuery('div.course4-tab.two').html());
                                        adjustHeight();
				}
			if(jQuery('input[name="option"]').attr('value')==5)
				{
					jQuery('div.p-content').html( jQuery('div.course5-tab.two').html());
                                        adjustHeight();
				}                               
			}
		);
           jQuery('div.tab-3').click(
		function()
			{                            
                        var title = $("title").text();
                        title = title.split("|");
                        var course_name = title[0] + '- ' + jQuery('div.product-box.current div.easy-payments h3').html();                       

                        if(jQuery('input[name="option"]').attr('value')==1)
				{
					get_course_dates(course_name,jQuery(this).attr('id'));
                                        jQuery('div.p-content').html( jQuery('div.course4-tab.three').html());
                                        adjustHeight();
				}
			if(jQuery('input[name="option"]').attr('value')==2)
				{
					get_course_dates(course_name,jQuery(this).attr('id'));
                                        jQuery('div.p-content').html( jQuery('div.course4-tab.three').html());
                                        adjustHeight();
				}
			if(jQuery('input[name="option"]').attr('value')==3)
				{
					get_course_dates(course_name,jQuery(this).attr('id'));
                                        jQuery('div.p-content').html( jQuery('div.course4-tab.three').html());
                                        adjustHeight();
				}
			if(jQuery('input[name="option"]').attr('value')==4)
				{
					get_course_dates(course_name,jQuery(this).attr('id'));
                                        jQuery('div.p-content').html( jQuery('div.course4-tab.three').html());
                                        adjustHeight();
				}
			if(jQuery('input[name="option"]').attr('value')==5)
				{
					get_course_dates(course_name,jQuery(this).attr('id'));
                                        jQuery('div.p-content').html( jQuery('div.course4-tab.three').html());
                                        adjustHeight();
				}                               

			}
		);
		
		
	//SHOW THE PROCESS FOR PRODUCT	

	jQuery('div.course1-tab.one').click(
		function()
			{
			jQuery('div.p-content').html(  jQuery('div.course1-tab.one.content').html());
			}
		);
	jQuery('div.course1-tab.two').click(
		function()
			{
			jQuery('div.p-content').html(  jQuery('div.course1-tab.two.content').html());
			}
		);
	jQuery('div.course2-tab.one').click(
		function()
			{
			jQuery('div.p-content').html(  jQuery('div.course2-tab.one.content').html());
			}
		);
	jQuery('div.course2-tab.two').click(
		function()
			{
			jQuery('div.p-content').html(  jQuery('div.course2-tab.two.content').html());
			}
		);
	jQuery('div.course3-tab.one').click(
		function()
			{
			jQuery('div.p-content').html(  jQuery('div.course3-tab.one.content').html());
			}
		);
	jQuery('div.course3-tab.two').click(
		function()
			{
			jQuery('div.p-content').html(  jQuery('div.course3-tab.two.content').html());
			}
		);
	jQuery('div.course4-tab.one').click(
		function()
			{
			jQuery('div.p-content').html(  jQuery('div.course4-tab.one.content').html());
			}
		);
	jQuery('div.course4-tab.two').click(
		function()
			{
			jQuery('div.p-content').html(  jQuery('div.course4-tab.two.content').html());
			}
		);
	jQuery('div.course5-tab.one').click(
		function()
			{
			jQuery('div.p-content').html(  jQuery('div.course5-tab.one.content').html());
			}
		);
	jQuery('div.course5-tab.two').click(
		function()
			{
			jQuery('div.p-content').html(  jQuery('div.course5-tab.two.content').html());
			}
		);
	
	jQuery('ul.children li.page_item').hover(function() {
            jQuery(this).css('background-color', '#8CC63D');
        },
        function() {
            jQuery(this).css('background-color', '#FFF');
        })

		
	//CHANGE PRODUCT INFO

        jQuery('div.course1').hide();
        jQuery('div.course2').hide();
        jQuery('div.course3').hide();
        jQuery('div.course4').hide();
        jQuery('div.course5').hide();

        jQuery('div.p-process').hide();
	jQuery('div.p-guaranty').hide();

	jQuery('div.pp1').click(
		function()
			{
			jQuery('div.p-content').html( jQuery('div.course1-tab.one').html());
			jQuery('input[name="option"]').attr('value',1);
                        jQuery('div.p-content div.p-heading p').html( jQuery(this).children('div.easy-payments').children('h3').html() );
                        jQuery('div.ppadmin').show();
                        adjustHeight();
			}
		);
	jQuery('div.pp2').click(
		function()
			{
			jQuery('div.p-content').html( jQuery('div.course2-tab.one').html());
			jQuery('input[name="option"]').attr('value',2);
                        jQuery('div.p-content div.p-heading p').html( jQuery(this).children('div.easy-payments').children('h3').html() );
                        adjustHeight();
			}
		);
	jQuery('div.pp3').click(
		function()
			{
			jQuery('div.p-content').html( jQuery('div.course3-tab.one').html());
			jQuery('input[name="option"]').attr('value',3);
                        jQuery('div.p-content div.p-heading p').html( jQuery(this).children('div.easy-payments').children('h3').html() );
                        adjustHeight();
			}
		);
	jQuery('div.pp4').click(
		function()
			{
			jQuery('div.p-content').html( jQuery('div.course4-tab.one').html());
			jQuery('input[name="option"]').attr('value',4);
                        jQuery('div.p-content div.p-heading p').html( jQuery(this).children('div.easy-payments').children('h3').html() );
                        adjustHeight();
			}
		);
	jQuery('div.pp5').click(
		function()
			{
			jQuery('div.p-content').html( jQuery('div.course5-tab.one').html());
			jQuery('input[name="option"]').attr('value',5);
			//jQuery('div.p-info').hide();
                        jQuery('div.p-content div.p-heading p').html( jQuery(this).children('div.easy-payments').children('h3').html() );
                        adjustHeight();
			}
		);
	
	
			
});

//POPUPS
function changepopup(element,top_offset){
	
	if(top_offset)
		{
		top_offset = top_offset;	
		}
	else
		{
		top_offset = 63;
		}

		var offset = jQuery(element).offset();
		var name = jQuery(element).attr("name")
		
		jQuery('div.help-container div.center').html( name );
		jQuery('div.help-container').fadeIn('fast');
		jQuery('div.help-container').css("position","absolute");
		jQuery('div.help-container').css("top",offset.top-top_offset);
		jQuery('div.help-container').css("left",offset.left-20);

}

// EXPAND THE HEIGHT OF THE CONTENT CONTAINER ON THE PRODUCT PAGES 
function adjustHeight(tooSmall) {

    var p_contentH = jQuery('div.p-content').height();

    var oldHeight = 0;
        
   if (p_contentH > 530 || oldHeight < p_contentH) {

        jQuery('div.product-info div.center').height(p_contentH + 60);
        jQuery('div.p-container div.sign-up').height(p_contentH + 60);

    }

    //This is only true if the calendar is called.
    //It is here so that the signup form's height is a bit bigger
    if (tooSmall == 1) {
        jQuery('div.product-info div.center').height(p_contentH + 120);
        jQuery('div.p-container div.sign-up').height(p_contentH + 120);
    }

    oldHeight = p_contentH;
}

//Hide the home content at the bottom and show it when read more is clicked




function showMore (it) {
    alert('123');
       jQuery(this).next('div.hidemore').show();
       return false;
}
