function pageprint(){ 
var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
  disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25"; 
var content_vlue = document.getElementById("printme").innerHTML;
var docprint=window.open("","",disp_setting); 
docprint.document.open(); 
docprint.document.write('<html><head><title>Vermont Systems, Inc - Page Print</title>'); 
//docprint.document.write('</head><body onLoad="self.print()"><center>');    
docprint.document.write('</head><body>');          
docprint.document.write(content_vlue);          
docprint.document.write('</body></html>'); 
docprint.document.close(); 
docprint.focus();}

/*function mailpage(pageurl){
var content_value = document.getElementById("printme").innerHTML;
mail_str = "mailto:?subject=Check out " + document.title;
mail_str += "&body=I thought you might be interested in the " + document.title;
mail_str += ". You can view it at, " + encodeURIComponent(pageurl) + ".";
location.href = mail_str;}*/


$(document).ready(function(){
$('.num').mask("(999) 999-9999");
$('.zipcode').mask("99999");
$('#menu ul').superfish({
	delay: 900,
	autoArrows: false,
	dropShadows: false
});
$('form').not(".loginform").not(".reqform").submit($.blockUI);
$('.numlist a').click($.blockUI);
$(".loginform").validate({
	submitHandler: function(form) {
		$.blockUI();
		form.submit();
		return false;
	}
});
$(".reqform").validate({
	submitHandler: function(form) {
		$.blockUI();
		form.submit();
		return false;
	}
});
$(".close").click(function(){
	$(this).parent("div").hide();
	return false;
});
$("#error .close").click(function(){
	$("#error").hide();
	return false;
});
$("#message .close").click(function(){
	$("#message").hide();
	return false;
});
$("#message").fadeIn("slow").animate({opacity:1.0},15000).fadeOut("slow");
$("#error").fadeIn("slow").animate({opacity:1.0},15000).fadeOut("slow");
$(".advsearch").click(function(){
	if ($(this).next("form").is(":hidden")){
		$(this).next("form").removeClass("hide");
		$(this).next("form").show();
	} else {
		$(this).next("form").hide();
	}
	return false;
});
//$(".showhide").next("fieldset").hide();
$(".showhide").click(function(){
	if ($(this).next("fieldset").is(":hidden")) {
		$(this).next("fieldset").show();
	} else {
		$(this).next("fieldset").hide();
	}
	return false;
});
$(".showhideall").click(function(){
	if ($(this).nextAll("fieldset").is(":hidden")) {
		$(this).nextAll("fieldset").show();
	} else {
		$(this).nextAll("fieldset").hide();
	}
	return false;
});

$(".hidden").hide();	 
/*$("#submenu .mid ul li.heading strong").click(function() {
	if ($(this).next("ul").is(":hidden")) {
		$(this).next("ul").removeClass("hide").slideDown(500);
	} else {
		$(this).next("ul").slideUp(500);
	}
	return false;
});*/
$("#submenu .mid ul li.heading strong").click(function() {
	if ($(this).next("ul").is(":hidden")) {
		$("#submenu .mid ul li.heading ul").slideUp();
		$(this).next("ul").removeClass("hide").slideDown(500);
	} 
	return false;
});
	 
$("table tr:nth-child(even)").not("#stats tr:nth-child(even)").addClass("alt");
$("table tr").mouseover(function(){$(this).addClass("over");});
$("table tr").mouseout(function(){$(this).removeClass("over");});	

$(".overbutton").hover(function(){
	$(".overbox",this).show();
},function(){
	$(".overbox",this).hide();
});  

$("legend.button").nextAll("ol").hide();
$("legend.button").click(function(){
	if ($(this).nextAll("ol").is(":hidden")) {
		$(this).nextAll("ol").slideDown(500);
	} else {
		$(this).nextAll("ol").slideUp(500);
	}
	return false;
});

Date.firstDayOfWeek = 7;
Date.format = 'mm/dd/yyyy';
$('.datepick').mask("99/99/9999");
$('.datepick').datePicker({startDate:'01/01/1985'});

/*$('.num').numeric();*/
$('.ext').numeric();
$('.font-small').click(function() {
	$('#printme').css("font-size","0.7em");
	return false;
});
$('.font-medium').click(function() {
	$('#printme').css("font-size","0.8em");
	return false;
});
$('.font-large').click(function() {
	$('#printme').css("font-size","0.9em");
	return false;
});
$("#products").scrollable({ 
		vertical:true,  
		next: '#nextBtn' ,
		prev: '#prevBtn',
		speed: 1000,
		circular: true
	}).autoscroll({
		autoplay: true,
		interval: 5000,
		autopause: true
});
$("span.imgpopup a").click(function(ev) {
	
	ev.preventDefault();	

	$('body').append('<div id="imgBoxCover"></div><div id="imgBox"><p>Loading...</p></div>');
	
    var img = new Image;
	var imgpath = $(this).attr('href');
	var wheight = $(window).height();
	var wwidth  = $(window).width();
	var dheight = $(document).height();
	var dwidth  = $(document).width();	
	var lheight = $('#imgBox').height();
	var lwidth  = 500;
	
	$("#imgBoxCover").css({
		'height' : dheight + 'px',
		'width' : dwidth + 'px',
		'background-color' : '#ccc',
		'position' : 'fixed',
		'top' : '0',
		'left' : '0',
		'right' : '0',
		'bottom' : '0',
		'z-index' : '99999998',
		'margin' : '0',
		'padding' : '0',
		'opacity' : '0.7',
		'text-align' : 'center',
		'cursor' : 'pointer'
	});	
	
	$('#imgBox').css({
		'position' : 'absolute',	
		'top' : ((wheight - (lheight + 20)) / 2) + 'px',
		'left' : ((wwidth - (lwidth + 20)) / 2) + 'px',
		'right' : ((wwidth - (lwidth + 20)) / 2) + 'px',
		'padding' : '0',
		'margin' : '0',
		'z-index' : '99999999',
		'cursor' : 'pointer'			
	});	
	
	$(img).load(function() {
	    $(this).css('display','none');
		$('#imgBox').html(this);
		$(this).fadeIn(500);
		var iwidth  = (this.width > wwidth) ? (wwidth - 40) : (this.width - 40);
		var iheight  = (this.height - (((this.width - iwidth) / this.width) * this.height));
		img.width = iwidth;	
		img.height = iheight;	
		if (img.width > 0) {
			$("#imgBox").css({
				'top' : '0',
				'left' : ((wwidth - (iwidth + 20)) / 2) + 'px',
				'right' : ((wwidth - (iwidth + 20)) / 2) + 'px'
			});
		}
    }).error(function(){
		$('#imgBox').html('No Image Found');
	}).attr({
		src : imgpath,
		title : 'Click to close',
		alt : 'Click to close'
	});	
	
	$("#imgBox").click(function() {
		$("#imgBox").remove();
		$("#imgBoxCover").remove();
		return false;
	});	
	$("#imgBoxCover").click(function() {
		$("#imgBox").remove();
		$("#imgBoxCover").remove();
		return false;
	});		
	return false;
});

/*TINY MCE*/

	$(".mceEditor").tinymce({
		script_url : '/js/v1/editor/tiny_mce.js',
		theme : "advanced",
		plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups,autosave",
		theme_advanced_buttons1 : "pasteword,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontsizeselect,forecolor",
		theme_advanced_buttons2 : "search,replace,|,bullist,numlist,blockquote,|,undo,redo,|,link,unlink,image,|,insertdate,inserttime,cite,abbr,acronym,del,ins,|,nonbreaking,pagebreak",
		theme_advanced_buttons3 : "removeformat,|,sub,sup,|,charmap,|,fullscreen,preview,code,cleanup,|,help",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : false,
		theme_advanced_styles : "Image Popup=imgpopup",
		content_css : "/css/v1/common.css",
		external_link_list_url : "/web.wsc/linklist.htm",
		formats : {bold : {inline : 'strong'},italic  : {inline : 'em'}},
		dialog_type : "modal",
		apply_source_formatting : true,
		cleanup_on_startup : true,
		convert_fonts_to_spans : true,
		doctype : '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
		element_format : "xhtml",
		fix_list_elements : true,
		invalid_elements : "b,i,font",
		relative_urls : false,
		body_id: "editcontent"
	});
	
	$(".mceEditorspl").tinymce({
		script_url : '/js/v1/editor/tiny_mce.js',
		theme : "advanced",
		plugins : "",
		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,fontsizeselect,forecolor",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "center",
		theme_advanced_statusbar_location : "none",
		theme_advanced_resizing : false,
		formats : {bold : {inline : 'strong'},italic  : {inline : 'em'}},
		dialog_type : "modal",
		apply_source_formatting : true,
		cleanup_on_startup : true,
		convert_fonts_to_spans : true,
		doctype : '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
		element_format : "xhtml",
		fix_list_elements : true,
		invalid_elements : "b,i,font",
		convert_urls: false,
		relative_urls : false,
		remove_script_host: false
	});

	//STATISTICS JS
	
	var statholder    = new Array();
	    statholder[0] = "#stat_header";
		statholder[1] = "#stat_session";
		statholder[3] = "#stat_misc";
		statholder[4] = "#stat_pages";
	
	var loader        = $("#loader").html();

	$.each(statholder,function(i,v){
		if ($("#stat_controls").length > 0) {statData(loader,i,v,"");}
	});

	$("#stat_controls").unbind();

	$("#stat_controls").submit(function(){
		$.each(statholder,function(i,v){
			statData(loader,i,v,"");
		});
		return false;
	});
	
	$(".strefresh").click(function() {
		var data = $(this).attr('rel');
		var stid = data.split('-');
		var view = stid[0];
		var cont = "#" + stid[1];
		if ($(cont).is(":hidden")) {
			$(cont).slideDown(700);
		}
		statData(loader,view,cont,"");
	});
	
	$(".stminimize").click(function() {
		var data = $(this).attr('rel');
		var stid = data.split('-');
		var view = stid[0];
		var cont = "#" + stid[1];
		if ($(this).is(".stmaximize")) {
			$(this).removeClass("stmaximize");
		} else {
			$(this).addClass("stmaximize");
		}
		if ($(cont).is(":hidden")) {
			$(cont).slideDown(700);
		} else {
			$(cont).slideUp(700);
		}
	});
	
});

function statData(loader,view,connect,addURL) {
	var begdate   = $("#stat_controls input[name=begdate]").val();
	var enddate   = $("#stat_controls input[name=enddate]").val();
	var incseo    = $("#stat_controls select[name=incseo]").val();
	var statdata  = window.location.search.substring(1);
	var qstring   = statdata + "&begdate=" + begdate + "&enddate=" + enddate + "&incseo=" + incseo + "&view=" + view + addURL;
	$(connect).html(loader);
	$.ajax({
		timeout: 600000,
		url: "statsdata.htm",
		cache: false,
		data: qstring,
		error: function(httpreq,status,error) {
			$(connect).html(status + '<br />' + error);
		},
		success: function(data){
			$(connect).html(data);
			$("#stat_header a[title]").tooltip({offset:[-10,0],effect:"fade",opacity: 0.8});
			$("#sessions tbody tr td").click(function(){
				var sessid = $(this).parent().attr("id");
				statData(loader,"2","#stat_session",("&sessid=" + sessid));
			});
			$("#session tbody tr td").click(function(){
				var sessid = $(this).parent().attr("id");
				statData(loader,"1","#stat_session","");
			});
			$("#session tbody tr td").hover(function(){	
				var parid = $(this).parent("tr");
				$(parid).children("td").addClass('over');
			},function() {
				var parid = $(this).parent("tr");
				$(parid).children("td").removeClass('over')
			});
			$("#sessions tbody tr td").hover(function(){	
				var parid = $(this).parent("tr");
				$(parid).children("td").addClass('over');
			},function() {
				var parid = $(this).parent("tr");
				$(parid).children("td").removeClass('over')
			});			
			if (view == "1") {$("#sessions").dataTable({"aaSorting": [[ 0, "desc" ],[ 1, "desc" ]],"sPaginationType": "full_numbers"});}
			if (view == "4") {$("#pages").dataTable({"aaSorting": [[ 0, "desc" ],[ 1, "desc" ]],"sPaginationType": "full_numbers"});}		
		}
	});
	
}

function showProcessing() {

	var vheight = $(document).height();
	var vwidth = $(document).width();
	var vpos = ($.browser.msie && parseInt($.browser.version) <= 6 ) ? 'absolute' : 'fixed';
	
	$("#overlay div").html('<img src="/website/images/loader.gif">');
	$('#overlay').css({
		'height' : vheight + 'px',
		'width' : vwidth + 'px',
		'background-color' : '#ccc',
		'position' : vpos,
		'top' : '0',
		'left' : '0',
		'right' : '0',
		'bottom' : '0',
		'z-index' : '99999999',
		'margin' : '0',
		'padding' : '0',
		'display' : 'none',
		'opacity' : '0.7',
		'text-align' : 'center'
	}).fadeIn(500);
	$('#overlay div').css({
		'margin' : '20% auto'
	});
	
}

function loadAjax(ajaxType,ajaxURL,ajaxString,ajaxCache,ajaxAttach) {
	$.blockUI();
	$.ajax({
		type: ajaxType,
		url: ajaxURL,
		data: ajaxString,
		success: function(html) {
			$.unblockUI();
			$(ajaxAttach).html(html);
			CommonCalls();
		},
		error: function(errObj,errStatus,errThrown) {
			$.unblockUI();
			$(ajaxAttach).html("Error Object: " + errObj + "<br />Error Status: " + errStatus + "<br />Error Thrown: " + errThrown);
			CommonCalls();
		}
	});
	
}

