window.onload = function() {append_query_string();}
$(document).ready(function() {
						   
	//homepage graphics fade					   
	
	var cont1 = 1;
	var cont2 = 2;
		
	function automat() {
		$('#v-fade-' + cont1).fadeOut("slow");
		$('#v-fade-' + cont2).fadeIn("slow");
		cont1++;
		cont2++;
		if(cont1==5) cont1 = 1;
		if(cont2==5) cont2 = 1;
	}
		

	var id = setInterval(automat, 10000);
	
	$('#home-down').mouseover(function() {
		if($(this).hasClass('this-seg') == false){
			id = window.clearInterval(id);
			$('#v-fade-2, #v-fade-3, #v-fade-4, #v-fade-5').fadeOut("slow");
			$('#v-fade-1').fadeIn("slow");
			$(this).toggleClass('this-seg');
			$('#home-comp, #home-bus, #home-ecomm, #home-enter').removeClass('this-seg');
		}
	});
	
	$('#home-comp').mouseover(function() {
		if($(this).hasClass('this-seg') == false){
			id = window.clearInterval(id);
			$('#v-fade-1, #v-fade-3, #v-fade-4, #v-fade-5').fadeOut("slow");
			$('#v-fade-2').fadeIn("slow");
			$(this).toggleClass('this-seg');
			$('#home-bus, #home-ecomm, #home-enter, #home-down').removeClass('this-seg');
		}
	});
	
	$('#home-bus').mouseover(function() {
		if($(this).hasClass('this-seg') == false){
			id = window.clearInterval(id);
			$('#v-fade-1, #v-fade-2, #v-fade-4, #v-fade-5').fadeOut("slow");
			$('#v-fade-3').fadeIn("slow");
			$(this).toggleClass('this-seg');
			$('#home-comp, #home-ecomm, #home-enter, #home-down').removeClass('this-seg');
		}
	});
		
	$('#home-ecomm').mouseover(function() {
		if($(this).hasClass('this-seg') == false){
			id = window.clearInterval(id);
			$('#v-fade-1, #v-fade-2, #v-fade-3, #v-fade-5').fadeOut("slow");
			$('#v-fade-4').fadeIn("slow");
			$(this).toggleClass('this-seg');
			$('#home-comp, #home-bus, #home-enter, #home-down').removeClass('this-seg');
		}
	});
		
	$('#home-enter').mouseover(function() {
		if($(this).hasClass('this-seg') == false){
			id = window.clearInterval(id);
			$('#v-fade-1, #v-fade-2, #v-fade-3, #v-fade-4').fadeOut("slow");
			$('#v-fade-5').fadeIn("slow");
			$(this).toggleClass('this-seg');
			$('#home-comp, #home-bus, #home-ecomm, #home-down').removeClass('this-seg');
		}
	});
	
	// features boxes (expand one row at a time)
	$('.features-box a.trigger').click(function(){
		var row = $(this).parent();
		var arrayOfClasses = $(row).attr('class').split(' '); 
		
		if($(this).hasClass('box-closed'))
		{
			$('.features-box.'+arrayOfClasses[1]+' a.trigger').removeClass('box-closed');
			$('.features-box.'+arrayOfClasses[1]+' a.trigger').addClass('box-opened');
			$('.features-box.'+arrayOfClasses[1]+' .box-content').slideDown('fast');
		}
		else
		{
			$('.features-box.'+arrayOfClasses[1]+' a.trigger').removeClass('box-opened');
			$('.features-box.'+arrayOfClasses[1]+' a.trigger').addClass('box-closed');
			$('.features-box.'+arrayOfClasses[1]+' .box-content').slideUp('fast');
		}
		return false;
	});
		
});
function append_query_string()
{
	var apvalue=GetParam('ap');
	if(apvalue != "")
	{
		a_href = document.getElementsByTagName("a");
		for(i=0;i<a_href.length;i++)
		{
			var linkurl = a_href[i].href;
			if(a_href[i].className != "exclude")
			{
				if(linkurl.indexOf("&ap=") == -1)
				{
					if(linkurl.indexOf("https://www.comodo.com/")!=-1)
					{
						if(linkurl.indexOf("?")!=-1)
						{
						a_href[i].href = a_href[i].href + "&ap=" + apvalue;
						}
						else
						{
						a_href[i].href = a_href[i].href + "?ap=" + apvalue;
						}
					}
				}
				else
				{
					if(linkurl.indexOf("&entryURL=")!=-1)
					{
						EntUrlArr = linkurl.split("&entryURL=");
						var EntUrl = unescape(EntUrlArr[1]);
						var QapStr = "ap=" + apvalue;
						while (EntUrl.indexOf(QapStr) > -1)
						{
							EntUrl = EntUrl.replace(QapStr,"");
						}
						a_href[i].href = EntUrlArr[0] + "&entryURL=" + EntUrl;
					}
				}
			}
		}
	}
}
function GetParam(name){ /*Returns values from location urls and assigns to reference variable*/
	var start=location.search.indexOf("?"+name+"=");
	if (start<0) start=location.search.indexOf("&"+name+"=");
	if (start<0) return '';
	start += name.length+2;
	var end=location.search.indexOf("&",start)-1;
	if (end<0) end=location.search.length;
	var result=location.search.substring(start,end);
	var result='';
	for(var i=start;i<=end;i++) {
	var c=location.search.charAt(i);
	result=result+(c=='+'?' ':c);}
	return unescape(result);
}

function checksearchForm() {
	if($("#search input[name='sp_q']").val() == "" || $("#search input[name='sp_q']").val() == "Search our website")
	{
		alert("Please enter a search term!");
	  	return false;
	}
	return true;
}
