var modelsel = 0;
var wptelvendor = "";

	function goAfterConfirm (url, confirm) {
		if ((! confirm) || (confirm && window.confirm(confirm))) {
			window.location = url;
		}
	}
	
	function count_chars() {
		if (document.objectEditForm.objectDescription.value.length < 501) {
			a=document.objectEditForm.objectDescription.value.length;
			b=500;
			c=b-a;
			document.objectEditForm.numberOfChars.value=c;
		} else {
			alert('Przekroczono dozwoloną ilość znaków !!!');
		}
	}

	function popupAddNewElem(type) {
		if(type == 'tag') {
			elemName = 'tag';
			setElemMethodName = '/panel/setTagFromPopup/';
		} else if(type == 'phoneNumber') {
			elemName = 'numer telefonu';
			setElemMethodName = '/panel/setPhoneNumberFromPopup/';			
		} else {
			elemName = '';
			setElemMethodName = '#';		
		}
		x=250;
		y=150;	
		html='<html><head>';
		html= html + '<title>Mobero.pl - Panel</title>';
		html= html + '<link href="/skin/css/panel_style.css" rel="stylesheet" type="text/css" media="screen" />';
		html= html + '</head><body class="popUpBody">';
		html= html + '<h2>Wpisz nowy ' + elemName + '</h2><form id="popupForm" name="tagEditForm" action="' + setElemMethodName + '" method="POST"><input name="elemValue" class="inpTxt" type="text" value="" /><input name="saveBtn" class="btn" type="submit" value="Zapisz" /></form>';
		html= html + '</body></html>';
		okno = 'width=' + x + ',height=' + y + ',toolbar=no,left='+(screen.availWidth-x)/2+',top='+(screen.availHeight-y)/2+',status=1,scrollbars=1';
		with(window.open('about:blank', '', okno)) {
			document.open();
			document.write(html);
			document.close();
			focus();
		}
	}

	function validateObject() {
		if(document.getElementById('phoneNumberForObj').value == '0' && document.getElementById('visibilityCheckbox').checked) {
			alert('Należy wybrać numer telefonu dla każdego publikowanego obiektu');
		}
		else if(document.getElementById('categoriesToJoin').value == '0' && document.getElementById('visibilityCheckbox').checked){
			alert('Należy wybrać kategorię dla każdego publikowanego obiektu');
		}
		else if((document.getElementById('tagsToJoin').value == '0' || document.getElementById('tagsToJoin').value == '') && document.getElementById('visibilityCheckbox').checked){
			alert('Należy wybrać co najmniej jeden tag dla każdego publikowanego obiektu. Wśród wybranych tagów nie może znajdować się opcja: --- brak ---');
		}		
		else {
			if(document.getElementById('visibilityCheckbox').checked) {
				document.getElementById('active').value = 1;
			} else { 
				document.getElementById('active').value = 0;
			}
			document.getElementById('submitBtn').click();
		}
	}
	
	function showUsersComments() {
		document.getElementById('userCommentsTr').style.display = 'block';
		document.getElementById('commentAddedInfoTr').style.display = 'none';
		document.getElementById('showUsersCommentsSpan').innerHTML = 'Wasze komentarze';
		showCommentForm();
	}
	
	function showCommentForm() {
		document.getElementById('addCommentNickTr').style.display = 'block';
		document.getElementById('addCommentTextLabelTr').style.display = 'block';
		document.getElementById('addCommentTextareaTr').style.display = 'block';
		document.getElementById('addCommentCodeImageTr').style.display = 'block';
		document.getElementById('addCommentCodeInputTr').style.display = 'block';	
		document.getElementById('addCommentBtnTr').style.display = 'block';			
	}

jQuery.fn.rating = function(){
    return this.each(function(){
        var div = jQuery("<div/>").attr({
            title: this.title,
            className: this.className
        }).insertAfter( this );

        jQuery(this).find("select option").each(function(){
            div.append( this.value == "0" ?
                "<div class=\"cancel\"><a href=\"http://www.mobero.pl/page/objectRate/" + this.title + ",0\" title=\"Oceń ten obiekt na: 0\" onclick=\"alert('" + this.title + "')\">Ocena na 0</a></div>" :
                "<div class=\"star\"><a href=\"http://www.mobero.pl/page/objectRate/" + this.title + "," + this.value + "\" title=\"Oceń ten obiekt na: " + this.value + "\" onclick=\"window.location='http://www.mobero.pl/page/objectRate/" + this.title + "," + this.value + "'\">" + this.value + "</a></div>" );
        });

        var averageRating = this.title.split(/:\s*/)[1].split("."),
            url = this.action,
            averageIndex = averageRating[0],
            averagePercent = averageRating[1];

        // hover events and focus events added
        var stars = div.find("div.star")
            .mouseover(drainFill).focus(drainFill)
            .mouseout(drainReset).blur(drainReset)
            .click(click);

        // cancel button events
        div.find("div.cancel")
            .mouseover(drainAdd).focus(drainAdd)
            .mouseout(resetRemove).blur(resetRemove)
            .click(click);

        reset();

        function drainFill(){ drain(); fill(this); }
        function drainReset(){ drain(); reset(); }
        function resetRemove(){ reset(); jQuery(this).removeClass('on'); }
        function drainAdd(){ drain(); jQuery(this).addClass('on'); }

        function click(){
            averageIndex = stars.index(this) + 1;
            averagePercent = 0;

            if ( averageIndex == 0 )
                drain();

            jQuery.post(url,{
                rating: jQuery(this).find('a')[0].href.slice(1)
            });

            return false;
        }

        // fill to the current mouse position.
        function fill( elem ){
            stars.find("a").css("width", "100%");
            stars.lt( stars.index(elem) + 1 ).addClass("hover");
        }
    
        // drain all the stars.
        function drain(){
            stars.removeClass("on hover");
        }

        // Reset the stars to the default index.
        function reset(){
            stars.lt(averageIndex).addClass("on");

            var percent = averagePercent ? averagePercent * 10 : 0;
            if (percent > 0)
                stars.eq(averageIndex).addClass("on").children("a").css("width", percent + "%");
        }
    }).remove();
};

jQuery.fn.disabledRating = function(){
    return this.each(function(){
        var div = jQuery("<div/>").attr({
            title: this.title,
            className: this.className
        }).insertAfter( this );

        jQuery(this).find("select option").each(function(){
            div.append( this.value == "0" ?
                "<div class=\"cancel\"><span>Ocena na 0</span></div>" :
                "<div class=\"disabledStar\"><span>" + this.value + "</span></div>" );
        });

        var averageRating = this.title.split(/:\s*/)[1].split("."),
            url = this.action,
            averageIndex = averageRating[0],
            averagePercent = averageRating[1];

        // hover events and focus events added
        var stars = div.find("div.disabledStar")
            .mouseover(drainFill).focus(drainFill)
            .mouseout(drainReset).blur(drainReset)
            .click(click);

        // cancel button events
        div.find("div.cancel")
            .mouseover(drainAdd).focus(drainAdd)
            .mouseout(resetRemove).blur(resetRemove)
            .click(click);

        reset();

        function drainFill(){ drain(); fill(this); }
        function drainReset(){ drain(); reset(); }
        function resetRemove(){ reset(); jQuery(this).removeClass('disabledOn'); }
        function drainAdd(){ drain(); jQuery(this).addClass('disabledOn'); }

        function click(){
            return false;
        }

        // fill to the current mouse position.
        function fill( elem ){
        }
    
        // drain all the stars.
        function drain(){
        }

        // Reset the stars to the default index.
        function reset(){
            stars.lt(averageIndex).addClass("disabledOn");

            var percent = averagePercent ? averagePercent * 10 : 0;
            if (percent > 0)
                stars.eq(averageIndex).addClass("disabledOn").children("span").css("width", percent + "%");
        }
    }).remove();
};

// fix ie6 background flicker problem.
if ( jQuery.browser.msie == true )
    document.execCommand('BackgroundImageCache', false, true);	
	