// JavaScript Document
$(document).ready(function(){
						   
	//if in subsetions - add case study and scrollpanes
	if($("#documentsystemssubsection").length > 0 || $("#itservicessubsection").length > 0 || $("#officesuppliessubsection").length > 0  || $("#disclaimer").length > 0 || $("#about").length > 0)
	{
		currentService = "#mainbody";
		
		$("#casestudies").show();
		$("#downloads").show();
		$("#mainbody #text").jScrollPane({showArrows:true});
		$("#casestudies #text").jScrollPane({showArrows:true});
		$("#downloads #text").jScrollPane({showArrows:true});
		$("#casestudies").hide();
		$("#downloads").hide();
		
		setupSubPage();
	}
	
	if($("#parnterslideshow").length > 0 )
	{
		$('#parnterslideshow').show();
		$('#parnterslideshow').cycle({ timeout:4000});
		
	}
	
	if($("#testimonal").length > 0 )
	{
		$('#testimonal').show();
		$('#ticker').cycle({ cleartype: 1, timeout:16000});
	}
	
	//navigation
	setupNav('itsub');
	setupNav('documentsub');
	setupNav('officesub');
	setupNav('itsubsecond2');
	
	//login module
	$("#accountName").inputclear();
	$("#username").inputclear();
	$("#password").inputclear();
	
	$("#login_submit").click(function(){
		checkMainForm();
	});
	
	/*if($("#enquiryform").length > 0)
	{
		$("#enquiry").change(function () {
		  if($("#enquiry").val() == "Remote Connection")
		  {
			 $("#enquiryform").hide();
			 $("#logmeinsupport").show();
		  }
		  else
		  {
			 $("#enquiryform").show();
			 $("#logmeinsupport").hide();
		  }
		});
	}*/
});

function setupSubPage()
{
	$(".caseicon").click(function () {
	  if(currentService!="#casestudies")
	  {
		  $(currentService).hide();
		  $("#downloads").hide();
		  $("#casestudies").show();
		  currentService = "#casestudies";
		  setSelected("caseicon");
	  }
    });
	
	$(".downloadicon").click(function () {
		if(currentService!="#downloads")
		{
		  $(currentService).hide();
		  $("#casestudies").hide();
		  $("#downloads").show();
		  currentService = "#downloads";
		  setSelected("downloadicon");
	 	}
    });
	
	
	$(".backiconselected").click(function () {
		if(currentService!="#mainbody")
		{
		   $(currentService).hide();
		   $("#downloads").hide();
		   $("#mainbody").show();
		   currentService = "#mainbody";
		   setSelected("backicon");
		}
    });
}

function  setSelected(id)
{
	//switch all off
	$("#backicon").removeClass();
	$("#backicon").addClass("backicon");
	$("#caseicon").removeClass();
	$("#caseicon").addClass("caseicon");
	$("#downloadicon").removeClass();
	$("#downloadicon").addClass("downloadicon");
	
	//switch id on
	$("#"+id).addClass(id+"selected");
}

//navigation code
function setupNav(navid)
{
		var sfEls = document.getElementById(navid).getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {         
			sfEls[i].onmouseover=function() 
			{             showNav(navid)         }         
			sfEls[i].onmouseout=function() 
			{            hideNav(navid)        }     
		} 
}	

showNav = function(id) {$("#"+id).show();}
hideNav = function(id) {$("#"+id).hide();}

//add onblur events
$.fn.inputclear = function() {
	return this.focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
};

function checkMainForm()
{
	if($("#accountName").val() == "Account Name" || $("#accountName").val() == "")
	{
		alert('You must enter an account name');
		$("#accountName").focus();
		return;
	}
else if($("#username").val() == "Username"|| $("#username").val() == "")
	{
		alert('You must enter a username');
		$("#username").focus();
		return false;
	}
else if($("#password").val() =="****" || $("#password").val() == "")
	{
		alert('You must enter a password');
		$("#password").focus();
		return false;
	}
else
	{document.MainForm.submit();}
}