// 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(){
	
	//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++;
						}
					else
						{
						if(!IsValidEmail(document.sign_up_form.cm_email.value))
							{
							show_errors("Please enter your e-mail address in the correct format ie: name@domain.co.za","div.error.cm_email",1);
							error++;
							}
						else
							{
							show_errors('','div.error.cm_email',0);
							}
						}
				}
				
				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.product-1').html());
			jQuery('div.process').html( jQuery('div.process-1').html());
			jQuery('div.p-process').show();
			jQuery('div.p-guaranty').show();
		}
	if(jQuery('input[name="option"]').attr('value')==2)
		{
			jQuery('div.p-content').html( jQuery('div.product-2').html());
			jQuery('div.process').html( jQuery('div.process-2').html());
			jQuery('div.p-process').show();
			jQuery('div.p-guaranty').show();
		}
	if(jQuery('input[name="option"]').attr('value')==3)
		{
			jQuery('div.p-content').html( jQuery('div.product-3').html());
			jQuery('div.process').html( jQuery('div.process-3').html());
			jQuery('div.p-process').show();
			jQuery('div.p-guaranty').show();
		}
	if(jQuery('input[name="option"]').attr('value')==4)
		{
			jQuery('div.p-content').html( jQuery('div.product-4').html());
			jQuery('div.process').html( jQuery('div.process-4').html());
			jQuery('div.p-process').hide();
			jQuery('div.p-guaranty').hide();
		}
	if(jQuery('input[name="option"]').attr('value')==5)
		{
			jQuery('div.p-content').html( jQuery('div.product-5').html());
			jQuery('div.process').html( jQuery('div.process-5').html());
			jQuery('div.p-process').show();
			jQuery('div.p-guaranty').show();
		}
	

        //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.products-nav li').hover(
		function()
			{

				jQuery(this).addClass('active');
			},
		function()
			{
				jQuery(this).removeClass('active');
			}
		);
       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.p-info').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.p-info').click(
		function()
			{
			if(jQuery('input[name="option"]').attr('value')==1)
				{
					jQuery('div.p-content').html( jQuery('div.product-1').html());
				}
			if(jQuery('input[name="option"]').attr('value')==2)
				{
					jQuery('div.p-content').html( jQuery('div.product-2').html());
				}
			if(jQuery('input[name="option"]').attr('value')==3)
				{
					jQuery('div.p-content').html( jQuery('div.product-3').html());
				}
			if(jQuery('input[name="option"]').attr('value')==4)
				{
					jQuery('div.p-content').html( jQuery('div.product-4').html());
				}
			if(jQuery('input[name="option"]').attr('value')==5)
				{
					jQuery('div.p-content').html( jQuery('div.product-5').html());
				}
				
			}
		);
		
		
	//SHOW THE PROCESS FOR PRODUCT	
	jQuery('div.p-process').click(
		function()
			{
			jQuery('div.p-content').html(  jQuery('div.process').html());
			}
		);
		
	//SHOW THE GUARANTY FOR PRODUCT		
	jQuery('div.p-guaranty').click(
		function()
			{
			jQuery('div.p-content').html( jQuery('div.guaranty').html());
			}
		);
	
	
		
	//CHANGE PRODUCT INFO		
	jQuery('li.prod1').click(
		function()
			{
			jQuery('li.prod1').addClass('active2');
                        jQuery('div.p-content').html( jQuery('div.product-1').html());
			jQuery('div.process').html( jQuery('div.process-1').html());
			jQuery('input[name="option"]').attr('value',1);
			jQuery('div.p-info').show();
			jQuery('div.p-process').show();
			jQuery('div.p-guaranty').show();

                        jQuery('li.prod2').removeClass('active2');
                        jQuery('li.prod3').removeClass('active2');
                        jQuery('li.prod4').removeClass('active2');

                        jQuery('div.p-info').addClass('active');
                        jQuery('div.p-process').removeClass('active');
                        jQuery('div.p-guaranty').removeClass('active');
			}
		);
	jQuery('li.prod2').click(
		function()
			{
			jQuery('li.prod2').addClass('active2');
                        jQuery('div.p-content').html( jQuery('div.product-2').html());
			jQuery('div.process').html( jQuery('div.process-2').html());
			jQuery('input[name="option"]').attr('value',2);
			jQuery('div.p-info').show();
			jQuery('div.p-process').show();
			jQuery('div.p-guaranty').show();

                        jQuery('li.prod1').removeClass('active2');
                        jQuery('li.prod3').removeClass('active2');
                        jQuery('li.prod4').removeClass('active2');

                        jQuery('div.p-info').addClass('active');
                        jQuery('div.p-process').removeClass('active');
                        jQuery('div.p-guaranty').removeClass('active');
			}
		);
	jQuery('li.prod3').click(
		function()
			{
			jQuery('li.prod3').addClass('active2');
                        jQuery('div.p-content').html( jQuery('div.product-3').html());
			jQuery('div.process').html( jQuery('div.process-3').html());
			jQuery('input[name="option"]').attr('value',3);
			jQuery('div.p-info').show();
			jQuery('div.p-process').show();
			jQuery('div.p-guaranty').show();

                        jQuery('li.prod1').removeClass('active2');
                        jQuery('li.prod2').removeClass('active2');
                        jQuery('li.prod4').removeClass('active2');

                        jQuery('div.p-info').addClass('active');
                        jQuery('div.p-process').removeClass('active');
                        jQuery('div.p-guaranty').removeClass('active');
			}
		);
	jQuery('li.prod4').click(
		function()
			{
			jQuery('li.prod4').addClass('active2');
                        jQuery('div.p-content').html( jQuery('div.product-4').html());
			jQuery('div.process').html( jQuery('div.process-4').html());
			jQuery('input[name="option"]').attr('value',4);
			//jQuery('div.p-info').hide();
			jQuery('div.p-process').hide();
			jQuery('div.p-guaranty').hide();

                        jQuery('li.prod1').removeClass('active2');
                        jQuery('li.prod2').removeClass('active2');
                        jQuery('li.prod3').removeClass('active2');

                        jQuery('div.p-info').addClass('active');
                        jQuery('div.p-process').removeClass('active');
                        jQuery('div.p-guaranty').removeClass('active');
			}
		);
	
	
		
	jQuery('div.help-container').click(
		function()
			{
			jQuery(this).fadeOut('fast');
			}
		);	
		
	jQuery('div.form-container div.close').click(
		function()
			{
			jQuery('div.sign-up-lightbox').fadeOut('fast');
			}
		);		
	
});

//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);

}
