//***************************************************************************************
function createCookie(name,value,days) 
{
	if (days) 
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else
	{
		 var expires = "";
	}
	document.cookie = name+"="+value+expires+"; path=/";
}
//***************************************************************************************
function readCookie(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) 
	{
		
		var c = ca[i];
		while (c.charAt(0)==' ') 
		{
			c = c.substring(1,c.length);
		}

		if (c.indexOf(nameEQ) == 0) 
		{
			return c.substring(nameEQ.length,c.length);
		}
	}
	return null;
}
//***************************************************************************************

function eraseCookie(name) 
{
	createCookie(name,"",-1);
}

//***************************************************************************************
	function ShowCoverDivScreen(Main_Div_id, Content_Div_id, ScreenWidth, ScreenHeight, Content_Div_HTML)
	{
	    $('#'+Main_Div_id).width($(document).width());
	    $('#'+Main_Div_id).height($(document).height());
	
	    $('#'+Content_Div_id).width(ScreenWidth);
	    $('#'+Content_Div_id).height(ScreenHeight);
	
	    $('#'+Content_Div_id).css('top', $(window).scrollTop()+($(window).height()/2-$('#'+Content_Div_id).height()/2));
	    $('#'+Content_Div_id).css('left', $(window).width()/2-$('#'+Content_Div_id).width()/2);
	
	    $('#'+Content_Div_id).html('');
	    $('#'+Content_Div_id).html(Content_Div_HTML);
	
	    $('#'+Main_Div_id).show();
	    $('#'+Content_Div_id).show();
	
	}
//***************************************************************************************
	function HideCoverDivScreen(Main_Div_id, Content_Div_id) 
	{
	    $('#'+Content_Div_id).html('');
	    $('#'+Main_Div_id).hide();
	    $('#'+Content_Div_id).hide();
	    
	    if($(".generaltablestyle tr")!=null)
		{
			var sfEls = $(".generaltablestyle tr");
			for (var i=0; i<sfEls.length; i++) 
			{
				sfEls[i].onmouseover=function() 
				{
					this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
					this.className+=" sfhover";
				}
				sfEls[i].onmouseout=function() 
				{
					this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
				}
			}
		}
	}
//***************************************************************************************
	function ShowLoadingDataDiv()
	{
	    var DivHtml=''+
	    '<table border="0" bgcolor="#F1EDE2" width="100%" height="100%">'+
	        '<tr>'+
	            '<td width="100%" align="center" style="text-align:center">'+
	                '<div id="loading_image_area" align="center" valign="middle">'+
						'<img src="'+BASE_URL+'images/loading2.gif" border="0">'+
					'</div>'+
	            '</td>'+
	        '</tr>'+
	    '</table>';
	
	    ShowCoverDivScreen('coverDiv', 'contentDiv', '300', '300', DivHtml); 
	}
//***************************************************************************************
	function limitText(limitField, limitCount, limitNum)
	{
	    if (limitField.value.length > limitNum)
	    {
	        limitField.value = limitField.value.substring(0, limitNum);
	    }
	    else
	    {
	        limitCount.value = limitNum - limitField.value.length;
	    }
	}
//***************************************************************************************
	function limitText_jq(limitField, limitCount, limitNum)
	{
		try
		{
			if ($('#'+limitField).val().length > limitNum)
			{
				$('#'+limitField).val($('#'+limitField).val().substring(0, limitNum));
				$('#'+limitCount).val(limitNum - $('#'+limitField).val().length);
			}
			else
			{
				$('#'+limitCount).val(limitNum - $('#'+limitField).val().length);
			}
		}
		catch(e)
		{
			//do nothing
		}
	}
//***************************************************************************************
function setSfhover()
{
	sfHover = function() 
	{
		if(document.getElementById("nav")!=null)
		{
			var sfEls = document.getElementById("nav").getElementsByTagName("LI");
			for (var i=0; i<sfEls.length; i++) 
			{
				sfEls[i].onmouseover=function() 
				{
					this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
					this.className+=" sfhover";
				}
				sfEls[i].onmouseout=function() 
				{
					this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
				}
			}
		}
	}
	if (window.attachEvent) window.attachEvent("onload", sfHover);
}
//***************************************************************************************
	function phoneonly(myfield, e, dec)
	{
		if(myfield.value.substring(0)==1)
		{
			myfield.value=myfield.value.substring(1,myfield.value.length)
		}
		
		if(myfield.value.length>=10)
		{
			return false;
		}
		
		var key;
		var keychar;
		
		if (window.event)
		   key = window.event.keyCode;
		else if (e)
		   key = e.which;
		else
		   return true;
		keychar = String.fromCharCode(key);
		
		
		if ((key==null) || (key==0) || (key==8) ||
		    (key==9) || (key==13) || (key==27) )
		   return true;
		else if ((("0123456789").indexOf(keychar) > -1))
		   return true;
		else if (dec && (keychar == "."))
		   {
		   myfield.form.elements[dec].focus();
		   return false;
		   }
		else
		   return false;
	}
//***************************************************************************************
	function numberonly(myfield, e, dec)
	{
		var key;
		var keychar;
		
		if (window.event)
		   key = window.event.keyCode;
		else if (e)
		   key = e.which;
		else
		   return true;
		keychar = String.fromCharCode(key);
		
		
		if ((key==null) || (key==0) || (key==8) ||
		    (key==9) || (key==13) || (key==27) )
		   return true;
		else if ((("0123456789").indexOf(keychar) > -1))
		   return true;
		else if (dec && (keychar == "."))
		   {
		   myfield.form.elements[dec].focus();
		   return false;
		   }
		else
		   return false;
	}
//***************************************************************************************
	function showHideArea(area_id,image_id)
	{
		
		if($('#'+image_id).attr('class')=='showit')
		{
			$('#'+image_id).attr('src',BASE_URL+'/images/control_down_blue.png');
			$('#'+image_id).attr('class','hideit');
			$('#'+area_id).slideDown('slow');
		}
		else
		{
			$('#'+image_id).attr('src',BASE_URL+'/images/control_right_blue.png');
			$('#'+image_id).attr('class','showit');
			$('#'+area_id).slideUp('slow');
		}
	}
//***************************************************************************************
	$.fn.selectRange = function(start, end) 
	{        
		return this.each(
			function() 
			{                
				if(this.setSelectionRange) 
				{                        
					this.focus();                        
					this.setSelectionRange(start, end);                
				} 
				else 
				if(this.createTextRange) 
				{                        
					var range = this.createTextRange();                        
					range.collapse(true);                        
					range.moveEnd('character', end);                        
					range.moveStart('character', start);                        
					range.select();                
				}        
			}
		);
	};
//***************************************************************************************
	/*
	 * jQuery plugin: fieldSelection - v0.1.0 - last change: 2006-12-16
	 * (c) 2006 Alex Brem <alex@0xab.cd> - http://blog.0xab.cd
	 */
	
	(function() {
	
		var fieldSelection = {
	
			getSelection: function() {
	
				var e = this.jquery ? this[0] : this;
	
				return (
	
					/* mozilla / dom 3.0 */
					('selectionStart' in e && function() {
						var l = e.selectionEnd - e.selectionStart;
						return { start: e.selectionStart, end: e.selectionEnd, length: l, text: e.value.substr(e.selectionStart, l) };
					}) ||
	
					/* exploder */
					(document.selection && function() {
	
						e.focus();
	
						var r = document.selection.createRange();
						if (r == null) {
							return { start: 0, end: e.value.length, length: 0 }
						}
	
						var re = e.createTextRange();
						var rc = re.duplicate();
						re.moveToBookmark(r.getBookmark());
						rc.setEndPoint('EndToStart', re);
	
						return { start: rc.text.length, end: rc.text.length + r.text.length, length: r.text.length, text: r.text };
					}) ||
	
					/* browser not supported */
					function() {
						return { start: 0, end: e.value.length, length: 0 };
					}
	
				)();
	
			},
	
			replaceSelection: function() {
	
				var e = this.jquery ? this[0] : this;
				var text = arguments[0] || '';
	
				return (
	
					/* mozilla / dom 3.0 */
					('selectionStart' in e && function() {
						e.value = e.value.substr(0, e.selectionStart) + text + e.value.substr(e.selectionEnd, e.value.length);
						return this;
					}) ||
	
					/* exploder */
					(document.selection && function() {
						e.focus();
						document.selection.createRange().text = text;
						return this;
					}) ||
	
					/* browser not supported */
					function() {
						e.value += text;
						return this;
					}
	
				)();
	
			}
	
		};
	
		jQuery.each(fieldSelection, function(i) { jQuery.fn[i] = this; });
	
	})();
//***************************************************************************************

setSfhover();
