﻿/* 
Moja-Trgovina.Net main js file
(c) 2010 Sistrum d.o.o.
*/



var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-7356489-1']);
_gaq.push(['_setDomainName', 'moja-trgovina.hr']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();



function WindowOpenXY( url, x, y )
{
	var prms = "Width=" + x + "px, Height=" + y + "px, left=100, top=100, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes";
	var wnd = window.open(url, "", prms );
	if( wnd )
	    wnd.focus();
}


function ToggleListSelection()
{
    var cbox_list = document.getElementsByName("selected");
    if( cbox_list )
    {
        for( i = 0; i< cbox_list.length; i++ )
        {
            cbox_list[i].checked = !cbox_list[i].checked;
        }
    } 
}

function RequestQueryString(qs_name)
{
	var qs = document.location.search;
	if( qs < 1 )
		return null;
	else
		qs = qs.substring(1,qs.length);
	var qs_arr = qs.split('&');
	
	for( var i = 0; i<qs_arr.length; i++ )
	{	
		var qname = qs_arr[i].split('=')[0].toString().toLowerCase();
		if( qname == qs_name.toString().toLowerCase() )
			return qs_arr[i].split('=')[1];
	}
	return null;
}

function StringFormat()
{
	var s = arguments[0];
	for( var i=1; i<arguments.length; i++ ) 
    {
        var placeholder = "{" + parseInt(i-1) + "}";
        var value = arguments[i].toString();
        while( s.indexOf(placeholder) != -1 )
            s = s.replace( placeholder, value );
    }
	return s;
}

function IsNullOrEmpty( s )
{
    return ( ( !s ) || ( s.toString() == "" ) )
}


function pause(milliseconds)
{
    var _date = new Date();
    var _curDate = null;
    do 
    { 
        _curDate = new Date(); 
    }
    while(_curDate-_date < milliseconds);
}



function BookmarkPage() {    
    if (window.opera && window.print) { 
        var elem = document.createElement('a');
        elem.setAttribute('href', location.href);
        elem.setAttribute('title', document.title);
        elem.setAttribute('rel', 'sidebar');
        elem.click();
    }
    else {        
        window.external.AddFavorite(location.href, document.title);
    }
}


String.prototype.Trim = function() {
    return this.replace(/^\s+|\s+$/g, "");
}
String.prototype.LTrim = function() {
    return this.replace(/^\s+/, "");
}
String.prototype.RTrim = function() {
    return this.replace(/\s+$/, "");
}

function HtmlEncode(str) {
    var div = document.createElement('div');
    var text = document.createTextNode(str);
    div.appendChild(text);
    return div.innerHTML;
}


// jquery click on enter
function RegisterForSubmitOnEnter(selTextbox, selButton) {
    if (jQuery) {
        jQuery(document).ready(function() {
            if ((jQuery(selTextbox).length != 0) && (jQuery(selButton).length != 0)) {
                jQuery(selTextbox).keypress(function(e) {
                    if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
                        e.stopImmediatePropagation();
                        e.preventDefault();
                        var href = jQuery(selButton).attr("href");
                        href = href.replace("javascript:", "");
                        eval(href);                        
                        return false;
                    } else {
                        return true;
                    }
                });
            }
        });
    }
}
function RegisterForSubmitOnEnter_Click(selTextbox, selButton) {
    if (jQuery) {
        jQuery(document).ready(function() {
            if (jQuery(selTextbox).length != 0) {
                jQuery(selTextbox).keypress(function(e) {
                    if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
                        if (jQuery(selButton).length != 0)
                            jQuery(selButton).click();
                        return false;
                    } else {
                        return true;
                    }
                });
            }
        });
    }
}


/* ------------------ notifikacije --------------------------*/
function AjaxErrorHandler(oXMLHttpRequest, textStatus, errorThrown) {
    MessageBox("Pogreška (AJAX)", "Došlo je do pogreške u radu aplikacije. Molimo Vas da pokušate Vaš upit kasnije. (" + textStatus + ": " + errorThrown + ")");
}
function MessageBox(title, message) {
    if (jQuery) {
        jQuery("<div id='dialog-message-content'>" + message + "</div>").dialog({
            modal: true
        , resizable: false
        , draggable: false
        , closeOnEscape: true
        , title: title        
        , buttons: {
            Ok: function() { jQuery(this).dialog('close'); }
        }
        });
    }
    else {
        alert(title + ":\n" + message);
    }
}
function Notification(title, message) {
    var html = "<dl class='inline-message'><dt>" + title + "</dt><dd>" + message + "</dd></dl>";
    jQuery(document.body).append(html);
    jQuery("dl.inline-message").fadeIn();    
    setTimeout(Notification_fadeout, 4 * 1000);
}
function Notification_fadeout() {
    var box = jQuery("dl.inline-message");
    box.fadeOut("slow");
    jQuery(document.body).remove(box);
}



jQuery(document).ready(function() {
    if (jQuery("#mreze").length > 0) {
        jQuery("#mreze a[title]").tooltip({
            offset: [10, 2],
            position: "center right",
            effect: 'slide'
        })
    }
});

/* ------------------------ EOF ------------------------------------------*/
