var mdiv = 'blank_receiver';
var tmpvar = '';
var indexsearching = 0;

function ready(acct){
	menupostLoad(1);
	analyticsLoad(acct);
	//$("#dbox").dialog({autoOpen:false,modal:true,width:'auto',height:'auto'});
	var megaConfig = {interval:150,sensitivity:4,over:loadMenu,timeout:100,out:emptyCall};
	$(".mega").hoverIntent(megaConfig);
	$('.rside > h3').bind('click', function(){toggleExpand(this,$('.rside-in',$(this).closest('.rside')).attr('rel'));});
	$('.rside > h3').each(function(){toggleExpand(this,$('.rside-in',$(this).closest('.rside')).attr('rel'));});
	$('.crumb').bind('mouseover mouseout', function(){crumbs(event,this);});
	/*jQuery('.searchinput').liveSearch({url: '/actions.cfm?task=livesearch&q='});*/
	$('.searchinput').focus();
	$( "#q" ).autocomplete({
		source: "/actions/actions.cfm?task=livesearch",
		minLength: 1,
		delay:0,
		autoFocus:true,
		select: function( event, ui ) {
			window.location.replace(ui.item.id);
		}
	});
	$('.pop').click(function(event){
		event.preventDefault();
		loadContentpopup($(this).attr('rel'));
		trackPageview($(this).attr('href'));
	});
}

function trackPageview(src){
	_gaq.push(['_trackPageview',src]);
}
function analyticsLoad(acct){
	var _gaq = _gaq || [];
	_gaq.push(['_setAccount', acct]);
	_gaq.push(['_trackPageview']);
	
	(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	})();
}
function crumbs(e,ele){//event, element
	if(e.type=='mouseover'){//mouseover
		$(ele).html($(ele).attr("title"));
	}
	else{//mouseout
		$(ele).html($(ele).attr("title").split(' ')[0]+' '+$(ele).attr("title").split(' ')[1]+'...');
	}
}
//expands and retracts narrow column content*******************************************************************
function expander(id1,id2){
	obj1 = document.getElementById(id1);
	obj2 = document.getElementById(id2);
	if (obj2.childNodes[0].data =='more'){
		i=obj1.style.height;
		obj1.style.height='100%';
		obj2.childNodes[0].data = 'less';
	}
	else {
		obj1.style.height=i;
		obj2.childNodes[0].data = 'more';
	}
}
//get image
function nextImage(id,ms){
  $.ajax({
	  url: "actions/actions.cfm",
	  type: "POST",
	  data: {task:'nextImage',id:id},
	  dataType: "text",
	  success: function(idata){
		home_flash(idata,ms);
	  },
	  error: function(){
		  crsr('default');
	  }
	});
}
function home_flash(idata,ms){//n is global set in hompage_img_flash.cfm and tells us which image we're on, images and imageext are global vars that tell us ids of images and extensions
	var wait = (ms==100)?18000:4000;
	var dar = idata.split("|");//0=imga,1=imgip,2=area,3=url,4=keywords
	$('#imga_2').attr('src',('https:' == document.location.protocol ? 'https://s.campbellsci.com/images/' : 'http://s.campbellsci.com/images/')+ 'a-'+images[n]+"."+imageext[n]);
	$('#imgp_2').css('background-image','url('+('https:' == document.location.protocol ? 'https://s.campbellsci.com/images/' : 'http://s.campbellsci.com/images/')+'6-'+dar[1]+'.png)');
  	nextfade = setTimeout(function(){
		var newsrc = $('.icons').not('[src*="g.png"]').attr('src').split(".");
		//alert(newsrc[0]+'.'+'g.png');
		$('.icons').not('[src*="g.png"]').attr('src',newsrc[0]+'g.png').fadeTo(0,1);
		$('#icon'+dar[2]).attr('src','/styles/images/icon'+dar[2]+'.png').fadeTo(500,1);
		$('#imgp_1').fadeTo(50,0,function(){$('#imgpi').attr('src',('https:' == document.location.protocol ? 'https://s.campbellsci.com/images/' : 'http://s.campbellsci.com/images/')+'6-'+dar[1]+'.png');$('#imgp_1').fadeTo(450,1);});
		$('#kwords').fadeTo(50,0,function(){$('#kwords').html(dar[4]);$('#kwords').fadeTo(450,1);});
		$('#imga_1').fadeTo(500,0,function(){
			$('#imga_1').attr('src',('https:' == document.location.protocol ? 'https://s.campbellsci.com/images/' : 'http://s.campbellsci.com/images/')+'a-'+images[n]+"."+imageext[n]);
			setTimeout(function(){
				$('#imga_1').fadeTo(0,1);
				n++;
				if(n >= images.length){n = 0;}
				nextImage(images[n],wait);
			},100);
		});
	},ms);
}

function userChange(){
	$('#imga_1').stop();
	clearTimeout(nextfade);
	var nid = $(this).attr("id").slice(4);
	n = nid-1;
	nextImage(images[n],100);
}

function emptyCall(){
	var nothing = 0;
}
function emptyCall2(){
	$("a:eq(35)").focus();
	var nothing = 0;	
}

//load the main site menu
function loadMenu(){
	var id = $("a",this).attr("rel");//id of category used in name divs
	$('.megamenu').each(function(i) {
    	$(this).css("z-index",100);
  	});
	$("#m"+id).css("z-index",101);
	var hovervars2 = {interval:1,sensitivity:1,over:emptyCall,timeout:300,out:unloadMenu};
	$(".megamenu, #menuoff").hoverIntent(hovervars2);
	$("#m"+id).slideDown(100);
	if(id > 0 && $("#menu"+id).html !=''){
	  crsr('wait');
	  $(".menucontent").html('<p style="text-align:center;margin-top:100px;"><img src="images/site/icons/spinner.gif" /></p>');
	  $.ajax({
		  url: "/actions/actions.cfm",
		  type: "POST",
		  data: {task:'loadMenu',pos:id},
		  dataType: "html",
		  success: function(html){
			  $("#menu"+id).html(html);
			  menusuccess();
			  crsr('default');
		  },
		  error: function(){
			  $("#menu"+id).html('There was error building the menu.');
			  $("#m"+id).slideDown("fast");
			  crsr('default');
		  }
		});
	}else{
		filler = $('#menuPreload'+$("a",this).attr("rel")).html();
		if(filler != undefined){
			$("#menu"+id).html(filler);
			menusuccess();
			$("#m"+id).slideDown("fast");
		}
		else{
			//alert('running the else');
			setTimeout(function(){loadMenu();},500);
		}
	}
}
function menusuccess(){//html
	var hovervars = {interval:150,sensitivity:4,over:loadMenuAct,timeout:300,out:unloadMenuAct};
	$(".menuact,.menuacts").hoverIntent(hovervars);
	$('.menuact').bind('mouseover', function(e){
		e.preventDefault();
	});
}
function unloadMenu(){
	if(indexsearching == 0){
		$(".megamenu").fadeOut(100);
	}
}

function loadMenuAct(){
	crsr('wait');
	var menudiv = $(this).parents(".menudiv").attr('id');//id of the container div the link is in
	var cid = $("a",this).attr("rel");//the rel value of the link hold the parent category id
	var stem = '#' + menudiv.split("-")[0] +"-";//root of the ids
	var curdiv = 1*menudiv.split("-")[1];//id prefix of the current div
	var divact = stem+(curdiv+1);//full id of the next div in line
	$("#"+menudiv+" ul li").removeClass("selitem");//remove all selected formatting
	if($(this).attr("class")=='menuact'){
		$(this).addClass("selitem");//add selected formatting to focused
		for(var i=curdiv+2;i<=4;i++){
			$(stem+i).fadeOut(100);
		}
		var x = $.ajax({
			url: "/actions/actions.cfm",
			type: "POST",
			data: {task:'loadMenuAct',id:cid},
			dataType: "html",
			success: function(html){
				$(divact).html(html);
				$(divact).fadeIn(300);
				menusuccess();
				crsr('default');
			},
			error: function(){
				$(divact).html('There was error building the menu.');
				crsr('default');
			}
		});	
	}
	else{
		if($(divact)){
			$(divact).fadeOut(100);
			crsr('default');
		}
	}
}

function unloadMenuAct(){
	var temp = 1;
}

function menupostLoad(on){
	$.ajax({
		url: "/actions/actions.cfm",
		type: "POST",
		data: {task:'postMenuload'},
		dataType: "html",
		success: function(html){
			$('#postLoadholder').html(html);
		},
		error: function(){
			if(on < 5){
			setTimeout(function(){postLoad(on+1);},300);
			}
			
		}
	});
}

function loadPopup(info){
	$('body').append('<div id="popit" class="popbox"></div>');
	$.ajax({
		url: "/actions/actions.cfm",
		type: "POST",
		data: {task:'loadPopup',data:info+'|'+urlvars},
		dataType: "html",
		success: function(html){
			$('#postLoadholder').html(html);
		},
		error: function(){
			if(on < 5){
			setTimeout(function(){postLoad(on+1);},300);
			}
		}
	});
}
function loadContentpopup(rel){//expects vars in this format: id:36|title:Ask an Expert|a:2 --requires component id and title, other vars optional
	crsr('wait');
	var str = rel.replace(/\|/g,'","');
	var str = str.replace(/:/g,'":"');
	var str = '{' + '"task":"contentpop","' + str + '"}';
	var data = jQuery.parseJSON(str);
	var qstr = $.param(data, true);
	$('#container').append('<div id="contentpop" class="popbox"></div>');
	$.ajax({
		url: "/actions/actions.cfm?"+qstr+'&q',//if url.p isdefined, popup is loaded
		type: "POST",
		data: data,
		dataType: "html",
		success: function(html){
			$('#contentpop').html(html);
			$('#contentpop').dialog({title:data.title,stackable:true,modal:true,position:'center',beforeClose:function(){$('#contentpop').dialog('destroy').remove();}});
			crsr('default');
		},
		error: function(){
			$('#contentpop').dialog({title:'Error',beforeClose:$('#helpbox').remove()});
			$('#contentpop').html("There was an error.");
			crsr('default');
		}
	});
/*	$('#container').append('<div id="contentpop" class="popbox"></div>');
	$.ajax({
		url: "/actions/actions.cfm",
		type: "POST",
		data: {task: "contentpop",data:info+'|'+pagevars},
		dataType: "html",
		success: function(html){
			$('#contentpop').html(html).css('overflow-y','auto');
			$('#contentpop').dialog({title:title,stackable:true,beforeClose:$('#helpbox').remove(),modal:true,position:'center',height:550,width:650});
			crsr('default');
		},
		error: function(){
			$('#contentpop').dialog({title:'Error',beforeClose:$('#helpbox').remove()});
			$('#contentpop').html("There was an error.");
		}
	});
*/}

function slider(ste,div){//state - 0:closed, 1:mid, or 2:full
  $("#topbar-show").toggle(function(){
   $(div).animate({height:20},200);
  },function(){
    $(div).animate({height:100},200);
  },function(){
    $(div).animate({height:1000},200);
  });


	if(ste==0){
		$(div).animate({ height: 'toggle' }, 3000);
	}
	else if(ste==1){
		$(div).slideDown("fast");
	}
	else{
		$(div).slideDown("fast");
	}
}

//call the jquery dialog box
function loadbox(){
	crsr('wait');
	$('#dbox').html('<img src="images/site/icons/spinner.gif" /> Loading...');
	/*$.ajax({
		url: "actions/actions.cfm",
		type: "POST",
		data: {task:task,data:data},
		dataType: "html",
		success: function(html){
			$('#dbox').dialog({title:'Campbell Scientific CMS' });
			$('#dbox').html(html);
			$("#dbox").dialog({position:'center'});
			crsr('default');
		},
		error: function(){
			$('#dbox').dialog({title:'Error' });
			$('#dbox').html("There was an error.");
		}
	});*/
	$("#dbox").dialog("open");
}

function crsr(what){
	document.body.style.cursor=what;
}

//validation for ask our expert form****************************************************************************
function askit(form){
	if(form.name.value==""){
		alert('Please enter your name.  ');
		form.name.focus();
		return false;
	}
	else if (form.email.value==""){
		alert('Please enter your email address.  ');
		form.email.focus();
		return false;
	}
	else if (isEmail(form.email.value)==false){
		alert('Please enter a valid email address.  ');
		form.email.select();
		return false;
	}
	else if(form.question.value==""){
		alert('Please enter a comment or question.  ');
		form.question.focus();
		return false;
	}
	else {
		//form.submit();
	}
}
//validation for email addresses***********************************************************************************
function isEmail(str) {
  //return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

//validation for sales questions************************************************************************************
function validate_question(form){
	if (form.support.value == ''){
		alert('Please tell us how we can help you.  ');
		form.support.focus();
		return false;
	}
	else if (form.name.value == ''){
		alert('Please enter your Name.  ');
		form.name.focus();
		return false;		
	}
	else if (form.org.value == ''){
		alert('Please enter the name of your Organization.  ');
		form.org.focus();
		return false;		
	}
	else if (form.email.value == ''){
		alert('Please enter your Email Address.  ');
		form.email.focus();
		return false;		
	}
	else if (isEmail(form.email.value)==false){
		alert('Please enter a valid Email Address.  ');
		form.email.select();
		return false;
	}
	else if (form.phone.value == ''){
		alert('Please enter your Phone Number.  ');
		form.phone.focus();
		return false;		
	}
	else if (form.country.value < 1){
		alert('Please select your Country.  ');
		form.country.focus();
		return false;		
	}
	return true;
}
//thumbnail scroller***********************************************************************************
function scroller(id,way,px){
	if (way=='right'){
		margin=document.getElementById(id).style.marginLeft.substring(0,document.getElementById(id).style.marginLeft.length-2);
		document.getElementById(id).style.marginLeft=margin-px + 'px';		
	}
	else {
		margin=document.getElementById(id).style.marginLeft.substring(0,document.getElementById(id).style.marginLeft.length-2);
		if (margin >= 0){
			margin=0;
		}
		else{
		document.getElementById(id).style.marginLeft=margin*1+px*1 + 'px';		
		}
	}
}
// returns random number between 1 and passed variable
function getRandom(upto){
   return (Math.round(Math.random()*(upto-1)))+1;
}
// Loads random images
function rand_image(image_name,num){
	//alert(num);
	document.getElementById(image_name).src='images/index' + getRandom(num) + '.jpg';
}

function reload_quick(){
	if (document.quick.back_refresh.value==1){
		location.replace('/33');
		//location.href='/33';
	}
}

function ajax_load_aetools(){
	$('body').append('<div id="aediv" class="popbox"><div id="popclose" onclick="close_aepop();"></div><div id="popcontent">&nbsp;</div></div>');
	$.post("/actions/actions.cfm", { task: "load_aetools"},
	  function(data){
		$('#popcontent').html(data);
		$('#aediv').dialog({title:'Customer Tools',stackable:true,beforeClose:$('#aediv').remove(),modal:true,position:'center',height:600,width:1010});
		$("#f1val").focus();
		$("#pcodes").bind("click",function(){o_pricshow();});
		$("#lcc").bind("click",function(){load_chunk('ae_content','load_chunk',100);});
		$(".forms").bind("submit",function(){
			var pre = $(this).attr('id');
			var num = pre.charAt(1);
			var val = $('#'+pre+'val').val();
			search_custom(val,num);
			return false;
		});
		$(".forms2").bind("submit",function(){
			var pre = $(this).attr('id');
			var num = pre.charAt(1);
			var val = $('#'+pre+'val').val();
			//alert(val.length);
			if(val.length >= 4){
				search_custom(val,num);
			}
			else {
				alert('To limit processing, please enter at least 4 characters.');	
			}
			
			return false;
		});
	  });
		
}
function search_custom(sval,cse){//value of searchbox, which case to run
	$('#ae_content').html('<img src="/styles/images/icons/spinner.gif" /> Searching..');
	$.post("/actions/actions.cfm", { task: "search_custom",sval:sval,cse:cse},
	  function(data){
		$('#ae_content').html(data);
	  });
}

function send_invite(email,id){
	$.post("/actions/actions.cfm", { task: "send_invite",email:email,id:id},
	  function(data){
		$('#invitearea_'+id).html('An invitation has been sent to '+email+'.<br />A copy was also sent to your email.');
	  });
}

function addLoadListener(fn){
	if (typeof window.addEventListener != 'undefined'){
		window.addEventListener('load', fn, false);
 	}
 	else if (typeof document.addEventListener != 'undefined'){
   		document.addEventListener('load', fn, false);
	}
 	else if (typeof window.attachEvent != 'undefined'){
   		window.attachEvent('onload', fn);
 	}
 	else {
   		var oldfn = window.onload;
   		if (typeof window.onload != 'function'){
     		window.onload = fn;
   		}
   		else {
     		window.onload = function(){
       			oldfn();
       			fn();
     		};
   		}
 	}
}
//find element position from quirksmode
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

//add file into the head
function add_scripts(file){
	var head = document.getElementsByTagName('head').item(0)
	var scriptTag = document.getElementById('loadScript');
	if(scriptTag) head.removeChild(scriptTag);
	script = document.createElement('script');
	script.src = file;
	script.type = 'text/javascript';
	script.id = 'loadScript';
	head.appendChild(script)
}  

function load_calendar(field){
	Calendar.setup({
		inputField     :    field,   // id of the input field
		ifFormat       :    "%m/%d/%Y",       // format of the input field
		showsTime      :    false,
		cache:true,
		weekNumbers:true
	});
}


function menu_search(form,str,menu){
	search_string = str.toUpperCase();
	text_length = search_string.length;
	var i=document.getElementById(menu).options.length;
	var e=0;
	do {
		test_item = document.getElementById(menu).options[e].text;
		match_item = test_item.substr(0, text_length).toUpperCase();	
		if(search_string == match_item){
			document.getElementById(menu).selectedIndex = e;
			break;
		}
		e++;
	}
	while (--i);
}

//http://www.expertsforge.com/Web-Development/Tutorial-217.asp
function Left(str, n)
{
   if (n <= 0)
         return "";
   else if (n > String(str).length)
         return str;
   else
         return String(str).substring(0,n);
}


function kill_tiny_mces(){
	tinytokill = document.getElementsByTagName("iframe");
	start = 0;
	if(tinytokill.item(0) != null && tinytokill.item(0).id == ''){start = 2};
	if(tinytokill.length > start){
		for(i=start;i<=tinytokill.length;i++){
			if(tinytokill.item(0).id.length > 4){
				tinyMCE.execCommand('mceRemoveControl', false, Left(tinytokill.item(0).id,tinytokill.item(0).id.length-4));
			};
		}
	kill_tiny_mces()
	}
}

function kill_tiny_mces2(){
	tinytokill = document.getElementsByTagName("iframe");
	if(tinytokill.length > 2){
		for(i=2;i<=tinytokill.length;i++){
				tinyMCE.execCommand('mceRemoveControl', false, Left(tinytokill.item(0).id,tinytokill.item(0).id.length-4));
		}
	kill_tiny_mces2()
	}
}


function dumpProps(obj, parent) {
   // Go through all the properties of the passed-in object
   for (var i in obj) {
      // if a parent (2nd parameter) was passed in, then use that to
      // build the message. Message includes i (the object's property name)
      // then the object's property value on a new line
      if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
      // Display the message. If the user clicks "OK", then continue. If they
      // click "CANCEL" then quit this level of recursion
      if (!confirm(msg)) { return; }
      // If this property (i) is an object, then recursively process the object
      if (typeof obj[i] == "object") {
         if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
      }
   }
}

function myCustomOnChangeHandler(inst) {
	tinyMCE.triggerSave(false,true);
}

function inittiny(ht){
	var h = (!ht)?'400px':ht;
		$('.tiny_area').tinymce({
                        // Location of TinyMCE script
                        script_url : '/gu/scripts/tiny_mce/tiny_mce.js',
		theme : "advanced",
		mode : "specific_textareas",
		editor_selector : "tiny_area",
		onchange_callback : "myCustomOnChangeHandler",
		plugins : "table,fullscreen,emotions,contextmenu,paste",
		theme_advanced_buttons1 : "bold,italic,underline,format,separator,bullist,numlist,separator,link,unlink,separator,image,separator,table,hr,charmap,h1,separator,code,fullscreen,help",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		valid_elements : "*[*]",
		invalid_elements : "pre",
		setup : function(ed) {
			ed.onClick.add(function(ed) {
				$('#'+ed.id+'_ifr').height(h);
				$('#'+$(this).attr("id")+"_savebutton").html('Save Me!').css({'color':'#cc0033','font-weight':'bold'});
				document.getElementById(ed.id+'_ifr').contentDocument.getElementById('tinymce').setAttribute('spellcheck','true');
			})
		},
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "center",
		theme_advanced_styles:"tgray = tgray",
		fullscreen_settings : {
			theme_advanced_buttons1 : "bold,italic,underline,format,separator,bullist,numlist,separator,link,unlink,separator,image,separator,table,hr,charmap,h1,separator,code,fullscreen",
			//valid_elements : "a[href],strong/b,em/i,br,p,table,tr,td,li,ol,ul,strike,img[src|height|width]"
		paste_create_paragraphs : true,
		paste_create_linebreaks : true,
		paste_use_dialog : true,
		paste_auto_cleanup_on_paste : true,
		paste_convert_middot_lists : false,
		paste_unindented_list_class : "unindentedList",
		paste_convert_headers_to_strong : false,
		paste_remove_styles : true,
		paste_insert_word_content_callback : "convertWord",
		paste_strip_class_attributes: "all"
		}
	})
}

function convertWord(type, content) {
	switch (type) {
		// Gets executed before the built in logic performes it's cleanups
		case "before":
			//content = content.toLowerCase(); // Some dummy logic
			break;

		// Gets executed after the built in logic performes it's cleanups
		case "after":
			//content = content.toLowerCase(); // Some dummy logic
			break;
	}

	return content;
}

function stripVowelAccent(str)
{
var s=str;

var rExps=[ /[\xC0-\xC2]/g, /[\xE0-\xE2]/g,
/[\xC8-\xCA]/g, /[\xE8-\xEB]/g,
/[\xCC-\xCE]/g, /[\xEC-\xEE]/g,
/[\xD2-\xD4]/g, /[\xF2-\xF4]/g,
/[\xD9-\xDB]/g, /[\xF9-\xFB]/g ];

var repChar=['|A|','|a|','|E|','|e|','|I|','|i|','|O|','|o|','|U|','|u|'];

for(var i=0; i<rExps.length; i++)
s=s.replace(rExps[i],repChar[i]);

return s;
}

function inittiny2(){
	tinyMCE.init
		({
		theme : "advanced",
		mode : "specific_textareas",
		editor_selector : "hist_tiny_area",
		onchange_callback : "myCustomOnChangeHandler",
		plugins : "table,fullscreen,emotions,contextmenu",
		theme_advanced_buttons1 : "bold,italic,underline,format,separator,bullist,numlist,separator,link,unlink,separator,table,hr,charmap,h1,separator,code,fullscreen",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "center",
		valid_elements : "a[href],strong/b,em/i,br,p[*],table[border=0|cellspacing|cellpadding|width|height|class|align|summary|style|dir|id|lang|bgcolor|background|bordercolor],tr[id|lang|dir|class|rowspan|width|height|align|valign|style|bgcolor|background|bordercolor],tbody[id|class],thead[id|class],tfoot[id|class],td[id|lang|dir|class|colspan|rowspan|width|height|align|valign|style|bgcolor|background|bordercolor|scope],th[id|lang|dir|class|colspan|rowspan|width|height|align|valign|style|scope],li,ol,ul,strike,img[src|height|width|style],h2[style],h3[style],input[*],form[*],div[*],button[*],object[*],param[*],embed[*]",
		invalid_elements: "pre",
		fullscreen_settings : {
			theme_advanced_buttons1 : "bold,italic,underline,format,bullist,numlist,link,unlink,tablecontrols,hr,charmap,emotions,code,fullscreen",
			//valid_elements : "a[href],strong/b,em/i,br,p,table,tr,td,li,ol,ul,strike,img[src|height|width]"
		paste_create_paragraphs : true,
		paste_create_linebreaks : true,
		paste_use_dialog : true,
		paste_auto_cleanup_on_paste : true,
		paste_convert_middot_lists : false,
		paste_unindented_list_class : "unindentedList",
		paste_convert_headers_to_strong : false,
		paste_remove_styles : true,
		paste_insert_word_content_callback : "convertWord",
		paste_strip_class_attributes: "all"
		}
		});
	
}

function toggle_admin_box(){
	$('#admin_tool_box').toggle();
}

function send_tooldisplay(toggle){
		document.cookie= 'loadadmin='+toggle+'; expires = 1/1/2038;';
		document.cookie= 'LOADADMIN='+toggle+'; expires = 1/1/2038;';
}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Today's Date 
function todaydate(){
	var months=new Array(13);
	months[1]="January";
	months[2]="February";
	months[3]="March";
	months[4]="April";
	months[5]="May";
	months[6]="June";
	months[7]="July";
	months[8]="August";
	months[9]="September";
	months[10]="October";
	months[11]="November";
	months[12]="December";
	
	var time=new Date();
	var lmonth=months[time.getMonth() + 1];
	var date=time.getDate();
	var year=time.getYear();
	
	if ((navigator.appName == "Microsoft Internet Explorer") && (year < 2000)){ 
		year="19" + year; 
	}
	if (navigator.appName == "Netscape"){
		year=1900 + year;
	}
	var d = lmonth + " " + date + ", " + year;
	return d;
}


function imageswap(img,id){
	var image = img.src;
	var image_name = image.substring(0,image.length-4);
	var image_ext = image.substring(image.length-4,image.length);
	if (id == 1){
		if (document.getElementById('bigimg').style.display=='none'){
			document.images.bigimg.src = image_name+'-b'+image_ext;
			document.getElementById('bigimg').style.display='block';
			document.getElementById('litimg').innerHTML='&laquo;click to hide big image&raquo;'
		}
		else {
			document.getElementById('bigimg').style.display='none';
			document.getElementById('litimg').innerHTML='&laquo;click image to enlarge&raquo;'
		}
	}
	else {
		if (image_name.substring(image_name.length-2,image_name.length)=='-b'){
			img.src = image_name.substring(0,image_name.length-2) + image_ext;
		}
		else {
			img.src = image_name + '-b' + image_ext;
		}
	}
}
//tab mouseovers**************************************************************************************
function tab_over(tab){
	for (i=1;i<10;i++){//tab_out any existing tabs.
		if(document.getElementById('tab'+ i) && document.getElementById('tab'+ i).style.height=='27px'){
			tab_out(document.getElementById('tab'+ i));
			break;
		}
	}
	tab.style.height='27px';
	tab.style.marginTop='0';
}
function tab_out(tab){
	tab.style.height='20px';
	tab.style.marginTop='7px';
}
function tabset(tab,act,num){
	switch (act){
		case "expand_all":
			for (x=1;x<=num;x++){
				if (document.getElementById('tab'+ x).style.color=='#999999' || document.getElementById('tab'+ x).style.color=='rgb(153, 153, 153)'){
					continue;
				}
				document.getElementById('tab_'+ x).style.display='block';
				document.getElementById('tab'+ x).style.visibility ='hidden';
			}
			document.getElementById('exp_id').style.display='none';
			document.getElementById('col_id').style.display='block';
			break;
		case "collapse_all":
			for (x=2;x<=num;x++){
				document.getElementById('tab_'+ x).style.display='none';
				document.getElementById('tab'+ x).style.visibility ='visible';			
			}
			document.getElementById('tab_1').style.display='block';
			document.getElementById('tab1').style.visibility ='visible';			
			document.getElementById('col_id').style.display='none';
			document.getElementById('exp_id').style.display='block';
			break;
		default://front
			if (document.getElementById('tab'+ tab).style.color=='#999999' || document.getElementById('tab'+ tab).style.color=='rgb(153, 153, 153)'){
				return false;
			}
			for (x=1;x<=num;x++){
				document.getElementById('tab_'+ x).style.display='none';
				//document.getElementById('tab'+ x).style.color='#000000';	
				document.getElementById('tab' + x).style.height='20px';
			}
			if (tab==5){
				document.getElementById('kbase').src='../kbase/knowbase2.cfm?term=' + prodid.split('-L')[0] + '&filter=all&sortbox=order by custom2 desc';
			}
			document.getElementById('tab_' + tab).style.display='block';
			document.getElementById('tab'+ tab).style.height='27px';
			document.getElementById('tab'+ tab).style.marginTop='0';
			//document.getElementById('tab'+ tab).style.color='#000066';	
		}
}

function elmLoop(formm,ajax_nme,showunchecked){
	var onname = '';
	valstring = ajax_nme;
	theForm = document[formm];
	
	if(theForm.elements == undefined){
		return false;	
	}
	for(i=0; i<theForm.elements.length; i++){
		var alertText = ""
		
		if(theForm.elements[i].type == "text" || theForm.elements[i].type == "textarea" || theForm.elements[i].type == "button"){
			if(theForm.elements[i].value != ''){
				valstring = valstring+'&'+theForm.elements[i].name+'='+ theForm.elements[i].value;	
			}else{
				if(theForm.elements[i].title.length > 0){
					alert(theForm.elements[i].title);
				}else{
					alert('Please provide the requested information');
				}
				theForm.elements[i].focus();
				return false;
			}
		}
		else if(theForm.elements[i].type == "password"){
			if(theForm.elements[i].value == ''){
				if(theForm.elements[i].title.length > 0){
					alert(theForm.elements[i].title);
				}else{
					alert('Please provide the requested information');
				}
				theForm.elements[i].focus();
				return false;
			}
			valstring = valstring+'&'+theForm.elements[i].name+'='+ theForm.elements[i].value;	
		}
		else if(theForm.elements[i].type == "hidden"){
		valstring = valstring+'&'+theForm.elements[i].name+'='+ theForm.elements[i].value;	
		}
		else if(theForm.elements[i].type == "checkbox" || theForm.elements[i].type == "radio"){
			if(showunchecked != 1){
				if(theForm.elements[i].checked == true){
					if(onname != theForm.elements[i].name){
						onname = theForm.elements[i].name;	
						valstring = valstring+'&'+theForm.elements[i].name+'='+ theForm.elements[i].value;	
					}else{
						valstring = valstring +','+ theForm.elements[i].value;
					}
				}
			}else{
				if(onname != theForm.elements[i].name){
					onname = theForm.elements[i].name;	
					valstring = valstring+'&'+theForm.elements[i].name+'='+ theForm.elements[i].checked;
				}else{
					valstring = valstring +','+ theForm.elements[i].checked;
				}
			}
		}else if(theForm.elements[i].type == "select-one"){
			valstring = valstring +'^'+ theForm.elements[i].options[theForm.elements[i].selectedIndex].text;
		}
	}
	return valstring;
} 

function preview_it(id){
	$('#blank_reciever').css({'position': 'absolute', 'top':'100','background':'#FFFFFF','display':'block'}).html('<div style="padding:20px; border:solid 1px; text-align:center;"><img src="indd/a-'+id+'.png" id="previmg" /><br /><a href="javascript:void(0);" onclick="close_it();">close</a></div>');
	move_it();
	$('#shell_fix_wide').fadeTo(1,0.2);
	$('#shell_bot_wide').fadeTo(1,0.2);
}

function position_pop(){
	divid = mdiv;
	divwidth = document.getElementById(divid).offsetWidth;
	windowwidth = window.innerWidth;
	leftit = windowwidth-divwidth;
	if(isNaN(leftit) == false){
		document.getElementById(divid).style.left=leftit*.5+'px';
		divheight = document.getElementById(divid).offsetHeight;
		windowheight = window.innerHeight;
		topit = windowheight-divheight;
		if(topit >= 0){
			document.getElementById(divid).style.top =topit*.5+window.pageYOffset+'px';
			//document.getElementById(divid).style.top ='90px';
		}else{
			document.getElementById(divid).style.top = '60px';
		}
	}else{
		windowwidth = $(window).width();
		leftit = windowwidth-divwidth;
		document.getElementById(divid).style.left=leftit*.5+'px';
		divheight = document.getElementById(divid).offsetHeight;
		windowheight = $(window).height();
		topit = windowheight-divheight;
		document.getElementById(divid).style.top = '60px';
	}
	document.getElementById(mdiv).style.visibility = 'visible';
}

function move_it(div,speed){
	if(speed == undefined){
		speed = 300;	
	}
	if(div == undefined){
		div = 'blank_reciever';	
	}
	mdiv = div;
	//document.getElementById(mdiv).style.visibility = 'hidden';
	setTimeout('position_pop();',speed);
}

function close_it(){
	displayit('blank_reciever');
	$('#shell_fix_wide').fadeTo(1,1);
	$('#shell_bot_wide').fadeTo(1,1);
}


function copy_date(valu,curfield,getfield){
	if(valu == ''){
		$(curfield).value = $(getfield).value;
	}
}

//sets the style of whatever div is passed to display or hide
function displayit(id,state){
	if(state == 1){//1 = display it
		document.getElementById(id).style.display = 'block';	
	}else{//else hide it
		document.getElementById(id).style.display = 'none';	
	}
}

function more_images(type,id){
	$('#container').append('<div id="moreimages"><div id="popcontent"></div></div>');
	$.ajax({
		url: "/actions/actions.cfm",
		type: "POST",
		data: {task:"more_images",type:type,id:id},
		dataType: "html",
		success: function(html){
			$('#moreimages').dialog({title:'Image Gallery',position:'center',modal:true,height:540,width:650,beforeClose:function(){$('#moreimages').dialog('destroy').remove();}});
			$('#popcontent').html(html);
			inittiny();
		},
		error: function(){
			$('#moreimages').dialog({title:'Error',position:'center',height:'auto',width:'auto',beforeClose:function(){$('#moreimages').dialog('destroy').remove();}});
			$('#popcontent').html("There was an error.");
		}
	});
	/*$.post("action.cfm", { vars: "more_images",type:type,id:id },
	function(data){
		$('body').prepend('<div id="popdiv"><div id="popclose" onclick="close_pop();"></div><div id="poptitle">Image Gallery</div><div id="popcontent">&nbsp;</div></div><div id="popback">&nbsp;</div>');
		if(jQuery.browser.version == 6.0 && jQuery.browser.msie == true){
			$('body').css({'width':'100%','height':'100%'});
			$('#popback').css({'position':'absolute'});
			$('#popdiv').css({'position':'absolute'});
		}
		move_it('popdiv',0);
		$("#popcontent").html(data);
		$('#popback').fadeTo(500,0.7,function(){$('#popdiv').fadeTo(250,1.0);});
	});*/
}

function more_chngimage(id,caption){
	$("#image").html('<img src="'+('https:' == document.location.protocol ? 'https://s.campbellsci.com/images/' : 'http://s.campbellsci.com/images/')+ '10-'+id+'.png"><div class="img_caption">'+caption+'</div>');	
}

function close_pop(){
	$('#popdiv').fadeTo(100,0.1); 
	$('#popback').fadeTo(250,0.1,function(){
		if(jQuery.browser.version == 6.0 && jQuery.browser.msie == true){
			$('body').css({'width':'','height':''});
		}
		$('#popback').remove();
		$('#popdiv').remove();
	});
}

function close_aepop(){
	$('#aediv').fadeTo(100,0.1); 
	$('#popback').fadeTo(250,0.1,function(){
		if(jQuery.browser.version == 6.0 && jQuery.browser.msie == true){
			$('body').css({'width':'','height':''});
		}
		$('#popback').remove();
		$('#aediv').remove();
	});
}



function default_prod_view(viewid,hideafter){
	$.post("/actions/cc_actions.cfm", { vars: "default_prod_view",viewid:viewid },
	function(data){
		//$('#prod_defaultview').html('<img src="images/site/check.png" alt="Default Page View" align="absmiddle" id="prod_defaultview_img" /> Default view updated');
		//if(hideafter){
		//	setTimeout('$("#prod_defaultview").empty()',3000);	
		//}
	});
}

function add_quickquote(prodid){
	$.post("/actions/actions.cfm", { vars: "add_quickquote",prodid:prodid },
	function(data){
		tmpvar = $('.prod_info_box').html();
		$('.quick_quote_links').attr({'href':'/quick-quote','onclick':''}).css('color','#000000');
		$('#add_quickquote_txt').html('View Quick Quote');
		$('#add_quickquote_img').attr('src','images/site/check.png');
		$('.prod_info_box').html(data);
	});
	return false;
}

//add to downloadlist
function add_download(dlid){
	$.post("action.cfm", { vars: "add_download",download:dlid },
	function(data){
		//tmpvar = $('.prod_info_box').html();
		$('.quick_quote_links')
		$('#add_dl_'+dlid).html('view download list').attr({'href':'/19_2_0','onclick':''});
		//$('#add_quickquote_img').attr('src','images/site/check.png');
		//$('.prod_info_box').html(data);
	});
	return false;
}

//new product component display for case studies, rotates through them
function fade_cs(show,playcs){	
	if(show > maxcs){
		show = maxcs;
	}else if(show < 1){
		show = 1;
	}							
	if(show <= maxcs && show > 0){
		for(i=1;i<=maxcs+1;i=i+1){
			$('#cs_'+i).fadeOut(0);
		}
		fadenext = oncur+1;
		
		$('#cs_'+oncur).fadeOut(200);
		$('#cs_'+show).fadeIn(400);
		$('#cs_'+fadenext).fadeIn(400);
		oncur = show*1;
		change_cs_navbuttons(show);
		if(playcs == 1 && playcsvar == 1){
			setTimeout('cs_rotater()',10000);
		}else{
			playcsvar = 0;
		}
	}
}

//part of the rotation function
function cs_rotater(){
	if((oncur*1) +1 <= maxcs){
		oncur = oncur + 1;
	}else{
		oncur = 1*1;
	}
	if(playcsvar == 1){
		fade_cs(oncur,1);
	}
}

//more of the rotation function, modifies the navigation buttons
function change_cs_navbuttons(onnum){
	if(oncur ==1){
		//$('#cs_button_l').css('color','#CCCCCC');
		//$('#cs_button_1').css('background-image','url(/images/site/toolbar-back.png)');
		//$('#cs_button_2').css('background-image','url(/images/site/toolbar-back-dark.png)');
	//	$('#cs_button_3').css('background-image','url(/images/site/toolbar-back-dark.png)');
		$('#cs_button_1').html('1').css({'border':'solid 1px #d6d6d6','background-color':'#f3f3f3'});
		$('#cs_button_2').html(2).css({'border':'','background-color':''});
		$('#cs_button_3').html(3).css({'border':'','background-color':''});
	}else if(oncur != maxcs){
		//math = (oncur*1)-1+i;
		$('#cs_button_l').css('color','#000000');
		$('#cs_button_r').css('color','#000000');
		$('#cs_button_1').html(oncur*1-1).css({'border':'','background-color':''});
		$('#cs_button_2').html(oncur).css({'border':'solid 1px #d6d6d6','background-color':'#f3f3f3'});
	//	$('#cs_button_1').css('background-image','url(/images/site/toolbar-back-dark.png)');
	//	$('#cs_button_2').css('background-image','url(/images/site/toolbar-back.png)');
	//	$('#cs_button_3').css('background-image','url(/images/site/toolbar-back-dark.png)');
		$('#cs_button_3').html(oncur*1+1);
	}else{
		$('#cs_button_r').css('color','#CCCCCC');
		$('#cs_button_1').css({'border':'','background-color':''});
		$('#cs_button_2').css({'border':'','background-color':''});
		$('#cs_button_3').css({'border':'solid 1px #d6d6d6','background-color':'#f3f3f3'});
		$('#cs_button_'+i).attr('onclick','play=0;fade_cs('+i+',0);').html(i).css({'border':'solid 1px #d6d6d6','background-color':'#f3f3f3'});
	}
}

//apr 7 2010 open case study on the same page
var cstmpvar = '';
var csrepdiv = '';
function load_casestudy(csid,replacediv,onid){
	$.post("action.cfm", { vars: "load_casestudy",caseid:csid,prodid:onid},
	function(data){
		cstmpvar = $('#'+replacediv).html();
		csrepdiv = replacediv;
		$('#'+replacediv).html(data);
	});
	return false;
}


//oct 8th open user preferences window
function open_user_preferences(){
	$('#container').append('<div id="contentpop" class="popbox"></div>');
	$.post("/actions/cc_actions.cfm", { vars: "user_preferences"},
	function(data){
		$("#contentpop").html(data);
		$("#contentpop").append('<button style="float:right;padding:5px 10px;" id="saveprefs">Save</button>');
		$('#contentpop').dialog({title:'Preferences',stackable:true,modal:true,position:'center',beforeClose:function(){$('#contentpop').dialog('destroy').remove();reload_content();}});
		//$('#popdiv').dialog({title:'Preferences',stackable:true,modal:true,position:'center',height:475,width:640,beforeClose:function(){$('body').css('overflow-y','');reload_content();}});
		$('#saveprefs').click(function() {$('#contentpop').dialog("close");});
	});
}

// change any cookie oct 9th
function change_cookie(cookiename,newvalue){
	$.post("/actions/cc_actions.cfm", { vars: "change_cookie",cookie:cookiename,val:newvalue},
	function(data){
		
	});
}

function change_pc(col,newvalue){
	$.post("/actions/cc_actions.cfm", { vars: "change_pc",val:newvalue,col:col},
	function(data){
		reload_content();
	});
}

function change_keyadshow(newvalue){
	$.post("/actions/cc_actions.cfm", {vars:"change_keyadshow",newval:newvalue},
	function(data){
		reload_content();
	});
}


function reload_area(locat,template){
	upddiv = 'loc'+template+'_'+locat;
	$('#shell_fix').fadeTo(1000,1);
	$('#shell_bot').fadeTo(1000,1);
	$('#page_admin_box').css("display","none");
	
	$.post("action.cfm", { vars: "load_location",locat:locat,template:template,urla:urla,urlb:urlb,urlc:urlc,urld:urld},
	  function(data){
		$('#'+upddiv).html(data);
	  });
}





/*	//var divheight = $('#cat_desc').height();
	function view_amntchange(element,speed){
		if(speed == undefined){
			speed = 1000;
		}
	//	newheight = divheight;
		newheight = '1000px';
		if($(element).height() == divheight){
			newheight = '28px';
		}
		if($(element).height() == divheight){
			$('#view_control_'+element).html('...&nbsp;&nbsp;(<span class="navtext">more</span>)');
		}else{
			$('#view_control_'+element).html('<span class="navtext">(less)</span>');
		}
		$(element).animate({height:newheight,},speed);
	}
	*/
	
function toggle_supportdiv(thediv){
	if($('#help_holder_'+thediv).height() == 80){
		$('#help_holder_'+thediv).height('auto');
		$('#toggle_holder_'+thediv).html('expand this support area');
	}else{
		$('#help_holder_'+thediv).height(80);
		$('#toggle_holder_'+thediv).html('collapse this support area');
	}
}

function load_chunk(container,action,id){
	$("#"+container).load("action.cfm",{id:id,vars:action});	
}

function toggleExpand(thisval,midval){
	if(midval == undefined){
		midval = 105;	
	}
	if($('.rside-in',$(thisval).closest('.rside')).attr('mode') == undefined && $('.rside-in',$(thisval).closest('.rside')).height() > midval){
		$('.rside-in',$(thisval).closest('.rside')).attr('mode',1);
	}else if($('.rside-in',$(thisval).closest('.rside')).attr('mode') == undefined){
		$('.rside-in',$(thisval).closest('.rside')).attr('mode',2);
	}
	
	if($('.rside-in',$(thisval).closest('.rside')).attr('mode')== 1){
	  if($('.rside-in',$(thisval).closest('.rside')).attr('name') ==1 || $('.rside-in',$(thisval).closest('.rside')).attr('name') == undefined){
			  $(".rside-in",$(thisval).closest('.rside')).animate({height:midval},200).css('padding','').attr('name',2);
	  }else if($('.rside-in',$(thisval).closest('.rside')).attr('name') == 2){
			  $(".rside-in",$(thisval).closest('.rside')).animate({height:'100%'},200).attr('name',0);
	  }else{
			  $(".rside-in",$(thisval).closest('.rside')).animate({height:0},200).css('padding','0').attr('name',1);;
	  }
	}else{
		$('.rside-in',$(thisval).closest('.rside')).slideToggle();
	}
/*	switch(state){
		case 1:
			alert('should run');
			$(".rside-in",$(thisval).closest('.rside')).animate({height:150},200);
			alert('should run');
			$(".rside-in",$(thisval).closest('.rside')).attr('name',2);
			alert('should run');
		break;
		case 2:
			$(".rside-in",$(thisval).closest('.rside')).animate({height:auto},200);
			$(".rside-in",$(thisval).closest('.rside')).attr('name',0);
		break;
		default:	
			$(".rside-in",$(thisval).closest('.rside')).animate({height:0},200);
			$(".rside-in",$(thisval).closest('.rside')).attr('name',1);
	}
	$(".rside-in",thisval).toggle(function(){
  		$(this).animate({height:32},200);
  	},function(){
    	$(this).animate({height:100},200);
  	},function(){
    	$(this).animate({height:1000},200);
  	});*/
}


/**
* hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne brian(at)cherne(dot)net
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);

function liveKeys(e){
	if(e=='38'){
		alert('up arrow was pressed');
	}
	else {
		alert('down arrow was pressed');
	}
}

function ask_an_expert(theform){
	if(theform.name.value==""){
		alert('Please enter your name.  ');
		form.name.focus();
		return false;
	}
	else if (theform.email.value==""){
		alert('Please enter your email address.  ');
		form.email.focus();
		return false;
	}
	else if (isEmail(theform.email.value)==false){
		alert('Please enter a valid email address.  ');
		form.email.select();
		return false;
	}
	else if(theform.question.value==""){
		alert('Please enter a comment or question.  ');
		form.question.focus();
		return false;
	}
	$.post("/actions/actions.cfm", { task: "ask_an_expert",data:'country:'+$('#country').val()+'|email:'+$('#email').val()+'|phone:'+$('#phone').val()+'|name:'+$('#name').val()+'|question:'+$('#question').val()+'|ask:'+$('#ask').val()+'|id:'+$('#id').val()},
	function(data){
		$('#askdiv').html('<h3>Thank You</h3><div>Your question has been sent.</div>');
	});
}

//validation for email addresses***********************************************************************************
function isEmail(str) {
  //return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}
//validation for quick quote************************************************************************************
function validate_qq(form){
	if (form.name.value == ''){
		alert('Please enter your name.  ');
		form.name.focus();
		return false;
	}
	else if(form.address.value == ''){
		alert('Please enter your street address.');
		form.address.focus();
		return false;
	}
	else if(form.city.value == ''){
		alert('Please enter your city.');
		form.city.focus();
		return false;
	}
	else if (form.email.value == ''){
		alert('Please enter your email address.  ');
		form.email.focus();
		return false;
	}
	else if (isEmail(form.email.value)==false){
		alert('Please enter a valid email address.  ');
		form.email.select();
		return false;
	}
	else if (form.org.value == ''){
		alert('Please enter your organization.  ');
		form.org.focus();
		return false;
	}
	else if (form.country.value == 0){
		alert('Please select your country.  ');
		form.country.focus();
		return false;
	}
	else if(form.zip.value == ''){
		alert('Please enter your postal code.');
		form.zip.focus();
		return false;
	}
	else if (form.phone.value == 0){
		alert('Please enter your phone number.  ');
		form.phone.focus();
		return false;
	}
	else if (form.solution.value == 0){
		alert('Please select your solution.  ');
		form.solution.focus();
		return false;
	}
	else if (form.country.value == 217 && form.state.value == 0){
		alert('Please select your state.');
		form.state.focus();
		return false;
	}
	return true;
}
//tree menu script for faqs page************************************************************************************
function tree(nam,num,cntr){
	var div = cntr.substring(1,10);
	div2 = div*1 + 1;
	new_div = 'd' + div2;
	if (document.getElementById(new_div).style.display=='none'){
		i = 1;
		j = 1;
		while (i<=num){
			if (document.images['i' + (1*div+j)].name == nam + '_' + i){
				document.getElementById('d' + (1*div+j)).style.display='block';				
				i++;
			}
			j++;
		}
		document.images[nam].src='images/minus.gif';
	}
	else {
		for (k=1;k<1000;k++){
			if (document.images['i' + (1*div+k)].name.substring(0,nam.length) == nam){
				document.getElementById('d' + (1*div+k)).style.display='none';
				if(document.images['i' + (1*div+k)].src.match("minus")=='minus'){
					document.images['i' + (1*div+k)].src='images/plus.gif';
				}
			}
			else {
				break;
			}
		}
		document.images[nam].src='images/plus.gif';
	}
}
//validation for downloads form ****************************************************************************************
function check_dform(form){
	var software = 0;
	for (x=0;x<form.elements.length;x++){
		if (form.elements[x].name == 'software' && form.elements[x].checked==true){
			software = 1;
			break;
		}
	}
	if (software==0){
		alert('Please select the software (above) that you want to download.  ');
		return false;
	}
	return validate_question(form);
	return true;
}
//validation for training registration ************************************************************************************
function check_form(form){
	if (form.name.value == ''){
		alert('Please enter your name.  ');
		form.name.focus();
		return false;
	}
	else if (form.org.value == ''){
		alert('Please enter your organization.  ');
		form.org.focus();
		return false;		
	}
	else if (form.email.value == ''){
		alert('Please enter your email address.  ');
		form.email.focus();
		return false;		
	}
	else if (isEmail(form.email.value)==false){
		alert('Please enter a valid email address.  ');
		form.email.select();
		return false;
	}
	else if (form.phone.value == ''){
		alert('Please enter your phone number.  ');
		form.phone.focus();
		return false;		
	}	
	else if (form.b_address.value == ''){
		alert('Please enter your billing Address.  ');
		form.b_address.focus();
		return false;
	}
	else if (form.b_city.value == ''){
		alert('Please enter your billing City.  ');
		form.b_city.focus();
		return false;		
	}
	else if (form.b_state.value == ''){
		alert('Please enter your billing State.  ');
		form.b_state.focus();
		return false;		
	}
	else if (form.b_zip.value == ''){
		alert('Please enter your billing Zip Code.  ');
		form.b_zip.focus();
		return false;		
	}
	else if (form.s_address.value == ''){
		alert('Please enter your shipping Address.  ');
		form.s_address.focus();
		return false;		
	}
	else if (form.s_city.value == ''){
		alert('Please enter your shipping City.  ');
		form.s_city.focus();
		return false;		
	}
	else if (form.s_state.value == ''){
		alert('Please enter your shipping State.  ');
		form.s_state.focus();
		return false;		
	}
	else if (form.s_zip.value == ''){
		alert('Please enter your shipping Zip Code.  ');
		form.s_zip.focus();
		return false;		
	}
	else if (form.payment[0].checked == true && form.po.value == ''){
			alert('Please enter a PO number.  ');
			form.po.focus();
			return false;
	}
	return true;
}
//validation for case study submission ************************************************************************************
function check_proj(form){
	if (form.contact.value == ''){
		alert('Please enter a contact name.  ');	
		form.contact.focus();
		return false;
	}
	else if (form.email.value == ''){
		alert('Please enter an email address for the contact.  ');
		form.email.focus();
		return false;		
	}
	else if (isEmail(form.email.value)==false){
		alert('Please enter a valid email address.  ');
		form.email.select();
		return false;
	}
	else if (form.desc.value == ''){
		alert('Please enter a description of the project.  ');
		form.desc.focus();
		return false;		
	}	
	return true;
}
//validation for integrator submission ************************************************************************************
function check_int(form){
	if (form.coname.value == ''){
		alert('Please enter your company name.  ');	
		form.coname.focus();
		return false;
	}
	else if (form.desc.value == ''){
		alert('Please enter a description of the services you offer.  ');
		form.desc.focus();
		return false;		
	}
	else if (form.region.value == ''){
		alert('Please enter the regions in which you work.  ');
		form.region.focus();
		return false;		
	}
	else if (form.contact.value == ''){
		alert('Please enter a contact.  ');
		form.contact.focus();
		return false;		
	}
	else if (form.email.value == ''){
		alert('Please enter an email address for the contact.  ');
		form.email.focus();
		return false;		
	}
	else if (isEmail(form.email.value)==false){
		alert('Please enter a valid email address.  ');
		form.email.select();
		return false;
	}
	else if (form.solutions.selectedIndex==-1){
		alert('Please select one or more Solutions pages in your area of expertise.  ');
		form.solutions.focus();
		return false;		
	}	
	return true;
}


function ajax_send_postconfirm(id){
	$.post("/forum/newposts.cfm", {messages:id,onlyone:1},
	function(data){
		document.body.style.cursor="default";
		$('#'+id+'_confbtn').style.display='none';
		$('#'+id+'_unreviewed').style.backgroundColor='##FFFFFF';
	});
}

function ajax_load_abusereport(threadid,messageid){
	$.post("/forum/newposts.cfm", {loadmessage:messageid,threadid:threadid},
	function(data){
		$('#reportmsg_'+messageid).html(data);
	});
	/*ajaxEngine.registerAjaxElement('reportmsg_'+messageid);
	ajaxEngine.registerRequest('load_abusereport', 'newposts.cfm');
	document.body.style.cursor="wait";
	var cfm = "loadmessage="+messageid+"&threadid="+threadid;
	var options = {onComplete:function() {
		document.body.style.cursor="default";
	},method:'post', parameters:cfm};
	ajaxEngine.sendRequest('load_abusereport',options);*/
}

function ajax_send_abusereport(messageid,threadid){
	if($('reasonid_'+messageid).value != ''){
		reason= $('reasonid_'+messageid).value;
	}else{
		reason = 'No reason given';
	}
	$.post("/forum/newposts.cfm", {message:messageid,report:1,thread:threadid,reason:reason},
	function(data){
		$('#reportmsg_'+messageid).html('Thank You!');
	});
	/*ajaxEngine.registerRequest('confirmpost', 'newposts.cfm');
	document.body.style.cursor="wait";
	var cfm = "message="+messageid+"&report=1&thread="+threadid+'&reason='+reason;
	var options = {onComplete:function() {
		document.body.style.cursor="default";
		$('reportmsg_'+messageid).innerHTML='Thank You!';
	},method:'post', parameters:cfm};
	ajaxEngine.sendRequest('confirmpost',options);*/
}


