function search(keywords) {
	if(keywords.length < 3)
		alert("Search text should be at least 3 characters.");
	else
		window.location.href = webRoot + "/search?txtSearch=" + keywords;
}

function goToQuoteList()
{
	location.href= webRoot + "/testimonial";
}


/*----- key press event handler, which handle enter event to perform action script ----- */
function keyPressHandler(e, elemID, action) {
    var keynum; //key ASCII value
    if (window.event) // IE
    {
        keynum = e.keyCode;
    }
    else if (e.which) // Netscape//Firefox/Opera
    {
        keynum = e.which;
    }
    if (keynum == 13) {
        //----- perform action script -----
        if (action == "click") {
            document.getElementById(elemID).click();
        }
        else {
            eval(action);
        }
        return false; //----- return false (to mark event as handled) -----
    }
    //----- pass on the event if not enter key -----
    return true;
}

var min=8;
var max=18;

//Define our Dom Elements in an array that we want to be utilized by the Increase/Decrease Font Size function
var arDomElements = new Array("h1","h2","h3","p","li","blockquote", "td");
	
function IncreaseFontSize()
{
	var fontSize = $("body").css("font-size");
	var fontSizeVal = parseInt(fontSize.replace("px",""));
	
	var newSize = fontSizeVal + 2;
	$("body").css("font-size", "" + newSize + "px");
	
	//$.cookie("sFontSize", newSize, { expires : 30, path : '/' });	//somehow the jquery.cookie doesn't work across pages
	
	SetCookie("sFontSize", newSize,'','/','','');
	
	
/*	var x;
	
	for(x in arDomElements)
	{
		size = IncreaseFontSizeItem(arDomElements[x]);
		SetCookie( 'sfontsize'+arDomElements[x], size, '', '/', '', '' );
	}
*/
}

function DecreaseFontSize()
{
	var fontSize = $("body").css("font-size");
	var fontSizeVal = parseInt(fontSize.replace("px",""));

	var newSize = fontSizeVal - 2;
	$("body").css("font-size", "" + newSize + "px");

	//$.cookie("sFontSize", newSize, { expires : 30, path : '/' });	//somehow the jquery.cookie doesn't work across pages
	SetCookie("sFontSize", newSize,'','/','','');

/*	var x;
	
	for(x in arDomElements)
	{
		size = DecreaseFontSizeItem(arDomElements[x]);
		SetCookie( 'sfontsize'+arDomElements[x], size, '', '/', '', '' );
	}
*/
}

function IncreaseFontSizeItem(domElement) 
{
	//Get the dom elements to modify. Filter out Top nav and left nav
	var domToMod = $('td.mainContent').find(domElement);
	
	var domToModSize = parseFloat( domToMod.css('font-size') );
	
	if(domToModSize!=max) 
	{
		domToModSize += 1;
	}
	
	domToMod.css('font-size',domToModSize);
	
	

 //  	for(i=0;i<p.length;i++) 
 //  	{
   //  	if(p[i].style.fontSize) 
	//  	{
//var s = parseFloat(p[i].style.fontSize.replace("px",""));
   //   	} 
	//  	else 
	//  	{	
	//		alert('font size ' + p[i].style.fontSize );
//        	var s = parseFloat(p[i].style.fontSize); //12;
    //  	}
      	
		
		
      	//p[i].style.fontSize = s+"px"
 //  }
   return domToModSize;
}

function DecreaseFontSizeItem(domElement) 
{
//Get the dom elements to modify. Filter out Top nav and left nav
	var domToMod = $('td.mainContent').find(domElement);
	
	var domToModSize = parseFloat( domToMod.css('font-size') );
	
	if(domToModSize!=min) 
	{
		domToModSize -= 1;
	}
	
	domToMod.css('font-size',domToModSize);    
}

function SetFontSizeItem(size,domElement)
{	

/**	var domToMod = $('td.mainContent').find(domElement);
	
//	var domToModSize = parseFloat( domToMod.css('font-size') );
	
	var sizeToModTo = parseInt(size);
//	alert('in' + sizeToModTo );
	
	if( !isNaN(sizeToModTo) )
	{
		domToMod.css('font-size',sizeToModTo);  				
	}**/	
	
	var p = $('td.mainContent').find(domElement);
	
	for(i=0;i<p.length;i++) 
   	{
    	if(p[i].style.fontSize) 
	  	{
        	var s = parseFloat(p[i].style.fontSize.replace("px",""));
      	} 
	  	else 
	  	{	
        	var s = size;
      	}
      	
      	p[i].style.fontSize = s+"px"
   	}

}

function SetFontSize(size)
{
	var x;
	
	for(x in arDomElements)
	{
		SetFontSizeItem(size,arDomElements[x]);
	}
}

function SetCookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

function GetCookie( check_name ) 
{
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function InitializeFontSize()
{
/*	var x;
	
	for(x in arDomElements)
	{
		var fsize = GetCookie('sfontsize'+arDomElements[x]);
		SetFontSize(fsize);
	}
*/
	//var savedFontSize = $.cookie("sFontSize");	//somehow the jquery.cookie doesn't work across pages
	var savedFontSize = GetCookie("sFontSize");
	
	if(savedFontSize == null || savedFontSize == ""){
		/* no default cookie size, do nothing */
	}
	else {
		$("body").css("font-size", "" + savedFontSize + "px");
	}
}

var msg = "Sorry, you don't have permission to right-click and save images.";

function right(e) 
{	
	if (navigator.appName == 'Netscape' && e.which == 3) 
	{
		alert(msg);
		return false;
	}
	
	if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2) 
	{
		alert(msg);
		return false;
	}
	else return true;
}

function PreventImageSave() 
{
	if(document.images)
	{
		for(i=0;i<document.images.length;i++)
	  	{
	  		document.images[i].onmousedown = right;
	  		document.images[i].onmouseup = right;
	  	}
	}
}

function PreventPrintScreen()
{
	$(document).keyup(function(e) 
	{
		if(e.keyCode == 44)
		{	
			alert("Sorry, you don't have permission to save images.");	
			if( window.clipboardData && clipboardData.setData )
			{				
				window.clipboardData.setData("Text","Sorry, you don't have permission to save images."); 	
			}					
		}	
	});	
}

/**
function GoogleAnalytics()
{
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-3658456-2']);
  _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);
  })();	
}**/



$(document).ready(function()
{
	var name = GetCookie("fullname");
	if( name != "" && name != null)
	{
		$("#membername").text("Welcome " + name);		
	}	

	$(".incdecFontSize img").hover(function(){
		$(this).attr("title",$(this).attr("alt"));
	});
		
	PreventPrintScreen();
	PreventImageSave();	
});



