var CookieManager = new function() {
	var path = "/";
	var domain = null;
	var secure = null;

	this.getCookie = function (name) { 
		var start = document.cookie.indexOf( name + "=" ); 
		var len = start + name.length + 1; 
		if ( (!start ) && ( name!= document.cookie.substring( 0, name.length ) ) ) { 
			return null; 
		} 
		if ( start == -1 ) return null; 
		var end = document.cookie.indexOf( ';', len ); 
		if ( end == -1 ) end = document.cookie.length; 
		return unescape( document.cookie.substring( len, end ) ); 
	} 

	this.setCookie = function (name, value, shelfLife) { 
		if ((name == null) || (name == "") || (value == null))
			return;
		var today = new Date(); 
		today.setTime( today.getTime() ); 
		if ( shelfLife ) { 
			shelfLife = shelfLife * 1000 * 60 * 60 * 24; 
		} 
		var expires_date = new Date( today.getTime() + (shelfLife) ); 
	
		document.cookie = name+'='+escape( value ) + 
		( ( shelfLife )? ';expires='+expires_date.toGMTString() : '' ) +
		( ( path )? ';path=' + path : '' ) + 
		( ( domain )? ';domain=' + domain : '' ) + 
		( ( secure )? ';secure' : '' ); 
	} 

	this.deleteCookie = function (name) { 
		if ( this.getCookie( name ) ) 
		    document.cookie = name + '= ' + ( ( path )? ';path=' + path : '') + ( ( domain )? ';domain=' + domain : '' ) + ';expires=Thu, 01-Jan-1970 00:00:01 GMT'; 
	}
	
	this.resetCookies = function () {
		var cookies = document.cookie.split ("; ");
		for (var i=0; i<cookies.length; i++) {
			var tmp = cookies[i].split ("=");
			if (tmp.length > 0)
				this.deleteCookie (tmp[0]);
		}
	}
}


function switchToEnglish(){
	setLanguageToEngilsh();
	document.location = "http://www.galitz.co.il/en";
}

function switchToHebrew(){
	setLanguageToHebrew();	
	document.location = "http://www.galitz.co.il";
}

function setLanguageToEngilsh(){
	CookieManager.setCookie("len", "en", 30);
}

function setLanguageToHebrew(){
	CookieManager.setCookie("len", "he", 30);
}

function getLanguage(){
	var len = CookieManager.getCookie("len");
	return (len)? len : "he";
}
