
$(document).ready(function () {


/***By default requestQuote+ pagenavwrap will be hidden***/
$("#pagenavwrap").hide();
$("#requestQuote").hide();

/*** Show requestQuote***/
$("#requestQuoteHide").click(function () {
           $("#requestQuote").hide();
		   return true;
});

/*** Hide requestQuote***/
$("#requestQuoteShow").click(function () {
           $("#requestQuote").toggle("slow");
           $('.coda-slider-no-js').attr('disabled', 'disabled');
		   //history.go(-1);
		   return true;
});


$('#coda-slider-1').codaSlider();


//home page has been hidden every time when ajax called replaced the content
$(".hide1").click(function () {
  $("#pagenavwrap").hide();  
  $("#coda-slider-wrapper").hide();  
return true;
});

//due to some problem shockwave is not included in the ajax call.
$(".hide4").click(function () {
	document.getElementById('content').value = '';
	$("#coda-slider-wrapper").hide();
    $("#pagenavwrap").show();	
return true;
});


//Check if url hash value exists (for bookmark)
$.history.init(pageload);

//highlight the selected link
$('a[href=' + document.location.hash + ']').addClass('selected');

//Seearch for link with REL set to ajax
/***For single click***/
$('a[rel=ajax]').bind ('click' , function () {
		
      //For the double click first click will be accept second click will be disable
      //$(this).click(function () {return false; });

		
		//grab the full url
		var hash = this.href;
		//remove the # value
		hash = hash.replace(/^.*#/, '');
		//for back button
	 	$.history.load(hash);
	 	//clear the selected class and add the class class to the selected link
	 	$('a[rel=ajax]').removeClass('selected');
	 	$(this).addClass('selected');
	 	//hide the content and show the progress bar
	 	$('#content').hide();
	 	$('#loading').show();
	 	/*** Clear div before update***/
		$("#content").empty();
				//run the ajax
		getPage();
	
		
		//cancel the anchor tag behaviour
		return false;
	});

});




function pageload(hash) {
	//if hash value exists, run the ajax

	//alert('Hash: ' + document.location.hash);
	//alert('Hash: ' + document.getElementById(this.hash).value);

	if(document.location.hash != "#designdevelopment"
	   && document.location.hash != "#ecommercesolutions"
	   && document.location.hash != "#searchenginemarketing"
	   && document.location.hash != "#searchengineoptimisation"
	   && document.location.hash != "#softwaredevelopment"
	   && document.location.hash != "#onlineinformationsolutions"
	   && document.location.hash != "#domainregistration"
	   && document.location.hash != "#webhosting"
	   && document.location.hash != "#graphicdesignprint"
	   //&& document.location.hash != "#portfolio"
	)
	{ 
 		if(document.location.hash != ""){
			$("#coda-slider-wrapper").hide();
 		}
 		
		if (hash) getPage();
	}
}

function getPage() {

	//generate the parameter for the php script
	var data = 'page=' + encodeURIComponent(document.location.hash);
	//var data = 'page=%23' + option; 
	$.ajax({
		url: "loader.php",
		type: "GET",
		data: data,
		async: false,
		cache: false,
		timeout: 30000,
		
		success: function (html) {

			//hide the progress bar
			$('#loading').hide();

            
			
			//add the content retrieved from ajax and put it in the #content div
			$('#content').html(html);
			
			
			/*** 
			In the "Safari" the inner HTML can not loaded properly.
            Making sure the innerHTML has been loaded properly in "Safari".
            Try minimum count times to fill up with ajax content if not filled up    
		    ***/
			
			var contentElement = document.getElementById("content");
			var contentData = document.getElementById("content").innerHTML;
			
		    var count = 3 ;
			if(contentData =='' || contentData == null) setInnerHTML(contentElement , html , count);
		   
			//display the body with fadeIn transition
			$('#content').show();
		}
		
		
	});		
}



/***
In the "Safari" the inner HTML can not loaded properly.This is a well known problem in safari
Making sure the innerHTML was loaded properly in "Safari".
***/
			

 function setInnerHTML( element, html, count ) {

     element.innerHTML = html;

     if( ! count )

         count = 1;

     if( html != '' && element.innerHTML == '' && count < 5 ) {

         ++count;

         setTimeout( function() {

             setInnerHTML( element, html, count );

         }, 10 );

     }

 } 



function callmenuleft(selectedmenu) {

	//generate the parameter for the php script
	//alert('Selected: ' + selectedmenu);
	var data = 'page=%23' + selectedmenu;

	//var data = 'page=' + encodeURIComponent(document.location.hash);
	$.ajax({
		url: "loader.php",
		type: "GET",
		data: data,
		cache: false,
		success: function (html) {

			//hide the progress bar
			$('#loading').hide();

			//add the content retrieved from ajax and put it in the #content div
			$('#contentleft').html(html);


			//display the body with fadeIn transition
			$('#contentleft').fadeIn('slow');
		}
	});
}




function contactUs(contactForm){


    document.getElementById("mailNotify").innerHTML = "";
	
        /***Check Contact Name***/
        var contactName = $("input#contactName").val();  
	    if (contactName == "") {  
	    $("#contactNameError").html("Please give your name");
        $("#contactName").focus();  
        return false;
		}
		
		$("#contactNameError").html("");

	    /***Check Contact Name***/
        var contactEmail = $("input#contactEmail").val();  
	    if (contactEmail == "") {  
	    $("#contactEmailError").html("Please give your email address");
        $("#contactEmail").focus();  
        return false;
		}
		
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        if(reg.test(contactEmail) == false) {
	    $("#contactEmailError").html("Email address is not a valid format!");
        $("#contactEmail").focus();  
        return false;  
	    }
	   
	   $("#contactEmailError").html("");
	
        /***Check Contact Message***/
        var contactMessage = $("textarea#contactMessage").val();  
	    if (contactMessage == "") {  
	    $("#contactMessageError").html("Your saying is important to us!");
        $("#contactMessage").focus();  
        return false;
		}
		
		$("#contactMessageError").html("");
	
	
	

    /***Getting values from the text fields ***/
	
	var from      = document.getElementById("contactName").value;
        var email     = document.getElementById("contactEmail").value;
        var message   = document.getElementById("contactMessage").value;
    
	var data = 'from=' + from 
	         + '&email=' + email
	         + '&message=' + message;

	//var data = 'page=' + encodeURIComponent(document.location.hash);
	$.ajax({
		url: "contactrequest.php",
		type: "POST",
		data: data,
		cache: false,
		success: function (html) {

			//hide the progress bar
			$('#loading').hide();

			//add the content retrieved from ajax and put it in the #content div
			$("#mailNotify").html(html);

			//display the body with fadeIn transition
			$('#contentleft').fadeIn('slow');
		}
	});


/*** Clear all the form fields ***/
$(':input','#contactForm')
 .not(':button, :submit, :reset, :hidden')
 .val('')
 .removeAttr('checked')
 .removeAttr('selected');

 
 
 
 /*** Remain in the same page to let the user see the mail sending notification***/
 return false;
}



function mailrequest(){

  
       document.getElementById("mailsent").innerHTML = "";
	
      /***Check Contact Name***/
        var cEmail = $("input#cemail").val();  
	    if (cEmail == "") {  
	    $("#cemailError").html("Please give your email address");
        $("#cemail").focus();  
        return false;
		}
		
		$("#cemailError").html("");
	
		
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        if(reg.test(cEmail) == false) {
	    $("#cemailError").html("Email address is not a valid format!");
        $("#cemail").focus();  
        return false;  
	    }
	   
	   $("#cemailError").html("");
	
  

	//generate the parameter for the php script
	
    var from    = document.getElementById('name').value;
    var company = document.getElementById('company').value;
    var phone   = document.getElementById('phone').value;
    var cemail  = document.getElementById('cemail').value;

    var services  = document.getElementById('services').value;
    var solutions = document.getElementById('solutions').value;
    var budget    = document.getElementById('budget').value;
    var curl      = document.getElementById('curl').value;
    var comments  = document.getElementById('ccomment').value;
	
	var data = 'name=' + from 
	         + '&company=' + company
	         + '&phone=' + phone
	         + '&email=' + cemail
	         + '&services=' + services
	         + '&solutions=' + solutions
	         + '&budget=' + budget
	         + '&curl=' + curl
	         + '&comments=' + comments;

	//var data = 'page=' + encodeURIComponent(document.location.hash);
	$.ajax({
		url: "mailrequest.php",
		type: "POST",
		data: data,
		cache: false,
		success: function (html) {

			//hide the progress bar
			$('#loading').hide();

			//add the content retrieved from ajax and put it in the #content div
			$('#mailsent').html(html);

			//display the body with fadeIn transition
			$('#contentleft').fadeIn('slow');
		}
	});
	
	
$(':input','#requestQuoteForm')
 .not(':button, :submit, :reset, :hidden')
 .val('')
 .removeAttr('checked')
 .removeAttr('selected');

	
}

