function getScrollXY() 
{
  var scrOfX = 0, scrOfY = 0;
  
  if( typeof( window.pageYOffset ) == 'number' ) 
  {
	  //Netscape compliant
	  scrOfY = window.pageYOffset;
	  scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
  {
	  //DOM compliant
	  scrOfY = document.body.scrollTop;
	  scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
  {
	  //IE6 standards compliant mode
	  scrOfY = document.documentElement.scrollTop;
	  scrOfX = document.documentElement.scrollLeft;
  }
  
  return [ scrOfX, scrOfY ];
}
	
function alertSize() 
{
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) 
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	{
		//IE 4 compatible
	    myWidth = document.body.clientWidth;
	    myHeight = document.body.clientHeight;
	}

	return [ myWidth, myHeight ];
}

	
function makeBookmark()
{
	var host=document.location.host,
	u='http://'+host+'/';
		
	try
	{
		if (window.sidebar)
		{
			window.sidebar.addPanel(this.title, u, '');
		}else if(document.all)
		{
			window.external.AddFavorite(u, this.title);
		}
	}catch(ex){alert(ex.message)}
	
	return false;
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
	var today = new Date();
	today.setTime( today.getTime() );

	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 Get_Cookie( check_name ) 
{
	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++ )
	{
		a_temp_cookie = a_all_cookies[i].split( '=' );
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}
	

function cookieChecker()
{
	Set_Cookie( 'test', 'none', '', '/', '', '' );
	if (!Get_Cookie( 'test' ) )
	{
		$('.errors').append('<h2>Cookies are not currently enabled.</h2>');
		cookie_set = false;
	}
}

$(function()
{
	var loc  = String(window.location);
	var pattern = /#.+$/;
	var result = pattern.exec(loc);

	if(result)
	{
		loc = loc.replace(result[0], '');
	}

	$.each($('.anchor'), function()
	{
		$(this).attr('href', loc + $(this).attr('href'));
	})
	
	/* Check cookie */
	cookieChecker();
	
	/* 
	 * Chat online
	$("#chat_online").html("<span id='chatImageSpan' name='chatImageSpan'></span> " +
			"<script type='text/javascript'> var chatQueue = 1;var enduserportal = 0;  " +
			"var chatAccnt = 'ligro_trial';  " +
			"var chatUrlPreffix = 'http://helpdesk.acs-24.com:8080/'; " +
			"offlineImage = './images/chat/offline.png'; " +
			"onlineImage = './images/chat/online.png'; </script>	" +
			"<script type=text/javascript src=http://helpdesk.acs-24.com:8080/ChatImage?queue=1&script=yes></script>");
	*/
	
	$('select[name="product"]').change(function(){
		$(this).parents('form').append('<input type="hidden" name="up" value="1"/>');
		$(this).parents('form').submit();
	});
	
	$('input[name="form_shipping"]').change(function(){
		$(this).parents('form').append('<input type="hidden" name="up" value="1"/>');
		$(this).parents('form').submit();
	});
})
