﻿/* POSTA JAVASCRIPT LIBRARY */
/* Ergin BULUT / 2009 */

/* ANASAYFA */
var Anasayfa = {
    HavaDurumuDropDownList_OnChange: function(element) {
        var merkez = element.options[element.selectedIndex].value;
        Cookies.create("HavaDurumuMerkez", merkez, 30);
        
        $('#HavaDurumuAjaxUpdatableData').hide();
        $('#HavaDurumuAjaxLoadingAnimation').show();
        
        $.get("/D/GenericHandler.aspx?hCase=HavaDurumuGetir&rnd=" + Math.random(), function(data){
            $('#HavaDurumuAjaxUpdatableData').html(data);
            $('#HavaDurumuAjaxUpdatableData').show();
            $('#HavaDurumuAjaxLoadingAnimation').hide();
        });
    },
    AstrolojiDropDownList_OnChange: function(element) {
        var burc = element.options[element.selectedIndex].value;
        Cookies.create("AstrolojiBurc", burc, 360);
        parent.location = $('#burc_detay_url_' + burc).attr('href');
    },
    BolgeDropDownList_OnChange : function(element)
    {
        var region = element.options[element.selectedIndex].value;
        if(region != '')
        {
            parent.location='/bolgesel/' + region;
        }
    },
    Ara_Submit : function() {
        var searchKey = $('#search').val();
        
        if(searchKey == '' || searchKey == this.SearchDefaultKey)
        {
            alert('Arama kriteri boş olamaz!');
            return false;
        }
        
        parent.location = '/detayliara?q=' + encodeURIComponent(searchKey);
        return false;
    },
    Ara_Click : function() {
        if($('#search').val() == this.SearchDefaultKey)
        {
            $('#search').val('');
        }
    },
    Ara_Blur : function() {
        if($('#search').val() == '')
        {
            $('#search').val(Anasayfa.SearchDefaultKey);
        }
    },
    Yenile: function() {
        ScrollHelper.saveScrollCoordinates("Anasayfa.ScrollCoordinates");
        sx = window.location.search;
        sx = (sx == "" || sx.length > 10) ? "?ver=" : (sx.indexOf('ver=') > 0 ? sx : sx + "&ver=");
        window.location = window.location.pathname + sx + String(Math.random()).substr(2,1);
    },
    SwitchVis : function(prm) {
        if(prm==1)
        {
            $('#ul_gundem').show();
            $('#ul_spor').hide();
            $('#ul_bugun').hide();
            $('#li_gundem').addClass("current")
            $('#li_spor').removeClass("current");   
            $('#li_bugun').removeClass("current");            
        }
        if(prm==2)
        {
            $('#ul_gundem').hide();
            $('#ul_spor').show();
            $('#ul_bugun').hide();
            $('#li_spor').addClass("current")
            $('#li_gundem').removeClass("current"); 
            $('#li_bugun').removeClass("current");                      
        }        
        if(prm==3)
        {
            $('#ul_gundem').hide();
            $('#ul_spor').hide();
            $('#ul_bugun').show();
            $('#li_spor').removeClass("current")
            $('#li_gundem').removeClass("current"); 
            $('#li_bugun').addClass("current");
        }
        
        Cookies.create("Anasayfa.SwitchVis", prm, false);
    },
    changeNewsDetailFontSize : function(size){
        $('#divAdnetKeyword3 *').css('font-size', size.toString() + 'px');
    },
    SearchDefaultKey : "Posta'da Ara",
    CurrentPanaromaHoveredItem : null
}

/* COOKIES */
var Cookies = {
    init: function() {
        var allCookies = document.cookie.split('; ');
        for (var i = 0; i < allCookies.length; i++) {
            var cookiePair = allCookies[i].split('=');
            this[cookiePair[0]] = cookiePair[1];
        }
    },
    create: function(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=/";
        this[name] = value;
    },
    erase: function(name) {
        this.create(name, '', -1);
        this[name] = undefined;
    }
};
Cookies.init();

/* STATS HELPER CLASS */
/* Use as lazy loading.. */
var StatsHelper = {
    count : function(sourceId, uniqueId, random){
        var cookiename = "StatsHelper_" + uniqueId + "_" + random;
        if(Cookies[cookiename] == '1') return;
        
        var img = document.createElement("img");
        img.src = "http://istatistik.posta.com.tr/CntRpt.aspx?SourceID="+ sourceId +"&UniqueID="+ uniqueId +"&Random=" + random;
        img.style.display = "none";
        img.style.width = "1px";
        img.style.height = "1px";
        
        document.body.appendChild(img);
        
        Cookies.create(cookiename, "1", (1/(24*60)));  // 1 minute.
    }
}

/* SCROLL HELPER CLASS */
var ScrollHelper = {
    getScrollXY : function() {
        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 ];
    },
    saveScrollCoordinates : function(name){
      if(name == null || name == undefined) name = "FotoGaleri.ScrollCoordinates";
      Cookies.create(name, this.getScrollXY(), false);
    },
    scrollToSavedCoordinates : function(name){
        if(name == null || name == undefined) name = "FotoGaleri.ScrollCoordinates";
        var scrollPositions = Cookies[name];
        if(scrollPositions != null && scrollPositions != '')
        {
          var positions = scrollPositions.split(',');
          window.scrollTo(positions[0], positions[1]);
          Cookies.erase(name);
        }
    }
}

/* PAGE LOAD */
$(document).ready(function(){
    if(Cookies["PostaMember.Name"] != null && Cookies["PostaMember.Name"] != '')
    {
        $('#MemberName').html(Url.decode(Cookies["PostaMember.Name"]));
        $('#login').show();
    }
    if(Cookies["Anasayfa.SwitchVis"] != null && Cookies["Anasayfa.SwitchVis"] != '')
    {
        Anasayfa.SwitchVis(Cookies["Anasayfa.SwitchVis"]);
    }
    if ($.browser.msie && jQuery.browser.version.substring(0,1) == "6")
    {
        $("a[href='javascript:;']").attr("href", "#");
    }
    $('#search').val(Anasayfa.SearchDefaultKey);
    $('#search').blur(function(){Anasayfa.Ara_Blur();});
    $('#search').click(function(){Anasayfa.Ara_Click();});
    $('#search').keypress(function(e){
        if(e.which == 13){
            Anasayfa.Ara_Submit();
            return false;
        }
    });
    if(window.location.pathname == '/')
    {
        ScrollHelper.scrollToSavedCoordinates("Anasayfa.ScrollCoordinates");
        $("a[href*='.htm']").attr('target', '_blank');
        setTimeout('Anasayfa.Yenile()', 3 * 60 * 1000);
    }
    
    if($.browser.msie && window.location.pathname.indexOf('.htm') > 0 && window.opener != null && window.opener.location.pathname == '/'){
        CurrentWindow.maximize();
        window.opener = null;
    }
    
    $('a.panaroma-anchor div.panaromaHover').fadeTo(1, 0);
    $('a.panaroma-anchor').mouseenter(function(){
        $('div.panaromaHover', this).fadeTo(500, 0.75);
        $('span', this).fadeTo(500, 1);
    });
    $('a.panaroma-anchor').mouseleave(function(){
        $('*:gt(0)', this).fadeTo(500, 0);
    });
    
   // Check WTCookie
   if(readCookie("WTCookie")==null)
   {
       var tarih = new Date()
       createCookie("WTCookie", tarih.getTime(), 10000);
   }
});


/* VALIDATION */
var Validation = {
    isValidEmail: function(string) {
        if (string.search(/^[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
            return true;
        else
            return false;
    },
    isValidPassword: function(string) {
        if (string.search(/^\w{4,16}$/) != -1)
            return true;
        else
            return false;
    },
    isValidUsername: function(string) {
        if (string.search(/^\w{4,32}$/) != -1)
            return true;
        else
            return false;
    }
}

/* COMMON */
var Common = {
    checkAll: function(parentCheckBox, checkBoxNamesStartWith) {
        for(var i=0; i < document.forms[0].elements.length; i++)
        {
          if(document.forms[0].elements[i].name.indexOf(checkBoxNamesStartWith) == 0)
            document.forms[0].elements[i].checked = parentCheckBox.checked;
        }
    },
    getQueryStringVariable : function(variable)
    {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++)
        {
            var pair = vars[i].split("=");
            if (pair[0] == variable)
            {
                return Url.decode(pair[1]);
            }
        }
    },
    voteComment : function(articleId, userArticleId, commentId, isPositive){
        $.post("/D/GenericHandler.aspx?hCase=VoteArticleComment", {ArticleID: articleId, UserArticleID: userArticleId, CommentID: commentId, IsPositive: isPositive}, function(data){
            if(data.length > 0){
                if(Cookies["ArticleVoteCommentIDs"] == null || Cookies["ArticleVoteCommentIDs"] == '')
                    Cookies.create("ArticleVoteCommentIDs", commentId, 1);
                else
                {
                    var values = Cookies["ArticleVoteCommentIDs"] + ',' + commentId;
                    Cookies.erase("ArticleVoteCommentIDs");
                    Cookies.create("ArticleVoteCommentIDs", values, 1);
                }
                    
                var container_id = 'vote_article_container_' + commentId;
                $('#'+ container_id + ' .voteText, #'+ container_id + ' .goodVote, #'+ container_id + ' .badVote').fadeOut();
                $('#'+ container_id + ' .numberVote span').html(data);
                
                if(parseInt(data) == -1 && $('#'+ container_id + ' .stateGoodVote').length == 1)
                    $('#'+ container_id + ' .stateGoodVote').removeClass('stateGoodVote').addClass("stateBadVote");
                if(parseInt(data) == 0 && $('#'+ container_id + ' .stateBadVote').length == 1)
                    $('#'+ container_id + ' .stateBadVote').removeClass('stateBadVote').addClass("stateGoodVote");
            }
            else{
                alert("Beklenmeyen bir sorun oluştu, lütfen daha sonra tekrar deneyiniz!");
            }
        });
    },
    setVoteEnabledDisabledStatusByCookie : function(){
        if(Cookies["ArticleVoteCommentIDs"] == null) return;
        if(Cookies["ArticleVoteCommentIDs"] == '') return;
        
        $('div.vote').each(function(i){
            var ids = Cookies["ArticleVoteCommentIDs"].split(',');
            for(var i=0; i<ids.length; i++)
            {
                if(this.id == 'vote_article_container_' + ids[i])
                {
                    var container_id = 'vote_article_container_' + ids[i];
                    $('#'+ container_id + ' .voteText, #'+ container_id + ' .goodVote, #'+ container_id + ' .badVote').hide();
                }
            }
        });
    }
}
/* POPUPS */
var Popups = {
    // Article
    FotoEkle: function(articleID) {
            window.open('/UyelikIslemleri/FotoGiris?ArticleID='+ articleID, '_blank', '');
        },
    VideoEkle: function(articleID) {
            window.open('/UyelikIslemleri/VideoGiris?ArticleID='+ articleID, '_blank', '');
        },        
    YorumYaz: function(articleID, commentID) {
            window.open('/YorumIslemleri/YorumYaz?ArticleID='+ articleID +'&CommentID=' + ((commentID != null && commentID != undefined) ? commentID : ""), '', 'width=670,height=420');
        },
    YorumYazGenel: function(sourceTypeID, articleID, commentID) {
            window.open('/YorumIslemleri/YorumYaz?SourceTypeID='+ sourceTypeID +'&ArticleID='+ articleID +'&CommentID=' + ((commentID != null && commentID != undefined) ? commentID : ""), '', 'width=670,height=420');
        },
    Yazdir: function(articleID) {
            window.open('/Default.aspx?aType=HaberYazdir&ArticleID='+ articleID, '', 'width=670,height=420,scrollbars=1');
        },
    ArkadasinaGonder: function(articleID) {
            window.open('/Default.aspx?aType=ArkadasinaGonder&ArticleID='+ articleID, '', 'width=670,height=550,scrollbars=1');
        },

    // UserArticle
    OkurHaberFotoEkle: function(articleID) {
            window.open('/UyelikIslemleri/FotoGiris?UserArticleID='+ articleID, '_blank', '');
        },
    OkurHaberVideoEkle: function(articleID) {
            window.open('/UyelikIslemleri/VideoGiris?UserArticleID='+ articleID, '_blank', '');
        },        
    OkurHaberYorumYaz: function(userArticleID, commentID) {
            window.open('/YorumIslemleri/YorumYaz?UserArticleID='+ userArticleID +'&CommentID=' + ((commentID != null && commentID != undefined) ? commentID : ""), '', 'width=670,height=420');
        },
    OkurHaberYazdir: function(userArticleID) {
            window.open('/Default.aspx?aType=HaberYazdir&UserArticleID='+ userArticleID, '', 'width=670,height=420,scrollbars=1');
        },
    OkurHaberArkadasinaGonder: function(userArticleID) {
            window.open('/Default.aspx?aType=ArkadasinaGonder&UserArticleID='+ userArticleID, '', 'width=670,height=550,scrollbars=1');
        },

    // Horoscope
    AstrolojiHaberYorumYaz: function(horoscopeID, commentID) {
            window.open('/YorumIslemleri/YorumYaz?HoroscopeID='+ horoscopeID +'&CommentID=' + ((commentID != null && commentID != undefined) ? commentID : ""), '', 'width=670,height=420');
        },
    AstrolojiHaberYazdir: function(horoscopeID) {
            window.open('/Default.aspx?aType=HaberYazdir&HoroscopeID='+ horoscopeID, '', 'width=670,height=420,scrollbars=1');
        },
    AstrolojiHaberArkadasinaGonder: function(horoscopeID) {
            window.open('/Default.aspx?aType=ArkadasinaGonder&HoroscopeID='+ horoscopeID, '', 'width=670,height=550,scrollbars=1');
        }   
}

/* WINDOW */
var CurrentWindow = {
    maximize : function() {
        window.moveTo(0,0);
        if (document.all)
        {
          top.window.resizeTo(screen.availWidth,screen.availHeight);
        }
        else if (document.layers||document.getElementById)
        {
          if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth)
          {
            top.window.outerHeight = screen.availHeight;
            top.window.outerWidth = screen.availWidth;
          }
        }
    }
}

/* SHARE URL */
var ShareUrl = {
    facebook : function(){
        window.open('http://www.facebook.com/sharer.php?title=' + encodeURIComponent(document.title) + '&u=' + encodeURIComponent(document.location), '', 'height=650,width=910,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1');
    },
    google : function(){
        window.open('http://www.google.com/bookmarks/mark?op=edit&title=' + encodeURIComponent(document.title) + '&bkmk=' + encodeURIComponent(document.location), '', 'height=650,width=910,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1');
    },
    yahoo : function(){
        window.open('http://myweb2.search.yahoo.com/myresults/bookmarklet?t=' + encodeURIComponent(document.title) + '&u=' + encodeURIComponent(document.location), '', 'height=650,width=910,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1');
    },
    myspace : function(){
        window.open('http://www.myspace.com/Modules/PostTo/Pages/?l=2&t=' + encodeURIComponent(document.title) + '&u=' + encodeURIComponent(document.location), '', 'height=650,width=910,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1');
    },
    friendFeed : function(){
        window.open('http://friendfeed.com/share/bookmarklet/frame?title=' + encodeURIComponent(document.title) + '&url=' + encodeURIComponent(document.location), '', 'height=650,width=910,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1');
    },
    mixx : function(){
        window.open('http://www.mixx.com/submit/story?title=' + encodeURIComponent(document.title) + '&page_url=' + encodeURIComponent(document.location), '', 'height=650,width=910,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1');
    },
    digg : function(){
        window.open('http://digg.com/submit?title=' + encodeURIComponent(document.title) + '&url=' + encodeURIComponent(document.location), '', 'height=650,width=910,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1');
    },
    stumpleUpon : function(){
        window.open('http://www.stumbleupon.com/submit?title=' + encodeURIComponent(document.title) + '&url=' + encodeURIComponent(document.location), '', 'height=650,width=910,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1');
    },
    delicious : function(){
        window.open('http://del.icio.us/post?title=' + encodeURIComponent(document.title) + '&url=' + encodeURIComponent(document.location), '', 'height=650,width=910,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1');
    },
    reddit : function(){
        window.open('http://reddit.com/submit?title=' + encodeURIComponent(document.title) + '&url=' + encodeURIComponent(document.location), '', 'height=650,width=910,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1');
    },
    twitter : function(){
        window.open('http://twshot.com/share.aspx?title=' + encodeURIComponent(document.title) + '&url=' + encodeURIComponent(document.location), '', 'height=650,width=910,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1');
    }
}

/* URL ENCODE/DECODE */
var Url = {
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}

		return string;
	}
}
var Paging = {
    _pageIndexKey : "PageIndex",
    create : function(totalPages, pageIndex){
        document.write('<div class="yPaging">');
        document.write('  <ul>');
        
        if(pageIndex > 1)
            document.write('    <li class="geri"><a href="'+ this.getBaseUrl() + this._pageIndexKey + '=' + (pageIndex - 1) +'"></a></li>');
        if(pageIndex < totalPages)
            document.write('    <li class="ileri"><a href="'+ this.getBaseUrl() + this._pageIndexKey + '=' + (pageIndex + 1) +'"></a></li>');
        
        for(var i=1; i<=totalPages; i++)
        {
            if(i > 20) break;
            
            if(pageIndex == i)
                document.write('<li class="current">');
            else
                document.write('<li>');
                
            document.write('<a href="'+ this.getBaseUrl() + this._pageIndexKey + '=' + i +'">'+ i +'</a>');
            document.write('</li>');
        }

        document.write('  </ul>');
        document.write('</div>');
    },
    getBaseUrl : function(){
        if(window.location.href.indexOf(this._pageIndexKey) > -1)
            return window.location.href.substring(0, window.location.href.indexOf(this._pageIndexKey));
        
        return window.location.href + '&';
    }
}

var Bolgesel = {
    BolgeDropDown_OnChange: function(element) {
        var bolge = element.options[element.selectedIndex].value;
        $.get("/D/GenericHandler.aspx?hCase=BolgeIlGetir&RegionID="+bolge, function(data){
            $('#BolgeUpdatableHTML').html(data);
        });
    },
    Switch: function() {
        if($('div.bolgeHarita a:first').hasClass('ac'))
        {
            $('#bolgesel_harita').slideDown();
            $('div.bolgeHarita a:first').attr('class','kapat');
            $('div.bolgeHarita a:first').text('Haritayı Kapat');
        }
        else
        {
            $('#bolgesel_harita').slideUp();
            $('div.bolgeHarita a:first').attr('class','ac');
            $('div.bolgeHarita a:first').text('Haritayı Aç');
        }
    },
    GoToCity: function() {
        var elmRegion = $('#RegionSelect').get(0);
        var elmCityID = $('#BolgeUpdatableHTML').get(0);
        if(elmRegion.selectedIndex>0)
            document.location = '/Bolgesel/'+elmRegion.options[elmRegion.selectedIndex].getAttribute("path") +'?CityID='+elmCityID.options[elmCityID.selectedIndex].value;
    }    
}

var MansetNewsTicker = {
      _counter : 1,
      _timerCount : null,
      _maxHeaderlineCount : 0,
      showArticle : function(selectedItemIndex)
      {
          this.stopTimer();
          for(i=1; i<=this._maxHeaderlineCount; i++)
          {
              if(i != selectedItemIndex)
              {
                  document.getElementById('HeaderTable_'+i).style.display = 'none';
                  document.getElementById('HeaderOK_'+i).className = '';
              }
              else
              {
                  document.getElementById('HeaderTable_'+i).style.display = 'block';
                  document.getElementById('HeaderOK_'+i).className = 'current';
              }
          }
      },
      timerStart : function(counterNum)
      {
        if(counterNum != -1)
            this._counter = counterNum;
        if(this._counter > this._maxHeaderlineCount) 
            this._counter = 1;
        for(i=1; i <=this._maxHeaderlineCount; i++)
        {
            if(i != this._counter)
            {
              document.getElementById('HeaderTable_'+i).style.display = 'none';
              document.getElementById('HeaderOK_'+i).className = '';
            }
            else
            {
              document.getElementById('HeaderTable_' + i).style.display = 'block';
              document.getElementById('HeaderOK_' + i).className = 'current';
            }
        }
        this._counter = this._counter + 1;
        this._timerCount = setTimeout("MansetNewsTicker.timerStart(-1)", 6000);
      },
      stopTimer : function()
      {
        clearTimeout(this._timerCount);
      },
      init : function(maxHeaderlineCount){
        this._maxHeaderlineCount = maxHeaderlineCount;
        this.timerStart(-1);
        document.getElementById('HeaderTable_1').style.display = 'block';
        document.getElementById('HeaderOK_1').className = 'current';
      }
}

// Required for WTCookie
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;
}
