
$(function(){
		
	
		 //  $("#quote_date").datepicker();

		/*$("div").each( function() {
			$(this).html($.trim($(this).html()));
			});*/
			$(".image_slideshow").cycle({
				fx: 'fade',
				speed: 3000
			});
			
			$(".index-slideshow").cycle({
				fx: 'fade',
				speed: 2500,
				timeout: 3000,
				next: ".index-slideshow",
				after: onAfter
			});

		/** Pause the slideshow in the beginning **/
		
		$(".index-slideshow").cycle('pause');


		//  Set interval to auto begin fade
		var main_itv;
		if($(".index-slideshow")[0] != null){
			main_itv = setInterval(function(){
				$(".index-slideshow").cycle('resume');
				clearInterval(main_itv);
			}, 16000);
		}
		
		/** Mouse click on the image slideshow to start **/
		
		$(".index-slideshow").click(function(){
			$(".index-slideshow").cycle('resume');
		});
		
		$(".sf-menu li li img").hover(function(){
			$(this).attr("src",$(this).attr("src").replace("-b","-a"));
		}, function(){
			$(this).attr("src",$(this).attr("src").replace("-a","-b"));
		});

			
		$("ul.sf-menu").supersubs({
			minWidth:    10,   // minimum width of sub-menus in em units 
            maxWidth:    27,   // maximum width of sub-menus in em units 
            extraWidth:  0 
		}).superfish({
			delay: 100
		}).find('.sf-menu').bgIframe({ opacity: false }); 
	});

/** Function callback for the index-slideshow **/
/** It will automaticallly stop when the slide index starts off
	from zero again.
**/
function onAfter(curr, next, opts){
	var index = opts.currSlide;
	if(index == 0)
	{
		$(".index-slideshow").cycle('pause');
	}
}
	
var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the FSCommand messages in a Flash movie.
function index_DoFSCommand(command, args) {
	var indexObj = isInternetExplorer ? document.all.index : document.index;
	//
	// Place your code here.
	//
	if (command == "showaddresses") {
		showAddress("Australia", true);
	}
}
// Hook for Internet Explorer.
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<scr'+'ipt language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub index_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call index_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</scr'+'ipt\>\n');
}

function showAddress(country, open_facebox){
	$.facebox.settings.opacity=0.5;
	if(open_facebox)
		$.facebox($(".maininfo").show());
	$('#contactinfo').stop();
	$('#contactinfo').scrollTo('#L_'+country, 2000);

	//Menu Animation
	$(".countriesMenu").css("background","url(./images/Contacts_Countries_0.gif)");
	$(".countriesMenu a img").css("opacity",0);
	$(".countriesMenu a img").unbind("hover");
	$(".countriesMenu a img").hover(function(){
		$(this).animate({opacity:1.0},200);
	},function(){
		$(this).animate({opacity:0.1},400)
	});
}

function showCareerInfo(ID,open_facebox)
{	
	$.facebox.settings.opacity=0.5;
	if(open_facebox)
		  $.facebox( { ajax: 'careersInfo.asp?careerID='+ ID});
	
}

function displayNewsletterBox()
{
	$.facebox.settings.opacity=0.5;
	$.facebox( { ajax: 'signup-newsletter.asp'});
}

function signupNewsletter()
{	
		
		var qtys = $("input[name*=newsletter_]"); //Get the values from user input
		
		for(var i = 0; i < qtys.length; i++) {
			var q = qtys[i];
			var name = $(q).attr("name");
			var value = $(q).val();
			data[name] = value; //sets up the name and the value
		}
	
	$.ajax({
		type: "POST",
		url: "addNewsletter.asp",
		data: data,
		success: function(){
			  $('#newsletter-message').show();
			}
	});
	return false;
}


var value = 1;

function scrollText(direction)
{	
	if(direction == 'prev' && value != 1)
	{
		value-=1;
		$("#content-slider").scrollTo('#p_' +value, 1000,{easing: 'easeout'});
	}
	
	if(direction == 'next' && value < $("#content-slider > div").length)
	{
		value +=1;
		$("#content-slider").scrollTo('#p_'+value, 1000,{easing: 'easeout'});
	}
}

function scrollTextFlashVersion(direction)
{	
	if(direction == 'prev' && value != 1)
	{
		value-=1;
		$("#flash-content-slider").scrollTo('#p_' +value, 1000,{easing: 'easeout'});
	}
	
	if(direction == 'next' && value < $("#flash-content-slider > div").length)
	{
		value +=1;
		$("#flash-content-slider").scrollTo('#p_'+value, 1000,{easing: 'easeout'});
	}
}


function signupNewsletter(){
	var fullname = $("#newsletter_fname").val();
	var email = $("#newsletter_email").val();
	
	var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	
	if(fullname == "" && email == "")
	{
		$("#input-error-message").empty();
		$("#input-error-message").append("<strong>Please enter your name and email address.</strong>");
		$("#newsletter_fname").focus();
	}
	else if(fullname == "" && !filter.test(email))
	{
		$("#input-error-message").empty();
		$("#input-error-message").append("<strong>Please enter your full name.</strong>");
		$("#newsletter_fname").focus();
	}
	else if(fullname != "" && email == "")
	{
		$("#input-error-message").empty();
		$("#input-error-message").append("<strong>Please enter your email address.</strong>");
		$("#newsletter_email").focus();
		
	}
	else if(fullname  != "" && !filter.test(email))
	{
		$("#input-error-message").empty();
		$("#input-error-message").append("<strong>Invalid email address. Please try again.</strong>");
		$("#newsletter_email").focus();
	}
	else{
	
	$.post("addNewsletter.asp", {fullname:fullname, email:email}, function(data) {
	
				if(String(data).match(/OK/i)){
					//$("#main_inputs").hide();
					$("#newsletter-info").hide();
					$("#input-error-message").hide();
					$("#message-text").append("<strong>Thank you for signing up with our newsletter.</strong>");
					$("#message-text").show();
				}
			}
		)
	}
}

function showImageByLinkType(linkName)
{	
	$(".image_slideshow").hide();
}

function goURL(url, win){
	void window.open(url, win);
}

function showPopups()
{
	$.facebox.settings.opacity=0.5;
	$.facebox( { ajax: 'popupMessage.asp'});
}


function emailQuote()
{
	
	var fullname = $("#quote_name").val();
	var companyName = $("#quote_company").val();
	var emailAddress = $("#quote_email").val();
	var contactNo = $("#quote_contact").val();
	var address = $("#quote_address").val();
	var countryName = $("#quote_country").val();
	var postcode = $("#quote_postcode").val();
	var helpInfo = $("#quote_info").val();
	var quantity = $("#quote_quantity").val();
	var budget = $("#quote_budget").val();
	var dateReq = $("#quote_date").val();

	var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	var dateRegex = /(?:0[1-9]|[12][0-9]|3[01])\/(?:0[1-9]|1[0-2])\/(?:19|20\d{2})/;
	
	if(fullname != "" && companyName != "" && emailAddress != "" && contactNo != "")
	{
	
	if(emailAddress.match(emailRegEx)){
		
		//Date.compare(today, future);
		
		var dateEntered = new Date(dateReq);
		
		if((dateEntered != "" && Date.today().compareTo(dateEntered) <= 0))
		{
	
		var obj = {
			fullname:fullname,
			companyname: companyName,
			emailAddress: emailAddress,
			contactNo: contactNo,
			address: address,
			countryName: countryName,
			postcode: postcode,
			helpInfo: helpInfo,
			quantity: quantity,
			budget: budget,
			dateReq: dateReq
		};
	

	
		$.post("emailQuote.asp", obj, function(data) {
			if(String(data).match(/OK/i)){
				$(".tbl_quote").hide();
			}
		});
		}
		else if(isNaN(dateEntered))
		{
			alert("Please enter the date in the format of (dd/mm/yyyy). ");
		}
		else if(Date.today().compareTo(dateEntered) > 0){
			alert("Please enter the date that is greater than today's date.");
		}
	}else{
			alert("Invalid email address. Please try again. ");
			
		}
	}else{
		
		alert("Please enter the details into for required (*) field(s)");
	}
	
}