﻿
function movecalendar() {
    var element = $get('news-container');

    if (element != null) {
        var finish = element.scrollTop + 196;

        if (finish >= element.scrollHeight) {
            for (var i = element.scrollTop; i > 0; i = i - 6) {

                element.scrollTop = i;
                sleep(10);
            }
        }
        else {
            for (var i = element.scrollTop; i < finish; i = i + 6) {

                element.scrollTop = i;
                sleep(30);
            }
        }

        window.setTimeout('movecalendar();', 5000);
    }
}

function sleep(milliseconds) {
    var start = new Date().getTime();
    for (var i = 0; i < 1e7; i++) {
        if ((new Date().getTime() - start) > milliseconds) {
            break;
        }
    }
}

window.setTimeout('movecalendar();', 5000);

function __CheckAll(me) {
    var index = me.name.indexOf('_');
    var prefix = me.name.substr(0, index);
    for (i = 0; i < me.parentElement.parentElement.parentElement.parentElement.parentElement.all.length; i++) {
        var o = me.parentElement.parentElement.parentElement.parentElement.parentElement.all[i];
        if (o.type == 'checkbox') {
            if (me.name != o.name) {
                if (o.name.substring(0, prefix.length) == prefix) {
                    // Must be this way
                    o.checked = !me.checked;
                    o.click();
                }
            }
        }
    }
}

function ApplyStyle(me, selectedForeColor, selectedBackColor, foreColor, backColor, bold, checkBoxHeaderId) {
    var td = me.parentNode;
    if (td == null)
        return;

    var tr = td.parentNode;
    if (me.checked) {
        tr.style.fontWeight = 700; // bold
        tr.style.color = selectedForeColor;
        tr.style.backgroundColor = selectedBackColor;
    }
    else {
        document.getElementById(checkBoxHeaderId).checked = false;
        tr.style.fontWeight = bold;
        tr.style.color = foreColor;
        tr.style.backgroundColor = backColor;
    }
}

var mouseOutColor;
var mouseCursor;
var mouseClassName;
function __MouseOverRow(source, mouseOverColor, styleclass) {
    mouseClassName = source.className
    mouseOutColor = source.style.backgroundColor;

    if (styleclass != null && styleclass != '') {
        source.className = styleclass;
    }
    else {
        source.style.backgroundColor = mouseOverColor;
    }

    mouseCursor = source.style.cursor;
    source.style.cursor = 'pointer';
}

function __MouseOutRow(source) {
    source.style.backgroundColor = mouseOutColor;
    source.style.cursor = mouseCursor;
    source.className = mouseClassName;
}

function ka1(e) {
    if (!e) {
        e = event;
    }
    var source = e.target || e.srcElement;

    return source.nodeName != 'DIV' && source.type != 'checkbox' && source.type != 'radio' && source.nodeName != 'A';
}

function SetUniqueRadioButton(nameregex, current) {
    re = new RegExp(nameregex);

    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type == 'radio') {
            //if (re.test(elm.name)) {
                elm.checked = false;
            //}
        }
    }

    current.checked = true;
}



var EcommerceServiceObject = null;

function GetEcommerceService() {
    if (EcommerceServiceObject == null) {
        EcommerceServiceObject = new IEcommerceService();
    }

    return EcommerceServiceObject;
}

function AddComment(Sender, SalesItemId, CommentId, PanelId, OkMessage, ErrorMessage) {
    var EcommerceServiceObj = GetEcommerceService();

    var comment = $get(CommentId);
    var panel = $get(PanelId);

    toggleDisabled(panel, true);

    EcommerceServiceObj.AddComment(SalesItemId, comment.value,
        function () {
            panel.style.display = 'none';
            comment.value = '';

            toggleDisabled(panel, false);
            alert(OkMessage);
        },
        function () {

            toggleDisabled(panel, false);
            alert(ErrorMessage);
        }
    );
}

function CancelCommentAdd(Sender, PanelId) {
    $get(PanelId).style.display = 'none'; 
}

function toggleDisabled(el, fixedValue) {
    if (el != null) {
        try {
            if (fixedValue != null) {
                el.disabled = fixedValue;
            }
            else {
                el.disabled = el.disabled ? false : true;
            }
        }
        catch (E) {
            var k = E;
        }

        if (el.childNodes && el.childNodes.length > 0) {
            for (var x = 0; x < el.childNodes.length; x++) {
                if (el.childNodes[x] != null && el.childNodes[x].nodeType == 1) {
                    toggleDisabled(el.childNodes[x], fixedValue);
                }
            }
        }
    }
}



function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
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" : "" );
}


// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	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++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

Sys.Application.add_load(function() {
    	var isShown = Get_Cookie('PopupShown');

	if( ! (isShown == 'true') )
	{
		Set_Cookie('PopupShown', 'true', '', '/', '', '');

	    var mp = $find('ModalPopupExtender1');
		if(mp!=null) mp.show();
	}
});

function OpenPopup(Url, Title) {
    window.open(Url, Title, "width=800,height=600");
    return false;
}

function lightup(element, imgName) {
    element.children[0].src = imgName;
}

function turnoff(element, imgName) {
    element.children[0].src = imgName;
}


try
{

            $(function () {
                $('.slide').anythingSlider({
                    delay: 10000,
                    navigationFormatter: function (index, panel) {

                        return '<img src="' + $('#ctl00_ctl00_CMSWebPartManager_BigBook_BigBookTitle_ctl00_rptItems_ctl0' +  (index - 1).toString() + '_lnkBigImage_' + (index - 1).toString()+ " img").attr("src") + '" />';
                        //return ['', '', '', ''][index - 1];

                    }
                });
            });
}
catch(e){}

