/*
 * Replace & validate form tags:
 * input checkbox, input radio, input text, input password,
 * input file, input password, select, textarea, acronym
 *
 * Copyright (c) 2010 Jiri Klir www.jklir.net
 * This is under GNU-GPL license
 *
 * @Version 1.0.1
 * @Author Jiri Klir
*/

var radioHeight = "17px";
var checkboxHeight = "18px";
var paddingLeft = "22px";
var paddingRight = "0";
var inputfileWidth = "87px";
var inputfileText = "Procházet...";
var inputtextSideWidth = "6px";
var inputtextHeight = "28px";
var inputtextPadding = "4px 3px 4px 1px";
var selectLeftWidth = "6px";
var selectArrowWidth = "27px";
var selectHeight = "28px";

;(function($){$.replaceForm=function(dom){if(dom=="")dom="body";$(dom).addClass("replaceform");replaceRadio(dom);replaceCheckbox(dom);replaceFile(dom);replaceText(dom);replaceSelect(dom);replaceTextarea(dom);replaceAcronym(dom);function replaceRadio(dom){$(dom+' label input:radio').parent().addClass("radioBg").css({"padding":"0 "+paddingRight+" 0 "+paddingLeft,"line-height":radioHeight,"height":radioHeight,"vertical-align":"middle"});$(dom+' input:radio:checked').parent().css("backgroundPosition","0 -"+radioHeight);$(dom+' label input:radio').parent().click(function(){$('input[name='+$(this).find("input:radio").attr("name")+']').parent().css("backgroundPosition","0 0");$(this).css("backgroundPosition","0 -"+radioHeight)});$(dom+' input:radio').hide();return true}function replaceCheckbox(dom){$(dom+' label input:checkbox').parent().addClass("checkboxBg").css({"padding":"0 "+paddingRight+" 0 "+paddingLeft,"line-height":checkboxHeight,"height":checkboxHeight,"vertical-align":"middle"});if($.browser.msie&&$.browser.version=="6.0"){$(dom+' label input:checkbox').parent().css({"marginTop":"2px","marginBottom":"1px"})}$(dom+' input:checkbox:checked').parent().css("backgroundPosition","0 -"+checkboxHeight);$(dom+' label input:checkbox').parent().click(function(){if($(this).find("input:checkbox").is(":checked")){$(this).css("backgroundPosition","0 -"+checkboxHeight)}else{$(this).css("backgroundPosition","0 0")}});$(dom+' label input:checkbox').parent().append('<span class="checkwrap"></span>');$(dom+' label input:checkbox').each(function(){$(this).appendTo($(this).parent().find(".checkwrap"))});return true}function replaceFile(dom){$(dom+' input:file').each(function(){var width=$(this).width();var height=inputtextHeight;var button=$('<span class="filebutton" style="width:'+inputfileWidth+';height:'+height+';display:inline;position:absolute;overflow:hidden;margin-left:5px;">');var filename=$('<input type="text" class="file" style="display:inline;width:'+width+'px;" disabled="disabled">').addClass($(this).attr("class"));$(this).css({"position":"absolute","height":height,"width":inputfileWidth,"display":"inline","cursor":"pointer","opacity":"0.0","z-index":"5"});$('<span class="filewrap"></span>').insertAfter($(this));$(this).appendTo($(this).next());$(this).before(filename);$(this).parent().append(button);$(this).appendTo($(this).next());$(this).parent().append('<span class="filetext" style="width:'+inputfileWidth+';line-height:'+height+';">'+inputfileText+'</span>');if($.browser.mozilla){if(/Win/.test(navigator.platform)){$(this).css("margin-left","-121px")}else{$(this).css("margin-left","-181px")}}else{$(this).css("margin-left",0)};if($.browser.msie){$(this).next().css({"margin-left":"5px"})}$(this).bind("change",function(){filename.val($(this).val())})});return true}function replaceText(dom){$(dom+' input:text, '+dom+' input:password').not(":file").each(function(){$(this).css({"border":"0 none","margin":"0","padding":inputtextPadding});var width=parseInt($(this).width())-(parseInt(inputtextSideWidth)*2);var padTop=parseInt($(this).css("paddingTop"));var padBot=parseInt($(this).css("paddingBottom"));var outwidth=$(this).outerWidth();var outheight=$(this).outerHeight();$(this).css({"width":width+"px","height":(parseInt(inputtextHeight)-padTop-padBot)+"px"});if($.browser.msie){$(this).css({"paddingTop":(padTop+2)+"px","paddingBottom":(padBot-2)+"px","width":(width+2)+"px"})}$('<span class="inputwrap" style="width:'+outwidth+'px;height:'+inputtextHeight+';"><span style="position:absolute;left:'+inputtextSideWidth+';width:'+(outwidth-(parseInt(inputtextSideWidth)*2))+'px;height:'+inputtextHeight+';"></span></span>').insertAfter($(this));$(this).appendTo($(this).next().find("span"));$('<span class="lft" style="width:'+inputtextSideWidth+';height:'+inputtextHeight+';"></span><span class="rght" style="width:'+inputtextSideWidth+';height:'+inputtextHeight+';"></span>').insertAfter($(this).parent())});return true}function replaceSelect(dom){var selectMidWidth=(parseInt(selectLeftWidth)-parseInt(selectArrowWidth));var selectMilWidth=(parseInt(selectLeftWidth)+parseInt(selectArrowWidth))-6;$(dom+' select').each(function(){var width=$(this).width()-selectMidWidth;var outwidth=$(this).outerWidth();var outheight=$(this).outerHeight();$('<span class="selectwrap" style="width:'+outwidth+'px;height:'+selectHeight+'px;"><ul style="width:'+outwidth+'px;margin-top:'+(parseInt(selectHeight)-2)+'px;"></ul><span class="selectmenu" style="margin-left:'+selectLeftWidth+';margin-right:'+selectArrowWidth+';width:'+(outwidth-selectMilWidth)+'px;height:'+selectHeight+';line-height:'+selectHeight+';float:left;color:'+($(this).css("color"))+';"></span><span class="lft" style="width:'+selectLeftWidth+';height:'+selectHeight+';margin-top:-'+selectHeight+';"></span><span class="rght" style="width:'+selectArrowWidth+';height:'+selectHeight+';margin-top:-'+selectHeight+';"></span></span>').insertAfter($(this));var aktualni=$(this).next();var aktualniul=aktualni.find("ul");var aktualniselmenu=aktualni.find(".selectmenu");var option="";$(this).find("option").each(function(){option+='<li><a href="javascript:void(0)">'+$(this).text()+'</a></li>'});$(option).appendTo(aktualniul);option="";if(aktualniul.height()>150){aktualniul.height("150px")}if($(this).find("option:selected")){aktualniselmenu.text($(this).find("option:selected").text())}else{aktualniselmenu.text($(this).find("option").eq(0).text())}$(this).next().find("li a").click(function(){aktualniselmenu.text($(this).text());aktualniul.hide();aktualni.prev().find("option").removeAttr("selected").eq($(this).parent().parent().children().index($(this).parent())).attr("selected","selected");return false});$(this).next().find("span").click(function(){$(".selectwrap").find('ul').not(aktualniul).hide();aktualniul.animate({"height":"toggle"},200);return false});if($.browser.msie&&($.browser.version=="6.0"||$.browser.version=="7.0")){aktualniul.css({"marginTop":"-2px","marginLeft":"-"+selectLeftWidth});if($.browser.version=="6.0"){aktualni.css("marginRight","-11px")}}});$('body').click(function(event){if(!$(event.target).closest('.selectwrap').length){$(".selectwrap ul").hide()}});$(dom+' select').hide();return true}function replaceTextarea(dom){$(dom+' textarea').each(function(){$(this).css({"background":"none","border":"0 none","margin":"0"});$('<span class="textareawrap"><span class="rfcorner rftl"></span><span class="rfcorner rftr"></span><span class="rfcorner rfbl"></span><span class="rfcorner rfbr"></span></span>').insertAfter($(this));$(this).appendTo($(this).next());if($.browser.msie){$(this).css({"position":"absolute","left":"0","top":"0"}).parent().css({"width":$(this).outerWidth(),"height":$(this).outerHeight()})}});return true}function replaceAcronym(dom){$(dom+' acronym').not(".error").each(function(){$(this).css({"border":"0 none","margin":"0 0 0 5px","outline":"none","height":$(this).parent().css("lineHeight")});if(!($.browser.msie&&($.browser.version=="6.0"||$.browser.version=="7.0"))){$(this).css({"marginBottom":"2px","height":$(this).height()-2+"px"})}$(this).hover(function(){title=$(this).attr("title");$(this).attr("title","");$('<span class="acronymwrap"><span class="arrow"></span>'+title+'</span>').insertAfter($(this));kor=(parseInt($(this).parent().height())/2)-(parseInt($(this).parent().css("fontSize"))*2)-1;if($(this).next().height()<=Math.round(parseFloat($(this).next().css("lineHeight")))){$(this).next().css({"marginTop":(kor+(parseInt($(this).parent().css("fontSize"))/2))+"px","width":"auto","white-space":"nowrap"}).find(".arrow").css("marginTop","-2px")}else{$(this).next().css("marginTop",kor+"px").find(".arrow").css("marginTop","5px")}},function(){$(this).attr("title",title).next().remove()})});return true}}})(jQuery);

var replaceFormValid = 0;

;(function($){$.fn.replaceFormValidate=function(errortext,method){var errortext=(errortext==null)?"":errortext;var method=(method==null)?"notEmpty":method;var thisel=this[0];var emailExp=/^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;var phoneExp=/^[ 0-9\.\+\/\-]{8,}$/;var pass;var ok=0;if(method=="force"){pass=false;ok=0}else if(method=="notEmpty"){if($(this).val().length>0){pass=true;ok+=1}}else if(method=="mail"){if($(this).val().match(emailExp)){pass=true;ok+=1}}else if(method=="shouldMail"){if($(this).val().length==0||$(this).val().match(emailExp)){pass=true;ok+=1}}else if(method=="phone"){if($(this).val().match(phoneExp)){pass=true;ok+=1}}else if(method=="checked"){if($(this).is(":checked")){pass=true;ok+=1}}if(pass!=true){if(thisel.nodeName.toLowerCase()=="input"){if($(this).attr("type")=="radio"){lastradioname=$(this).eq($(this).length-1);$('<label style="width:auto;margin:0;"><acronym class="error" title="'+errortext+'">&nbsp;</acronym></label>').insertAfter(lastradioname.parent());var acr=lastradioname.parent().next().find("acronym.error")}else if($(this).attr("type")=="file"){$('<label style="width:auto;margin:0;margin-left:'+($(this).parent().parent().children().find(".filetext").width()+5)+'px;"><acronym class="error" title="'+errortext+'">&nbsp;</acronym></label>').insertAfter($(this).parent().parent());var acr=$(this).parent().parent().next().find("acronym.error")}else{$('<label style="width:auto;margin:0;"><acronym class="error" title="'+errortext+'">&nbsp;</acronym></label>').insertAfter($(this).parent().parent());var acr=$(this).parent().parent().next().find("acronym.error")}}else if(thisel.nodeName.toLowerCase()=="select"){$('<label style="width:auto;margin:0;"><acronym class="error" title="'+errortext+'">&nbsp;</acronym></label>').insertAfter($(this).next());var acr=$(this).next().next().find("acronym.error")}else{$('<label style="width:auto;margin:0;vertical-align:top;"><acronym class="error" title="'+errortext+'">&nbsp;</acronym></label>').insertAfter($(this).parent());var acr=$(this).parent().next().find("acronym.error")}acr.css({"border":"0 none","margin":"0 0 0 5px","outline":"none","height":acr.parent().css("lineHeight")});if(!($.browser.msie&&($.browser.version=="6.0"||$.browser.version=="7.0"))){acr.css({"marginBottom":"2px","height":acr.height()-2+"px"})}acr.hover(function(){titleerr=$(this).attr("title");$(this).attr("title","");$('<span class="acronymwraperror"><span class="arrow"></span>'+titleerr+'</span>').insertAfter($(this));kor=(parseInt($(this).parent().height())/2)-(parseInt($(this).parent().css("fontSize"))*2)-1;if($(this).next().height()<=Math.round(parseFloat($(this).next().css("lineHeight")))){$(this).next().css({"marginTop":(kor+(parseInt($(this).parent().css("fontSize"))/2))+"px","width":"auto","white-space":"nowrap"}).find(".arrow").css("marginTop","-2px")}else{$(this).next().css("marginTop",kor+"px").find(".arrow").css("marginTop","5px")}},function(){$(this).attr("title",titleerr).next().remove()})}if(ok==1){return true}else{replaceFormValid+=1;return false}}})(jQuery);