// JavaScript Document//clear text box on click
function clearText(field){

if (field.defaultValue == field.value) field.value = '';
else if (field.value == '') field.value = field.defaultValue;

}


///////////////////////////////////////////   Jquery Tabs
$(document).ready(function() {
	//Default Action
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		
		var id = $(activeTab).attr('id');
		goToByScroll(id);
		
		return false;
	});

});

function goToByScroll(id){
	$('html,body').animate({scrollTop: $("#"+id).offset().top},'slow');
}

///////////////////////////////////////////  Back to Top
$(function() {
	$(window).scroll(function() {
		if($(this).scrollTop() != 0) {
			$('#toTop').fadeIn();	
		} else {
			$('#toTop').fadeOut();
		}
	});
 
	$('#toTop').click(function() {
		$('body,html').animate({scrollTop:0},800);
	});	
});


/////////////////////////////////////////// Quicklinks Panel
$(document).ready(function(){
	$("#quicklinks").click(function(){
		$("#quicklinks-panel").slideToggle("slow");
		//$(this).toggleClass("active"); 
		return false;
	});
	 
});

///////////////////////////////////////////  MORE OR LESS TEXT
$(function(){
	// The height of the content block when it's not expanded
	var adjustheight = 220;

	// The "more" link text
	var moreText = "+ View more";
	// The "less" link text
	var lessText = "- View less";
	var learnmore = "> Learn More";
	// Sets the .more-block div to the specified height and hides any content that overflows
	//$(".more-less .more-block").css('height', adjustheight).css('overflow', 'hidden');
	// The section added to the bottom of the "more-less" div
	$(".more-less").append('<p class="continued"></p><a href="#" class="adjust"></a><a class="learnmore"></a>');
	$("a.adjust").text(moreText);
	
	$(".adjust").toggle(function() {
			var inner = $(this).parent().find('.more-block');
			adjustheight = $(inner).css('height');
			
			$(this).parents("div:first").find(".more-block").css('height', 'auto').css('overflow', 'visible');
			// Hide the [...] when expanded
			$(this).parents("div:first").find("p.continued").css('display', 'none');
			$(this).text(lessText);
			var link = $(this).siblings('.more-block').find('a.hide').attr('href');
			$(this).next().text(learnmore).attr('href',link);			
		}, function() {					
			
			$(this).parents("div:first").find(".more-block").css('height', adjustheight).css('overflow', 'hidden');
			$(this).parents("div:first").find("p.continued").css('display', 'block');
			$(this).text(moreText);
			$(this).next().text('');
	});
});
/*
//Initialize FAQ Accordian:
ddaccordion.init({
	headerclass: "technology", //Shared CSS class name of headers group
	contentclass: "thelanguage", //Shared CSS class name of contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [0], //index of content(s) open by default [index1, index2, etc]. [] denotes no content.
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: false, //persist state of opened contents within browser session?
	toggleclass: ["closedlanguage", "openlanguage"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["prefix", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "normal", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})
//-->*/

function setVisibility(id) {
	if (id == '22'){
		document.getElementById('state_list').style.display = 'inline';
		document.getElementById('state_list').disabled = false;
		document.getElementById('state_box').disabled = true;
		document.getElementById('state_box').style.display = 'none';
		}
	else {
		document.getElementById('state_list').style.display = 'none';
		document.getElementById('state_list').disabled = true;
		document.getElementById('state_box').disabled = false;
		document.getElementById('state_box').style.display = 'inline';
		}
}


$(document).ready(function(){
	$(".cat_tbl tr").click(function (){		
		window.location.href = $(this).find(".view_td a").attr("href");
	});
	
	$('#prod_tbl td').click(function(){
		
		var a=$(this).parent().find('.enquire_td a');
		var id=a.attr("data-productId");
		
		setCookie("quoteItem",id);
		window.location.href=a[0].href;
		//$(this).parent().find('.enquire_td a').trigger('click');
	});
	
});

function setCookie(name, value){
	
	options = { path: '/'};
	$.cookie(name,value,options);	
}

function getCookie(name){
	var c = $.cookie(name); 
	return c;
}

function loadEnquiryProduct(){
	var cookie = getCookie("quoteItem");
	
	if(cookie){
		$("#quote_item").attr('value',cookie);
		$('.quote_item_td').css('visibility','visible');
	}
	
}

function displaySearchStr(){
	$("#ss_hidden h2").clone().appendTo('#search_str_ctn');	
}

function showLoader(){	
	document.getElementById("page_loader").style.display = 'block';
}



function getQuote(){
	var loc = $('#hidden_loc').text();	
	setCookie('quoteItem', '');
	setCookie('quoteItem', loc);
	window.location.href="/index.php?action=feedback&form_name=quote";
	
	return false;
}

function doSearch(search_form){
	
	var kw = $("#search_name").val();
	
	if(kw=="")
	{
		alert("Invalid search. No Keywords were entered");
		return false;
	}
	
	$("#search_tags").val(kw);
	$("#search_keywords").val(kw);
	
	
	
	/*var c = $(search_form).serialize();
	$.cookie("prod_search", c);*/
	
	setTimeout("showLoader()", 200);
	
	return true;
}

/*function repeatSearch(){
	var cookie = $.cookie("prod_search");
	var  newform=$("#job_detail").append("<form name='pages' id='pages' action='/jobSearch' method='POST'></form>").find("#pages");
	$.each(cookie.split("&"),function(){
		var a = this.split("=");		
		var input  = "<input name='"+a[0]+"' value='"+a[1]+"' type='hidden'/>";
		newform.append(input);		
	});
	
	document.pages.submit();
}*/

function Reg_redir(loc){
	var success = $("#reg_success").text();
	var error = $("#reg_errors").text();
	
	if(error)
		setCookie('reg_msg',error);
	else if(success)
		setCookie('reg_msg',success);
	
	
	window.location.href=loc;
	
}

function loadRegMsg(){
	var reg_msg = getCookie('reg_msg');
	setCookie('reg_msg','');
	if(reg_msg){
		alert(reg_msg);
	}
}






