$(document).ready(function() {
	// open links marked external in new windows
	$('a[rel="external"]').click( function() {
		window.open( $(this).attr('href') );
		return false;
	});

	// Detect current page filename in order to highlight appropriate main-menu button
	var filenameLength = location.pathname.length - (location.pathname.lastIndexOf("/")+1) - 4;
	var page = location.pathname.substr(location.pathname.lastIndexOf("/")+1, filenameLength);
	if (page=="index" || page=="") { page="home"; }

	// Add 'current' class for detected page to appropriate main-menu button
	$('#navigation .' + page + ' a').addClass('active');

	// Add PrettyPhoto to all links with rel=prettyPhoto
	$("a[rel^='prettyPhoto']").prettyPhoto({theme:'dark_square'});

    /* //Commented out by  Tranga
     //if submit button is clicked  
     $('.contactform #submitform').click(function () {          
           
         //Get the data from all the fields  
         var name = $('.contactform input[name=name]');  
         var phone = $('.contactform input[name=phone]');  
         var company = $('.contactform input[name=company]');  
         var email = $('.contactform input[name=email]');  
         var package = $('.contactform input[name=package]');  
   
         //Simple validation to make sure user entered something  
         //If error found, add hightlight class to the text field  
         if (name.val()=='') {  
             name.addClass('highlight'); 
         } else name.removeClass('highlight');  
           
         if (phone.val()=='') {  
             phone.addClass('highlight');  
         } else phone.removeClass('highlight');  

         if (email.val()=='') {  
             email.addClass('highlight');  
         } else email.removeClass('highlight');             
         
         if (name.val()==''||email.val()==''||phone.val()=='') 
         {
       		$('.contactform p#instructions').html('Please fill in all required fields.<br /><br />').css('color', '#b82e48');
         	return false; 
         }

         //organize the data properly  
         var data = 'name=' + name.val() + '&phone=' + phone.val() + '&company='  
         + company.val() + '&email='  + email.val() + '&package=' + package.val();
           
         //start the ajax  
         $.ajax({  
             //this is the php file that processes the data and send mail  
             url: "process.php",   
               
             //GET method is used  
             type: "GET",  
   
             //pass the data           
             data: data,       
               
             //Do not cache the page  
             cache: false,  
               
             //success  
             success: function (result) {                
                 //if process.php returned 1/true (send mail success)  
                 if (result==1) {
                 		$('.contactform form').fadeOut('slow');     
                 		$('.contactform p#instructions').fadeOut('slow', function() {
	                 		$('.contactform p#successmessage').fadeIn('slow');
                 		});
                 //if process.php returned 0/false (send mail failed)  
                 } else alert('Sorry, unexpected error. Please try again later.');                 
             }         
         });  
           
         //cancel the submit button default behaviours  
         return false;  
     });


    //Commented out by tranga
      */

/*
    // Commented out by Tranga
     //if submit button is clicked - for second form on packages page
     $('.contactform2 #submitform2').click(function () {          
           
         //Get the data from all the fields  
         var name = $('.contactform2 input[name=name2]');  
         var phone = $('.contactform2 input[name=phone2]');  
         var company = $('.contactform2 input[name=company2]');  
         var email = $('.contactform2 input[name=email2]');  
         var package = $('.contactform2 input[name=package2]');  
   
         //Simple validation to make sure user entered something  
         //If error found, add hightlight class to the text field  
         if (name.val()=='') {  
             name.addClass('highlight'); 
         } else name.removeClass('highlight');  
           
         if (phone.val()=='') {  
             phone.addClass('highlight');  
         } else phone.removeClass('highlight');  

         if (email.val()=='') {  
             email.addClass('highlight');  
         } else email.removeClass('highlight');             
         
         if (name.val()==''||email.val()==''||phone.val()=='') 
         {
       		$('.contactform2 p#instructions2').html('Please fill in all required fields.').css('color', '#b82e48');
         	return false; 
         }

         //organize the data properly  
         var data = 'name=' + name.val() + '&phone=' + phone.val() + '&company='  
         + company.val() + '&email='  + email.val() + '&package=' + package.val();
           
         //start the ajax  
         $.ajax({  
             //this is the php file that processes the data and send mail  
             url: "process.php",   
               
             //GET method is used  
             type: "GET",  
   
             //pass the data           
             data: data,       
               
             //Do not cache the page  
             cache: false,  
               
             //success  
             success: function (result) {                
                 //if process.php returned 1/true (send mail success)  
                 if (result==1) {
					    pageTracker._trackEvent('Form','form submitted');
                 		$('.contactform2 form').fadeOut('slow');     
                 		$('.contactform2 p#instructions2').fadeOut('slow', function() {
	                 		$('.contactform2 p#successmessage2').fadeIn('slow');
                 		});
                 //if process.php returned 0/false (send mail failed)  
                 } else alert('Sorry, unexpected error. Please try again later.');                 
             }         
         });  
           
         //cancel the submit button default behaviours  
         return false;  
     });

     //Commented out by Tranga
     */

});

function Show_Popup(package, preceding) {
		// Reset form
	$('.contactform form').show();     
	$('.contactform p#instructions').show();
	$('.contactform p#successmessage').hide();
	$('.contactform p#instructions').html('If you want more information on how <span>this package</span> can help your business grow, submit your details and a friendly web marketing consultant will call you!').css('color', '#333');
    $('.contactform input[name=name]').removeClass('highlight');
    $('.contactform input[name=phone]').removeClass('highlight');
    $('.contactform input[name=email]').removeClass('highlight');
	
	$('#window h2').html(package);
	$('#window p#instructions span').html(preceding+package);
	$('#window input.package').attr('value', package);
	Cufon.replace('#window h2', {fontFamily: 'futuramed' });

	$('#popup').fadeIn('fast');
	$('#window').fadeIn('fast');
}

function Close_Popup() {
	$('#popup').fadeOut('fast');
	$('#window').fadeOut('fast');
}

