function switchTab(clickedTab)
	{
		var tab = $(clickedTab).closest('li');
		
		if (tab.hasClass('service')) 
		{
			tab.addClass('first_current');
			tab.siblings().removeClass('current');
			var contentWrapper = $('div#service');
			contentWrapper.siblings('div').css('display', 'none');
			contentWrapper.css('display', 'block');
			$('ul#product_equipment').css('display', 'none');
			$('ul#product_service').css('display', 'block');
		}

		if (tab.hasClass('equipment')) 
		{
			tab.addClass('current');
			tab.siblings().removeClass('first_current');
			var contentWrapper = $('div#equipment');
			contentWrapper.siblings('div').css('display', 'none');
			contentWrapper.css('display', 'block');
			$('ul#product_service').css('display', 'none');
			$('ul#product_equipment').css('display', 'block');
		}
	}

	function displayForums(url,tabId)
	{
		
		var xmlhttp=null;
		try
		{
			xmlhttp=new XMLHttpRequest();
		}
		catch(B)
		{
			try
			{
				xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
			}catch(B)
			{
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				if (document.getElementById(tabId) != null)
				{
					document.getElementById(tabId).innerHTML=xmlhttp.responseText;
				}
				
			}
		}
		xmlhttp.open("GET",url,true);
		xmlhttp.send();
		
		var startIndex;
		
	    var vars = [], hash;
        var hashes = url.slice(url.indexOf('?') + 1).split('&');
        for (var i = 0; i < hashes.length; i++) {
            hash = hashes[i].split('=');
            vars.push(hash[0]);
            vars[hash[0]] = hash[1];
            
            if(hash[0]=="startIndex"){
            	startIndex = hash[1];
            }
        }
        
        if(startIndex==null){startIndex=1;}
        var hashParams = location.hash.split('_');
        
        if(hashParams[1] != undefined)
        {
        	// Get the hashparams as we need to get the paginated page index - hashParams[3]
        	
        	window.location.hash = "#_" + hashParams[1] + "_" + hashParams[2] + "_" + hashParams[3] + "_" + startIndex + "_" + hashParams[5] + "_" + hashParams[6] + "_" + hashParams[7];
        }
        else
        {
    		var filter1 = $('div.dropdowns ul li.filter1 p a span').text();
    		var filter2 = $('div.dropdowns ul li.filter2 p a span').text();
    		var filter3 = $('div.dropdowns ul li.filter3 p a span').text();
    		var filter1eng = $('div.dropdowns ul li.filter1 p a span').attr("id");
    		var filter2eng = $('div.dropdowns ul li.filter2 p a span').attr("id");
    		var filter3eng = $('div.dropdowns ul li.filter3 p a span').attr("id");
        	window.location.hash = "#_"+filter1+"_"+filter2+"_"+filter3+"_1_"+filter1eng+"_"+filter2eng+"_"+filter3eng;
        }
       }

		function callAjaxForEvent(actionurl,tabId)
		{
			
			var startIndex, rowsPerPage, listSize, tabId, isArcEvents;
			
		    var vars = [], hash;
	        var hashes = actionurl.slice(actionurl.indexOf('?') + 1).split('&');
	        for (var i = 0; i < hashes.length; i++) {
	            hash = hashes[i].split('=');
	            vars.push(hash[0]);
	            vars[hash[0]] = hash[1];
	            
	            if(hash[0]=="startIndex"){
	            	startIndex = hash[1];
	            }
	            else if(hash[0]=="tabId"){
	            	tabId = hash[1];
	            }
	            else if(hash[0]=="listSize"){
	            	listSize = hash[1];
	            }
	            else if(hash[0]=="rowsPerPage"){
	            	rowsPerPage = hash[1];
	            }
	            else if(hash[0]=="isArcEvents"){
	            	isArcEvents = hash[1];
	            }
	        }
	        var tabName = $('ul#events_tab_nav li.current').attr('name');
	        actionurl= actionurl+"&tabname="+tabName;
			if(isArcEvents == "true" || isArcEvents == "1")
			{
				window.location.hash = "#_" + startIndex + "_" + tabId + "_" + listSize + "_" + rowsPerPage+"_1";	
			}
			else
			{
				window.location.hash = "#_" + startIndex + "_" + tabId + "_" + listSize + "_" + rowsPerPage;
			}
			var xmlhttp=null;
			try
			{
				xmlhttp=new XMLHttpRequest();
			}
			catch(B)
			{
				try
				{
					xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
				}catch(B)
				{
					xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
			}
			xmlhttp.onreadystatechange=function()
		  	{
		  		if (xmlhttp.readyState==4 && xmlhttp.status==200 && tabName != undefined)
		    	{
		    		
			   		document.getElementById(tabId).innerHTML=xmlhttp.responseText;
			   	}
			   	
		  	}
		  	xmlhttp.open("GET",actionurl,true);
			xmlhttp.send();		
		}

	function submitFilterText(filterText,replaceId,hideId,actionUrl)
	{
		
		var val = filterText.innerHTML;
		$('#'+hideId).hide();
		$(replaceId).replaceWith('<span id="'+$(filterText).attr('rel')+'">'+val+'</span>');
		var option1 = $('div.dropdowns ul li.filter1 p a span').attr('id');
		var option2 = $('div.dropdowns ul li.filter2 p a span').attr('id');
		var option3 = $('div.dropdowns ul li.filter3 p a span').attr('id');
		actionUrl += "&filter1="+escape(option1);
		actionUrl += "&filter2="+escape(option2);
		actionUrl += "&filter3="+escape(option3);
		var tabId = "list_with_images_and_text";
		displayForums(actionUrl,tabId);
		
		var option1InLocalisedLang = $('div.dropdowns ul li.filter1 p a span').text();
		var option2InLocalisedLang = $('div.dropdowns ul li.filter2 p a span').text();
		var option3InLocalisedLang = $('div.dropdowns ul li.filter3 p a span').text();
				
		var hashParams = location.hash.split('_');
		var pageIndex = hashParams[4];
		
		if(hashParams[4] > 1){hashParams[4] = 1 ;}
		
		var pre = "#_" + option1InLocalisedLang + "_" + option2InLocalisedLang + "_" + option3InLocalisedLang + "_" + pageIndex + "_" + option1 + "_" + option2 + "_" + option3;
		pre = pre.replace(/%26/g,"^").replace(/\&/g,"^");
		window.location.hash = pre;

	}
        function unescapeAmp(value) {
		if(value && value !=null && value.length>0) {
                  value=value.replace(/\^/g,"&");
		}
		return value;
        }
 function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmailInquiry(fld) 
{
    var error="";
    var tfld = trim(fld.value);                        
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        error = "The email address contains illegal characters.\n";
    } 
    return error;
}

function ajaxRequest(){
	//activeX versions to check for in IE
	var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] 
	//Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
	if (window.ActiveXObject){ 
		for (var i=0; i<activexmodes.length; i++){
			try{
				return new ActiveXObject(activexmodes[i])
			}
			catch(e){
				//suppress error
			}
		}
	}
	// if Mozilla, Safari etc
	else if (window.XMLHttpRequest) {
	return new XMLHttpRequest()
	}
	else
		return false
}

//Function to show the capctha image
function showRecaptchaForm(element)
{
	var url='<%=ics.GetVar("displayCaptchaLink")%>';
	var xmlhttp =  new ajaxRequest();
	xmlhttp.onreadystatechange=function()
	{
			
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{	
				document.getElementById(element).innerHTML=xmlhttp.responseText;
			}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send();
}


