//scripts.js

function bindSetSizeLinks(){$(".set-cloth-sizes a, .set-favourite-colours a").bind("click",function(){var b=$(this).attr("rel");var c=$(this).attr("title");$(this).attr("href","#"+$(this).attr("rel"));$.ajax({url:"/go/_users/editsize.php",global:false,type:"POST",data:({"type":b,"value":c}),dataType:"html",success:function(a){$("#size-dialog").remove();$("body").append(a);$("#size-dialog").dialog({bgiframe:true,modal:true,buttons:{Ok:function(){$(this).dialog('close')}}})}})})}

function avatarCrop(){var c=$("img#avatar-crop");if(c!=null){c.imgAreaSelect({handles:true,aspectRatio:"1:1",x1:0,y1:0,x2:48,y2:48,minWidth:48,minHeight:48,instance:true,onSelectEnd:function(a,b){$("#pos_x").val(b.x1);$("#pos_y").val(b.y1);$("#pos_ex").val(b.width)}});return c}}

function trendListInit(){$(document).ready(function(){if($("#trend-deleted")!=null&&$("#trend-not-deleted")!=null){$("#trend-deleted, #trend-not-deleted").dialog({bgiframe:true,resizable:false,height:50,modal:true,autoOpen:false,buttons:{'Ok':function(){$(this).dialog('close')}}})}})}

function deleteTrend(b){$("#tid").attr("rel",b);$("#del-trend-confirmation").dialog({bgiframe:true,resizable:false,height:40,modal:true,autoOpen:true,buttons:{'Tak, skasuj trend':function(){$(this).dialog('destroy');$.post("/go/_users/trends.php",{action:"delete",tid:$("#tid").attr("rel")},function(a){if(a=="OK"){$("#trend-deleted").dialog("open");$("#t-"+$("#tid").attr("rel")).addClass("strike")}else{$("#trend-not-deleted").dialog("open")}});return false},Anuluj:function(){$(this).dialog('destroy');return false}}})}

function updateTips(t) {$("#validateTips").text(t).effect("highlight",{},1500);}

function checkLength(o,n,a,b){if(o.val().length>b||o.val().length<a){o.addClass('ui-state-error');updateTips("Długość pola musi się zawierać między "+a+" a "+b+" znaków.");return false}else{return true}}

function checkRegexp(o,a,n){if(!(a.test(o.val()))){o.addClass('ui-state-error');updateTips(n);return false}else{return true}}

function recommend(c){if(c){var d=$("#friend_email"),message=$("#messageForm"),sender_info=$("#sender_info"),your_email=$("#your_email"),allFields=$([]).add(d).add(sender_info).add(your_email),tips=$("#validateTips");$("#recommend-product").dialog({bgiframe:true,autoOpen:false,width:460,height:430,modal:true,buttons:{'Poleć produkt':function(){var b=true;allFields.removeClass('ui-state-error');b=b&&checkLength(d,"friend_email",6,92);b=b&&checkLength(sender_info,"sender_info",5,128);b=b&&checkLength(your_email,"your_email",6,92);b=b&&checkRegexp(d,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"np. info@avaro.pl");b=b&&checkRegexp(your_email,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"np. info@avaro.pl");if(b){$.post("/plugins/_recommend/index.php",{id:$("#hidden_id").val(),product:$("#hidden_product").val(),shop:$("#hidden_shop").val(),"friend_email":d.val(),"message":message.val(),"sender_info":sender_info.val(),"your_email":your_email.val(),isAjax:true},function(a){if(a=="OK"){$("#recommend-dialogs-ok").dialog("open")}else{$("#recommend-dialogs-error").dialog("open")}});$(this).dialog('close')}},'Anuluj':function(){$(this).dialog('close')}},close:function(){allFields.val('').removeClass('ui-state-error')}});$("#recommend-dialogs div").dialog({bgiframe:true,autoOpen:false,height:100,modal:true,buttons:{'OK':function(){$(this).dialog('close')}}})}else{$("#recommend-product").dialog("open");return false}}

function show_video(c){ if (c) { $(document).ready(function(){ $("#product-video").dialog({ bgiframe:true, autoOpen:false, modal:true, resizable:false, width:730, height:440 }); }); }else{ $("#product-video").dialog("open"); return false } }

function addReview(b){if(b==true && $('#open-add-review').attr('href')!=null){var c=$('#add-review');var d=$('#after-review-submit');c.load($('#open-add-review').attr('href')+'&ajax=true');d.dialog({bgiframe:true,autoOpen:false,resizable:false,modal:true,width:480,height:150,buttons:{'Zamknij':function(){$(this).dialog('close')}}});c.dialog({bgiframe:true,autoOpen:false,resizable:false,width:480,height:410,modal:true,buttons:{'Dodaj recenzję':function(){$(this).dialog('close');$('#form-add-review').iframer({onComplete:function(a){d.text('');d.append(a);d.dialog('open')}});$('#form-add-review').attr('action',$('#form-add-review').attr('action')+'&ajax=true');$('#form-add-review').submit()},'Anuluj':function(){$(this).dialog('close')}}});$('#open-add-review').click(function(){c.dialog('open');$('#rating').val($('#mark-select').val());return false})}else{$('#add-review').dialog('open');$('#rating').val($('#mark-select').val());return false}}

function addReview2(b, pId, pName){
	if(b==true && pId != null && pName != null){
		var c=$('#add-review');
		var d=$('#after-review-submit');
		c.load('/plugins/_reviews/add.php?id=' + pId + '&user_id=' + pId + '&product=' + pName + '&ajax=true');
		d.dialog({
			bgiframe: true,
			autoOpen: false,
			resizable: false,
			modal: true,
			width: 480,
			height: 150,
			buttons: {
				'Zamknij': function(){
					$(this).dialog('close')
				}
			}
		});
		c.dialog({
			bgiframe: true,
			autoOpen: false,
			resizable: false,
			width: 480,
			height: 410,
			modal: true,
			buttons: {
				'Dodaj recenzję': function(){
					$(this).dialog('close');
					$('#form-add-review').iframer({
						onComplete: function(a){
							d.text('');
							d.append(a);
							d.dialog('open')
						}
					});
					$('#form-add-review').attr('action',$('#form-add-review').attr('action')+'&ajax=true');
					$('#form-add-review').submit()
				},
				'Anuluj': function(){
					$(this).dialog('close')
				}
			}
		});
		$('#markSelectForm').submit(
			function(){
				$('#rating').val($('#mark-select').val());
				c.dialog('open');
				return false;
			}
		)
	} else {
		$('#rating').val($('#mark-select').val());
		$('#add-review').dialog('open');
		return false;
	}
}

function loginFirst(b){
	if(b==true){
		var d=$('#login-first');
		d.dialog({
			bgiframe: true,
			autoOpen: false,
			resizable: false,
			modal: true,
			width: 480,
			height: 150,
			buttons: {
				'Zamknij': function(){
					$(this).dialog('close')
				}
			}
		});
		$('#markSelectForm').submit(
			function(){
				d.dialog('open');
				return false;
			}
		)
	} else {
		$('#login-first').dialog('open');
		return false;
	}
}

//iFramer

(function($){$.fn.extend({iframer:function(b){b=$.extend({},{iframe:'iframer_iframe',returnType:'html',onComplete:function(){}},b);var c=$('<iframe name='+b.iframe+' id="'+b.iframe+'" width="0" height="0" frameborder="0" style="border: none; display: none; visibility: hidden;"></iframe>');$(this).append(c).attr('target',b.iframe).submit(function(){$('#'+b.iframe).load(function(){var a=$('#'+b.iframe).contents().find('body').html();if(b.returnType.toLowerCase()=='json')eval('data='+a);b.onComplete(a);$('#'+b.iframe).contents().find('body').html('');$('#'+b.iframe).unbind('load')});return true})}})})(jQuery);

//function.js

function loadInfoPages(){loadUserProfilePages($("#dialog"));}

function showHiddenDialogs(){$(".hidden-dialog").dialog({bgiframe:true,autoOpen:true,modal:true,stack:true,buttons:{Ok:function(){$(this).dialog('close')}}})}

function loadUserProfilePages(a){if($("#upload-avatar").length>0){a.children("#upload-avatar").load("/go/_users/upload-avatar.php?ajax=true")}if($("#show-size-tables").length>0){a.children("#show-size-tables").load("/plugins/_zstrony/ #tabbed-pages",null,function(){$("#tabbed-pages").tabs({selected:1});bindSetSizeLinks()})}}

function openSizesAndMeasure(a){var b=$("#"+a);b.dialog({bgiframe:true,autoOpen:false,modal:true,title:b.attr("title"),height:b.attr("height"),width:b.attr("width"),stack:false,resizable:false});b.load("/plugins/_zstrony/")}

function bindSliders(){$("a[rel=slide-div]").bind("click",function(){var a=$("#"+$(this).attr("name"));var b=$(this);a.slideToggle(600,function(){if(a.is(":visible")){b.children("span.visible").show();b.children("span.hidden").hide()}else{b.children("span.visible").hide();b.children("span.hidden").show()}})})}

function askforproduct(c){var a=$('#ask-for-product');if(c){var b=$('#r-sender_info'),c=$('#r-your_email'),d=$('#r-message'),e=$('#ask-success'),f=$('#ask-failure');e.dialog('option','buttons',{'Zamknij':function(){$(this).dialog("close")}});f.dialog('option','buttons',{'Zamknij':function(){$(this).dialog('close')}});a.dialog({bgiframe:true,autoOpen:false,width:460,height:390,modal:true,buttons:{'Wyślij zapytanie':function(){c.removeClass('ui-state-error');b.removeClass('ui-state-error');d.removeClass('ui-state-error');var g=true;g=g&&checkLength(d,'r-message',6,123456789);g=g&&checkLength(b,'r-sender_info',6,92);g=g&&checkRegexp(c,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"np. info@avaro.pl");if(g){$.post('/plugins/_info/mail.php',{'id':$('#r-id').val(),'product':$('#r-product').val(),'sender':b.val(),'mail':c.val(),'message':d.val(),'ask_product':true},function(a){if(a.indexOf('OK')==0){e.dialog('open')}else{f.dialog('open')}});$(this).dialog('close')}else{return false}},'Anuluj':function(){$(this).dialog('close')}}})}else{a.dialog('open')}}

