function formEvents(){
	//get all forms on page
	var allforms = document.getElementsByTagName('form');
	
	//loop through forms
	for(i=0;i<allforms.length;i++){
		
		//get all input tags in current form
		var thisform = allforms[i].getElementsByTagName('input');
		
		//loop through those inputs
		for(j=0;j<thisform.length;j++){
			//qualify that the input is a text input, and has a title, and isn't being excluded by using the 'noevents' class
			if(thisform[j].title && thisform[j].title != '' && thisform[j].type != 'image' && thisform[j].type != 'button' && thisform[j].type != 'submit' && thisform[i].className != 'noevents'){
				//assign the title to the value
				thisform[j].value = thisform[j].title;
				//events that will remove/replace default values into fields
				thisform[j].onfocus = function(){if(this.title == this.value){this.value = '';}}
				thisform[j].onblur = function(){if(this.value == ''){this.value = this.title;}}
			}
		}
	}
}

	//age check
	function twoDigits(dig){
		var str = dig.toString();
		var digit = (str.length == 2) ? str : '0'+str;
		return digit;
	}
	
	
	function realMonth(mm){
		var realmonth = (mm < 12) ? mm + 1 : mm = 1;
		return realmonth;
	}
			
	// returns true if the string is a US phone number formatted as...
	// (000)000-0000, (000) 000-0000, 000-000-0000, 000.000.0000, 000 000 0000, 0000000000
	function isPhoneNumber(str){
		var re = /^\(?[2-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/
		return re.test(str);
	}
	
	// returns true if the string only contains characters A-Z, a-z or 0-9 or . or #
	function isAddress(str){
		var re = /[^a-zA-Z0-9\#\.]/g
		if (re.test(str)) return true;
		return false;
	}
	
	// returns true if the string is 5 digits
	function isZip(str){
		var re = /\d{5,}/;
		if(re.test(str)) return true;
		return false;
	}
	
	// returns true if the string only contains characters A-Z or a-z
	function isAlpha(str){
		var re = /[^a-zA-Z]/g
		if (re.test(str)) return true;
		return false;
	}
	
	// returns true if the string only contains characters A-Z or a-z or 0-9
	function isAlphaNumeric(str){
		var re = /[^a-zA-Z0-9]/g
		if (re.test(str)) return false;
		return true;
	}

	function isEmpty(str){
		if(str.length == 0 || str == null){
			return true;
		}else{
			return false;
		}
	}
	
	function isEmail(str){
	if(str == '') return false;
	var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
	return re.test(str);
	}
	
function stripWhitespace(str, replacement){
	if (replacement == null) replacement = '';
	var result = str;
	var re = /\s/g
	if(str.search(re) != -1){
		result = str.replace(re, replacement);
	}
	return result;
}

/*******************************************************************************/
//functions for making rollovers in mainnav

		function nav_overs(elem)
		{
			var pnav = document.getElementById(elem);
			var nav_ims = pnav.getElementsByTagName('img');
			for(i=0;i<nav_ims.length;i++){
				//dont try to make rollovers for images with no_rollover class
				if(nav_ims[i].className != 'no_ro'){
					nav_ims[i].onmouseover=function(){this.src = splitSrc(this.src); }
					nav_ims[i].onmouseout=function(){this.src = splitSrc(this.src); }
				}
			}
			
		}
		
		//helper function for rollovers
		function splitSrc(imgsrc){			
			//now break it into parts so that we can change it to the over state
			var this_ext = imgsrc.substring(imgsrc.length-4,imgsrc.length);
			//flag the current state (on/off)
			var state = imgsrc.substring(imgsrc.length-7,imgsrc.length-4) == '_on' ? true : false;
				
				if(state){
					var this_src_split = imgsrc.split('_on');
					var newsrc = this_src_split[0]+''+this_ext;
				}else{
					var this_src_split = imgsrc.split(this_ext);
					var newsrc = this_src_split[0]+'_on'+this_ext;
				} 
			return newsrc;
		}
		
/*******************************************************************************/

//function to validate contact form
function validateContactForm(formname){
	
	var err_count = 0;
	var err_message = "The following errors occurred:<br />";
	
	var contact = eval('document.contact');
	
	if(isEmpty(contact.fullname.value)){
		err_count++;
		err_message += "Please include your name.<br />";
	}else{

	}
	
	if(isEmpty(contact.email.value) || !isEmail(contact.email.value)){
		err_count++;
		err_message += "Please include a valid email address.<br />";
		
	}else{
	}
	
	if(isEmpty(contact.message.value)){
		err_count++;
		err_message += "Please include your note.";
	}else{
	}
	
	if(err_count == 0){
		return true;
		//sendContactForm();
	}else{
		//alert(err_message);
		$("#cf_feedback").html(err_message);
		$("#cf_feedback").show();
	}
	
	return false;
}

//function to send mail from contact form
function sendContactForm(){
		
		var fullname = document.contact.fullname.value;
		var email = document.contact.email.value;
		var note = document.contact.message.value;
		var services
		
		var pars = 'fullname='+fullname+'&email='+email+'&message='+note;
		
		document.contact.reset();
		
		$.ajax({
		   type: "POST",
		   url: "ajax.contact.php",
		   data: pars,
			success: function(msg){
				$("#cf_feedback").html('Thank you. Your message has been sent.');
				$("#cf_feedback").show();
			}
		 });
		
}


//functions for the about us navigation menus
function getAboutUsInfo(aid,bid){
	//if we want to load in the first item in the list, 
	//we will pass in a 0 for the second ID
	var pars = 'aid='+aid+'&bid='+bid;
	
	$.ajax({
		   type: "POST",
		   url: "ajax.aboutus.php",
		   data: pars,
			success: function(msg){
				//alert(msg);
				//parse json response
				var myJson = eval('(' + msg + ')');
				
				var levela = '';
				var levelb = '';
				var levelc = '';
				var gallery ='';
				
				
				var aid = myJson.req[0].aid;
				var bid = myJson.req[0].bid;
				
				for(i=0;i<myJson.levela.length;i++){
					if(myJson.levela[i].id == aid){
						levela += '<li class="act"><a href="javascript:getAboutUsInfo('+myJson.levela[i].id+',0);">'+myJson.levela[i].category_name+'</a></li>';
					}else{
						levela += '<li><a href="javascript:getAboutUsInfo('+myJson.levela[i].id+',0);">'+myJson.levela[i].category_name+'</a></li>';
					}
				}
				
				for(i=0;i<myJson.info.length;i++){
					//grab the second column choice and display it in full
					if(i==0){
						if(bid == 0){
							bid = myJson.info[i].id;
						}
					}
					
					//build second column
					if(myJson.info[i].id == bid){
					
						//some categories dont have subcategories, so we need to extend the c column to fill the screen.
						if(myJson.info[i].title == ''){
							$("#levelc").addClass('widecol');
							$("#levelb").hide();
						}else{
							$("#levelb").show();
							$("#levelc").removeClass('widecol');
							levelb += '<li class="act"><a href="javascript:getAboutUsInfo('+aid+','+myJson.info[i].id+');">'+myJson.info[i].title+'</a></li>';
						}
						
						$("#levelcContent").html('<p>'+myJson.info[i].body_with_html+'</p>');
						//$("#ftimg1").html('<img src="admin/'+myJson.info[i].image_file_1+'" alt="" /><p>'+myJson.info[i].image_caption_1+'</p>');
						//$("#ftimg2").html('<img src="admin/'+myJson.info[i].image_file_2+'" alt="" /><p>'+myJson.info[i].image_caption_2+'</p>');
						//$("#ftimg3").html('<img src="admin/'+myJson.info[i].image_file_3+'" alt="" /><p>'+myJson.info[i].image_caption_3+'</p>');

					}else{
						levelb += '<li><a href="javascript:getAboutUsInfo('+aid+','+myJson.info[i].id+');">'+myJson.info[i].title+'</a></li>';
					}
					
				}
				
				
				var isclosed = true;
				
				for(i=0;i<myJson.gallery.length;i++){
				
					//now we need to traverse the gallery row looking for each image
					for(j=1;j<=10;j++){
					
					//make sure this isnt an empty row
					var testrow = 'myJson.gallery['+i+'].image_file_'+j;
					if(eval(testrow) != ''){
					
						//var that will keep track of whether the last set of images is closed or not
						isclosed = false;
						
						if ((j+2) % 3 == 0){
						gallery += '<div class="gallery">';
						}
						gallery += '<div class="item">';
						
						var thfile = 'myJson.gallery['+i+'].image_file_'+j;
						var th1file = eval(thfile);
						var th2file = th1file.replace(/images\//,'images/thumb154_');
						
						var imfile = 'myJson.gallery['+i+'].image_file_'+j;
						var imtitle = 'myJson.gallery['+i+'].title_'+j;
						var imdesc = 'myJson.gallery['+i+'].description_'+j;
						
						gallery += '<a href="admin/'+eval(imfile)+'"><img src="admin/'+th2file+'" alt="" /></a>';
						gallery += '<h3>'+eval(imtitle)+'</h3>';
						gallery += '<h4>'+eval(imdesc)+'</h4>';
						gallery += '</div>';
						
						if (j % 3 == 0){
						gallery += '</div>';
						isclosed = true;
						}					
					
					//end of if condition
					}
					
					}
				}
				
				if(!isclosed){ gallery += '</div>'; }
				
				//alert(gallery);
				
				$("#levela").html(levela);
				$("#levelb").html(levelb);
				$("#ftrgallery").html(gallery);
				
				//init the div scroller, since it must determine its height when the content changes
				myScroll = new ScrollObj(6,30,235,"track","up","down","drag","levelcContentMask","levelcContent");
				setupZoom();
				
				$('#ftrgallery').cycle({ 
				fx:     'scrollHorz',
				prev: '#prev',
				next: '#next',
				timeout: 0
				});
		
		
			}
		 });
	
}


//functions for the services navigation menus
function getServicesInfo(aid,bid){
	//if we want to load in the first item in the list, 
	//we will pass in a 0 for the second ID
	var pars = 'aid='+aid+'&bid='+bid;
	
	$.ajax({
		   type: "POST",
		   url: "ajax.services.php",
		   data: pars,
			success: function(msg){
				//alert(msg);
				//parse json response
				var myJson = eval('(' + msg + ')');
				
				var levela = '';
				var levelb = '';
				var levelc = '';
				var gallery ='';
				
				var aid = myJson.req[0].aid;
				var bid = myJson.req[0].bid;
				
				var cur_par = 0;
				
				for(i=0;i<myJson.levela.length;i++){
					//we want to print out the parents too
					if(myJson.levela[i].parent_category != cur_par){
						cur_par = myJson.levela[i].parent_category;
						if(cur_par != 0){levela += '</div>';}
						levela += '<li onmouseover="showChildren(\''+cur_par+'\')" style="display:block;cursor:pointer;">'+myJson.levela[i].category_name+'</li>';
						levela += '<div style="display:none;" id="'+cur_par+'" class="childmenu">';
					}
					
					if(myJson.levela[i].id == aid){
						levela += '<li class="act"><a href="javascript:getServicesInfo('+myJson.levela[i].id+',0);">'+myJson.levela[i].subcategory_name+'</a></li>';
					}else{
						levela += '<li><a href="javascript:getServicesInfo('+myJson.levela[i].id+',0);">'+myJson.levela[i].subcategory_name+'</a></li>';
					}
					
				}
					//close the last group
					levela += '</div>';
				
				for(i=0;i<myJson.info.length;i++){
					//grab the second column choice and display it in full
					if(i==0){
						if(bid == 0){
							bid = myJson.info[i].id;
						}
					}
					
					//build second column
					if(myJson.info[i].id == bid){
					
						//some categories dont have subcategories, so we need to extend the c column to fill the screen.
						if(myJson.info[i].title == ''){
							$("#levelc").addClass('widecol');
							$("#levelb").hide();
						}else{
							$("#levelb").show();
							$("#levelc").removeClass('widecol');
							levelb += '<li class="act"><a href="javascript:getServicesInfo('+aid+','+myJson.info[i].id+');">'+myJson.info[i].title+'</a></li>';
						}
						
						$("#levelcContent").html('<p>'+myJson.info[i].body_with_html+'</p>');
						//$("#ftimg1").html('<img src="admin/'+myJson.info[i].image_file_1+'" alt="" /><p>'+myJson.info[i].image_caption_1+'</p>');
						//$("#ftimg2").html('<img src="admin/'+myJson.info[i].image_file_2+'" alt="" /><p>'+myJson.info[i].image_caption_2+'</p>');
						//$("#ftimg3").html('<img src="admin/'+myJson.info[i].image_file_3+'" alt="" /><p>'+myJson.info[i].image_caption_3+'</p>');

					}else{
						levelb += '<li><a href="javascript:getServicesInfo('+aid+','+myJson.info[i].id+');">'+myJson.info[i].title+'</a></li>';
					}
					
				}
				
				//init
				isclosed = true;
				
				for(i=0;i<myJson.gallery.length;i++){
				
				
				
					//now we need to traverse the gallery row looking for each image
					for(j=1;j<=10;j++){
					
					//make sure this isnt an empty row
					var testrow = 'myJson.gallery['+i+'].image_file_'+j;
					if(eval(testrow) != ''){
					
						//var that will keep track of whether the last set of images is closed or not
						isclosed = false;
						
						if ((j+2) % 3 == 0){
						gallery += '<div class="gallery">';
						}
						gallery += '<div class="item">';
						
						var thfile = 'myJson.gallery['+i+'].image_file_'+j;
						var th1file = eval(thfile);
						var th2file = th1file.replace(/images\//,'images/thumb154_');
						
						var imfile = 'myJson.gallery['+i+'].image_file_'+j;
						var imtitle = 'myJson.gallery['+i+'].title_'+j;
						var imdesc = 'myJson.gallery['+i+'].description_'+j;
						
						gallery += '<a href="admin/'+eval(imfile)+'"><img src="admin/'+th2file+'" alt="" /></a>';
						gallery += '<h3>'+eval(imtitle)+'</h3>';
						gallery += '<h4>'+eval(imdesc)+'</h4>';
						gallery += '</div>';
						
						if (j % 3 == 0){
						gallery += '</div>';
						isclosed = true;
						}					
					
					//end of if condition
					}
					
					}
				}
				
				if(!isclosed){ gallery += '</div>'; }
				
				
				
				$("#levela").html(levela);
				$("#levelb").html(levelb);
				$("#ftrgallery").html(gallery);
				
				//init the div scroller, since it must determine its height when the content changes
				myScroll = new ScrollObj(6,30,235,"track","up","down","drag","levelcContentMask","levelcContent");
				setupZoom();
				
				$('#ftrgallery').cycle({ 
				fx:     'scrollHorz',
				prev: '#prev',
				next: '#next',
				timeout: 0
				});
				
			}
		 });
	
}

//function to hide scrolling arrows in galleries if they are not needed
function hideArrows(cnt){
	if(cnt <= 3){ 
		$('#prev').hide();
		$('#next').hide();
		//keep proper alignment
		$("#ftrgallery").addClass('na');
	}else{
		//keep proper alignment
		$("#ftrgallery").removeClass('na');
	}
}

//function for hiding/showing child menus in services
function showChildren(divid){
	//hide all the submenus first, then show the requested one
	$(".childmenu").hide();
	$("#"+divid).show();
}

//function for showing contact page sections
function showContact(section,anc){

	var ancs= new Array('contact_form','contact_directions','contact_jobs','contact_internship','contact_tech');

	for(i=0;i<ancs.length;i++){
		var curanc = ancs[i];
		$("#"+curanc).removeClass('act');
	}
	
	$("#"+anc).addClass('act');
	
	var all = new Array('contact_default_content','contact_form_content','contact_tech_content','contact_jobs_content','contact_internship_content','contact_formsent_content','contact_directions_content');
	for(i=0;i<all.length;i++){
		var cursec = all[i];
		$("#"+cursec).hide();
	}
	
	//set the page header
	switch (section){
		case 'form':
		var hdrtxt = 'Contact Us';
		break;
		case 'directions':
		var hdrtxt = 'Directions';
		break;
		case 'jobs':
		var hdrtxt = 'Employment';
		break;
		case 'internship':
		var hdrtxt = 'Internships';
		break;
		case 'tech':
		var hdrtxt = 'Technical Specifications';
		break;
		default:
		var hdrtxt = 'Contact Us';
		
	}
	var headers = new Array('Contact Us','Directions','Employment','Internships','Technical Specifications','Credit Applications');
	$("#contactpageheader").text(hdrtxt);
	
	var sec = 'contact_'+section+'_content';
	$("#"+sec).show();
}


// functions for performing search
function doSearch(str){
	var search = $("#search_widget_field").val();
	
	if(str == 'tt'){
		search = search.replace(/\//g, "[slash]");
		search = search.replace(/\+/g, "[plus]");
		search = search.replace(/\"/g, "&quot;");
		search = search.replace(/\&/g, "[and]");
		search = search.replace(/\%/g, "[perc]");
		search = search.replace(/ /g, "_");
		//window.location = 'http://www.triggertone.com/search/'+search;
		window.open('http://www.triggertone.com/search/'+search,'TT','');
	}else{
		window.location = 'search.php?q='+search;
	}

return false;
}

function toggleTabs(tabid){
	if(tabid == 'loc_content_a'){
		$("#loc_content_b").hide();
		$("#loc_content_a").show();
		$("#loc_tabs").css('background-image','url(im/cf_locations_top_left.jpg)');
		$("#getDir").attr('href','http://maps.google.com/maps?ie=UTF8&oe=utf-8&client=firefox-a&q=201+s.+victory+91502&fb=1&ll=34.172382,-118.316123&spn=0.009604,0.016158&z=16&g=201+s.+victory+91502&iwloc=addr');
	}else{
		$("#loc_content_a").hide();
		$("#loc_content_b").show();
		$("#loc_tabs").css('background-image','url(im/cf_locations_top_right.jpg)');
		$("#getDir").attr('href','http://maps.google.com/maps?q=1150+w.+olive+91506&ie=UTF8&oe=utf-8&client=firefox-a&ll=34.171263,-118.318956&spn=0.009605,0.016158&z=16&g=1150+w.+olive+91506&iwloc=addr');
	}
}


//functions for showing/hiding submenus
timer = null;

function showMenu(id){
if(timer) clearTimeout(timer);
	hideMenus();
	$('#'+id).show();
	//get the int
	var num = id.substr(-1);
	$('#services_cat'+num).addClass('act');
}

function hideMenu(id){
timer = setTimeout("doHide('"+id+"')",100);
}

function doHide(id){
$('#'+id).hide();
//get the int
var num = id.substr(-1);
$('#services_cat'+num).removeClass('act');
}

function hideMenus(){
	var mainIds = new Array('services_cat1','services_cat2','services_cat3','services_cat4','services_cat5','services_cat7')
	var menuIds = new Array('services_sub_cat1','services_sub_cat2','services_sub_cat3','services_sub_cat4','services_sub_cat5','services_sub_cat7');
	for(i=0;i<menuIds.length;i++)
	{
		thisID = menuIds[i];
		thisMain = mainIds[i];
		$('#'+thisID).hide();
		$('#'+thisMain).removeClass('act');
	}
}


function showAboutMenu(id){
if(timer) clearTimeout(timer);
	hideAboutMenus();
	$('#'+id).show();
	//get the int
	var num = id.substr(-1);
	$('#about_cat'+num).addClass('act');
}

function hideAboutMenu(id){
timer = setTimeout("doAboutHide('"+id+"')",100);
}

function doAboutHide(id){
$('#'+id).hide();
//get the int
var num = id.substr(-1);
$('#about_cat'+num).removeClass('act');
}

function hideAboutMenus(){
	var mainIds = new Array('about_cat1','about_cat2','about_cat3','about_cat4','about_cat5','about_cat6','about_cat7')
	var menuIds = new Array('about_sub_cat1','about_sub_cat3','about_sub_cat7');
	for(i=0;i<mainIds.length;i++)
	{
		thisMain = mainIds[i];
		$('#'+thisMain).removeClass('act');
	}
	for(i=0;i<menuIds.length;i++)
	{
		thisID = menuIds[i];
		$('#'+thisID).hide();
	}
}

//inits -------------------------------
window.onload = function(){
	
	formEvents();
	nav_overs('mainnav');
	setupZoom();
	
	correctPNG();
}