//***************************************************************************************
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 HideLoadingDataDiv() 
    {
        $('#loadingDiv').dialog('close');
        $('#loadingDiv').remove();

        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";
                    $(this).removeClass('sfhover');
                    $(this).addClass('sfhover');
                }
                sfEls[i].onmouseout = function () {
                    //this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
                    $(this).removeClass('sfhover');
                }
            }
        }
    }
//***************************************************************************************
	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); */
        var $dialog = $('<div id="loadingDiv" align="center"></div>')
			.html('<img src="' + BASE_URL + 'images/indatus_loading.gif" border="0">')
			.dialog({
			    autoOpen: true,
			    title: '',
			    modal: true,
			    resizable: false,
                draggable: false,
			    width:  '550px',
                height: 'auto',
                position:   'center'
			});
          $dialog.dialog('open');
          $('div.ui-dialog-titlebar').remove();
	}
//***************************************************************************************
    function loadController(selectedController,additionalDatalist,showloading)
    {
        $('#currentCT').val(selectedController);
        faqWindow.destroy({});
        $('#core_content').html("");
        //alert(typeof(showloading)+'--'+showloading.length+'--'+showloading);
        if(typeof(showloading)=='string' && showloading.length>0 && showloading=='true')
            $('#core_content').html('<center><image src="'+BASE_URL+'/images/retrievingData_tan.gif"></center>');

        
        
        var datalist='javaLoad=true&loadingController=true';

        if(typeof(additionalDatalist)=='string' && additionalDatalist.length>0)
            datalist+=additionalDatalist;

		$.ajax({
			type: "POST",
			url: BASE_URL+selectedController,
			data: datalist,
			success: function(returnData)
			{
				//alert(returnData);
				$('#core_content').html(returnData);
			},
			error: function (returnData)
			{
				$('#core_content').html('Error: unable to load controller please contact your systems administrator!');
				//error checking
			}
		});


        $('.selectedMenu_UnderLineClick').each(
		    function ()
		    {
			    $(this).removeClass('selectedMenu_UnderLineClick');
		    }
	    );
			
	    //$('#1\\:clicktracker\\/'+controller+'\\/\\:1').addClass('selectedMenu_UnderLineClick');
        
	    var underLineRegExp=new RegExp(':'+selectedController+':','gim');
        
        var selectedId='';
	    $('.core_navBucketChoice')
        .filter(function() {
            if($(this).attr('id').match(underLineRegExp)){
                selectedId=$(this).attr('id').split(':')[0];
			    $(this).addClass('selectedMenu_UnderLineClick');
		    }else{
                
            }
        });

        var marginRight=0;
        var paddingRight=0;
        try{marginRight = parseInt($('.core_navBucket').css('margin-right').replace("px", ""));}catch(e){}
        try{paddingRight = parseInt($('.core_navBucket').css('padding-right').replace("px", ""));}catch(e){}

        var BUCKET_OFFSET=marginRight+paddingRight;
        
        /*****************************
		*	Start move the menu arrow
		*****************************/
        if(selectedId!=''){
            $('.core_selectedMenu').fadeOut(1,
			    function ()
			    {
				    var count=0;
				    $('.core_navBucket').each(
					    function()
					    {
						    if($(this).attr('id')==selectedId)
						    {
							    if(count==0)
								    var offset=($(this).width()/2)-($('.core_selectedMenu').width()/2);
							    else
								    var offset=(($(this).width()/2)-($('.core_selectedMenu').width()/2))+(($(this).width()*count)+(count*BUCKET_OFFSET));

							    $('.core_selectedMenu').css('margin-left',offset)
						    }
					    count++;
					    }
				    );
				    $('#selectedMenuArea').show();
			    }
		    );
        }
        else{
           $('#selectedMenuArea').hide();
        }
        /*****************************
		*	End move the menu arrow
		*****************************/
    }
//***************************************************************************************
	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)
		}
		
		
		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(myfield.value.length>=10 && key!=8 && key!=46 && key!=0)
		{
			//myfield.value=myfield.value.substring(0,9)
            return false;
		}
        
		
		if ((key==null) || (key==0) || (key==8) ||
		    (key==9) || (key==13) || (key==27) || (key!=46))
		   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; });
	
	})();
//***************************************************************************************

function textCounter(textarea, counterID, maxLen) {
    var characterCount = document.getElementById(counterID);
	
    if (textarea.value.length > maxLen){
		textarea.value = textarea.value.substring(0,maxLen);
    }

    characterCount.innerHTML = maxLen - textarea.value.length;
}

//****************************************************************

setSfhover();









//------------------------------------------------------------
// suppress all error messages and do nothing with them:
//
//function noErrorMessages () { return true; }
//window.onerror = noErrorMessages;

//------------------------------------------------------------
// advanced: a full error handler
//
/*function handleError (err, url, line) {
    alert(
        "Error: "+err+"\n"+
        "URL: "+url+"\n"+
        "Line: "+line+"\n"
    );
    return true; // error is handled
  }

window.defaultOnError = window.onerror; // store default handler
window.onerror = handleError; // assign own handler
*/
//.. executing my faulty code

//window.onerror = window.defaultOnError;  // restore default handler


