function selectLanguage(lang){window.location='/doUpdateLanguage?lang='+lang+'&redirectUrl='+window.location;}
function selectCurrency(currency){window.location='/doUpdateCurrency?isoCurrency='+currency+'&redirectUrl='+window.location;}
var loginPopupForm=new ValidatedForm();function sendLoginPopup(){if(loginPopupForm.validateForm()){var email=getDialogFieldValue(loginPopupDialog,'email');var password=getDialogFieldValue(loginPopupDialog,'password');var hashedPassword=MD5(password);var rememberMe=isDialogCheckBoxChecked(loginPopupDialog,'rememberme');$.ajax({cache:false,url:'/ajax/ajaxLogin',type:'post',dataType:'json',data:{email:email,hashedPassword:hashedPassword,rememberMe:rememberMe},success:loginPopupResult});}}
function loginPopupResult(json){if(json.status=='success'){window.location=window.location;}else{loginPopupForm.showError("#"+json.errorField,json.errorMessage);showLoginPopupErrorDialog(json.popupErrorTitle,json.popupErrorMessage);}}
var loginPopupDialog;function createLoginPopupDialog(){loginPopupDialog=createDialogWidth(560);setTitleToDialog(loginPopupDialog,loginPopupTitleText);addTextFieldToDialog(loginPopupDialog,"email",loginPopupEmailText,'');addPasswordFieldToDialog(loginPopupDialog,"password",loginPopupPasswordText,'');var p=getDialogField(loginPopupDialog,'password');p.after('<span style="font-size:11px;"><a rel="nofollow" href="/forgotpassword" style="padding: 4px;">'+loginPopupForgotPasswordText+'</a></span>');addCheckBoxToDialog(loginPopupDialog,"rememberme",loginPopupRememberMeText,false);addHtmlFieldToDialog(loginPopupDialog,'createaccount','<a rel="nofollow" href="/createaccount">'+loginPopupCreateAccountText+'</a>','');setDialogOKCallback(loginPopupDialog,function(){sendLoginPopup();});}
function showLoginPopupDialog(){showDialog(loginPopupDialog,null,null);setDialogFieldValue(loginPopupDialog,'password','');loginPopupForm.setFocus();var savedEmailB64=$.cookie('authenticationEmail'+cookieSuffix);if(savedEmailB64){var savedEmail=Base64.decode(savedEmailB64);setDialogFieldValue(loginPopupDialog,'email',savedEmail);if(savedEmail.length>0){setFocusOnField(loginPopupDialog,'password');}}else{setDialogFieldValue(loginPopupDialog,'email','');}}
function showLoginPopupErrorDialog(title,message){showMessageDialogOKCallback(title,message,function(){showLoginPopupDialog();loginPopupForm.setFocusFirstError();});}
$(function(){createLoginPopupDialog();loginPopupForm.registerField('#'+getDialogFieldId(loginPopupDialog,'email'),'');loginPopupForm.registerField('#'+getDialogFieldId(loginPopupDialog,'password'),'');$('.loginButton').live('click',function(){showLoginPopupDialog();});$('#logOutButton').live('click',function(){sendLogout();});function sendLogout(){$.ajax({cache:false,url:'/ajax/ajaxLogout',type:'post',dataType:'json',data:{},success:logoutResult});}
function logoutResult(json){if(json.status=='success'){window.location=window.location;}}
$('.currencyButton').hover(function(){$(this).addClass("currencyButtonHi");},function(){$(this).removeClass("currencyButtonHi");});$('.languageButton').hover(function(){$(this).addClass("languageButtonHi");},function(){$(this).removeClass("languageButtonHi");});$('.buttonMenu').hover(function(){$(this).addClass("highlighted");},function(){$(this).removeClass("highlighted");});$('.buttonMarked').hover(function(){$(this).addClass("highlighted");},function(){$(this).removeClass("highlighted");});$('.buttonUnmarked').hover(function(){$(this).addClass("highlighted");},function(){$(this).removeClass("highlighted");});$('body').resize(adjustTopMenuPos);function adjustTopMenuPos(){var topMenuBox=$('#topMenuBox');if(topMenuBox.length>0){var topNavModLeft=topMenuBox.offset().left;var topNavModRight=topNavModLeft+topMenuBox.innerWidth();$("#topMenuBox .buttonMenu").each(function(){var position=$(this).offset();var root=$(this);$(this).children('ul').each(function(){var sub=$(this);root.hover(function(){sub.show();},function(){sub.hide();});var subPosition=sub.offset();subPosition.left=position.left;subPosition.top=position.top+root.outerHeight();if(subPosition.left+sub.outerWidth()>topNavModRight){subPosition.left=topNavModRight-sub.outerWidth();}
var w=$(this).width();$(this).css(subPosition);$(this).width(w);});});}}
function adjustTopMenuWidth(){$("#topMenuBox .buttonMenu").children().each(function(){$(this).children().each(function(){if($(this).is('ul')){var subWidth=$(this).outerWidth();$(this).children().each(function(){if($(this).is('li')){$(this).children().each(function(){if($(this).is('a')){var paddingLeft=parseInt($(this).css("padding-left"),10);$(this).width(subWidth-paddingLeft);}});}});}});});}
adjustTopMenuPos();adjustTopMenuWidth();});
function RequestedPrice(p,q){this.productId=p;this.quantity=q;}
function sendGetProductPrice(){var productIds=new Array();var quantities=new Array();$(".productUnitSellPrice").each(function(){var id=$(this).attr('id');var productId=parseProductId(id);var quantity=parseQuantity(id);productIds.push(productId);quantities.push(quantity);});var productIdArray=createAjaxArray(productIds);var quantityArray=createAjaxArray(quantities);$.ajax({cache:false,url:'/ajax/ajaxGetProductPrice',type:'post',dataType:'json',data:{productIdArray:productIdArray,quantityArray:quantityArray},success:getProductPriceResult});}
function getProductPriceResult(json){var n=json.priceStrings.length;for(var i=0;i<n;++i){var productId=json.productIds[i];var quantity=json.quantities[i];var priceString=json.priceStrings[i];var buyPriceString=json.buyPriceStrings[i];var gramPriceString=json.gramPriceStrings[i];var spreadString=json.spreadStrings[i];var spotString=json.spotStrings[i];$('#productId'+productId+'_quantity'+quantity+'_').html(priceString);$('#details_productId'+productId+'_quantity'+quantity+'_').html(priceString);if($('#buyProductPrice_productId'+productId+'_').length>0){$('#buyProductPrice_productId'+productId+'_').html(buyPriceString);}
$('#gramPriceString'+productId).html(gramPriceString);$('#spreadString'+productId).html(spreadString);if(spotString.length>0){$('#spotString'+productId).html('<a href="/price_difference">'+spotString+'</a>');}else{$('#spotString'+productId).html('');}}}
$(document).ready(function(){registerShoppingCartUpdatedCallback(function(){sendGetProductPrice();});$('.addToCartButton').live('click',function(){var id=$(this).attr('id');var productId=parseProductId(id);var quantityString=$('#quantity'+productId).val();var quantity=parseInt(quantityString,10);if(isNaN(quantity)){quantity=1;}
addProductToCart(productId,quantity);});});
function sendSetShippingCountry(shippingCountry){$.ajax({cache:false,url:'/ajax/ajaxSetShippingCountry',type:'post',dataType:'json',data:{shippingCountry:shippingCountry},success:updateShippingCountryResult});}
function sendGetShippingCountry(){$.ajax({cache:false,url:'/ajax/ajaxGetShippingCountry',type:'post',dataType:'json',data:{},success:updateShippingCountryResult});}
function getShippingCountry(){return $.cookie("shippingCountry"+cookieSuffix);}
function setShippingCountry(shippingCountry){$.cookie("shippingCountry"+cookieSuffix,shippingCountry,{path:'/',expires:30});}
var notifyShippingCountryUpdatedCallbacks=new Array(0);function notifyShippingCountryUpdate(shippingCountry){var i=0;for(i=0;i<notifyShippingCountryUpdatedCallbacks.length;i++)
{notifyShippingCountryUpdatedCallbacks[i](shippingCountry);}}
function registerShippingCountryUpdatedCallback(callback){notifyShippingCountryUpdatedCallbacks.push(callback);}
function updateShippingCountryResult(json){setShippingCountry(json.shippingCountry);notifyShippingCountryUpdate(json.shippingCountry);}
function topShippingCountryChanged(countryCode,countryName){$(".shippingCountry").val(countryCode);$('#topShippingCountryName').html(countryName);sendSetShippingCountry(countryCode);}
$(document).ready(function(){if(typeof defaultShippingCountry!='undefined'){$('.shippingCountry').val(defaultShippingCountry);$('#topShippingCountry').val(defaultShippingCountry);setShippingCountry(defaultShippingCountry);$('.shippingCountry').change(function(){var selectedIndex=$(this).attr('selectedIndex');$(".shippingCountry").each(function(intIndex){if($(this).attr('selectedIndex')!=selectedIndex){$(this).attr('selectedIndex',selectedIndex);}});var countryName=$(this).find("option:selected").text();$('#topShippingCountryName').html(countryName);var shippingCountry=$(this).val();sendSetShippingCountry(shippingCountry);});}});
var lastShoppingCartRequestId=0;function getNewShoppingCartRequestId(){lastShoppingCartRequestId++;return lastShoppingCartRequestId;}
function getLastShoppingCartRequestId(){return lastShoppingCartRequestId;}
function addProductToCart(productId,quantity){var requestId=getNewShoppingCartRequestId();$.ajax({cache:false,url:'/ajax/ajaxAddToShoppingCart',type:'post',dataType:'json',data:{requestId:requestId,productId:productId,quantity:quantity},success:handleShoppingCartResult});var addToCartDontShowCookie=$.cookie('addToCartDontShow'+cookieSuffix);if(addToCartDontShowCookie==null||addToCartDontShowCookie!='true'){showAddToCartDialog();}
startShowShoppingCartAnimation();};function updateShoppingCartQuantity(productId,quantity,requestId){$.ajax({cache:false,url:'/ajax/ajaxUpdateShoppingCartQuantity',type:'post',dataType:'json',data:{requestId:requestId,productId:productId,quantity:quantity},success:handleShoppingCartResult});}
function removeShoppingCartEntry(productId){var requestId=getNewShoppingCartRequestId();$.ajax({cache:false,url:'/ajax/ajaxRemoveShoppingCartEntry',type:'post',dataType:'json',data:{requestId:requestId,productId:productId},success:handleShoppingCartResult});}
function refreshShoppingCart(){var requestId=getNewShoppingCartRequestId();$.ajax({cache:false,url:'/ajax/ajaxRefreshShoppingCart',type:'post',dataType:'json',data:{requestId:requestId},success:handleShoppingCartResult});}
function removeInvalid(tbody,json){var n=json.productIds.length;function existsProductId(pid){for(var k=0;k<n;++k){if(pid==json.productIds[k]){return true;}}
return false;}
tbody.children('tr').each(function(){if($(this).is('.shoppingCartRow')){var childId=$(this).attr('id');var pid=parseProductId(childId);if(!existsProductId(pid)){$(this).remove();}}});}
function updateExisting(tbody,prefix,json,updatedIndexes,isCheckout){var n=json.productIds.length;function getIndex(pid){for(var k=0;k<n;++k){if(pid==json.productIds[k]){return k;}}
return-1;}
tbody.children('tr').each(function(){if($(this).is('.shoppingCartRow')){var childId=$(this).attr('id');var pid=parseProductId(childId);var idx=getIndex(pid);updateShoppingCartRow(prefix,pid,json.notes[idx],json.quantities[idx],json.unitPriceStrings[idx],json.totalPriceStrings[idx],isCheckout,json.quantityChanged[idx]);updatedIndexes[idx]=true;}});}
function addMissing(tbody,prefix,json,updatedIndexes,isCheckout){var n=json.productIds.length;for(var i=0;i<n;++i){if(!updatedIndexes[i]){var productId=json.productIds[i];var s=createShoppingCartRow(tbody,prefix,productId,json.productUrlName[i],json.quantities[i],json.titles[i],json.notes[i],json.imageIds[i],json.vmb[i],json.unitPriceStrings[i],json.totalPriceStrings[i],isCheckout);if(i==0){tbody.prepend(s);}else{$('#'+prefix+'ShoppingCartRow_productId'+json.productIds[i-1]+'_').after(s);}
$('#'+prefix+'RemoveCartEntry_productId'+productId+'_').click(function(){clickRemoveCartButton(this);return false;});$('#'+prefix+'ShoppingCartNote'+productId).tooltip({delay:0,showURL:false,bodyHandler:function(){return $('<p>'+json.notes[i]+'</p>');}});}}}
var shoppingCartEmpty=true;function updateShoppingCartEmpty(json){shoppingCartEmpty=true;var n=json.numEntries;for(var l=0;l<n;++l){if(json.quantities[l]>0){shoppingCartEmpty=false;}}}
function getShoppingCartEmpty(){return shoppingCartEmpty;}
function setShoppingCartEmpty(v){return shoppingCartEmpty=v;}
function handleShoppingCartResult(json){if(json.requestId==getLastShoppingCartRequestId()){updateShoppingCartEmpty(json);$('.shoppingCartRow').removeClass('firstRow');updateCart('shoppingCartTableBody','shoppingCartTable','shoppingCart',json,false);updateCart('checkoutShoppingCartTableBody','checkoutTable','checkout',json,true);$('.shoppingCartTotal').html(json.totalString);notifyShoppingCartUpdate();if(json.errorMessage.length>0){showMessageDialog(json.errorTitle,json.errorMessage);}}}
function updateCart(bodyName,tableName,prefix,json,isCheckout){var tbody=$('#'+bodyName);if(tbody.length==0){var table=$('#'+tableName);if(table.length==0){return;}
tbody=$('<tbody id="'+bodyName+'" ></tbody>');table.append(tbody);}
var n=json.numEntries;var updatedIndexes=new Array();for(var l=0;l<n;++l){updatedIndexes[l]=false;}
removeInvalid(tbody,json);updateExisting(tbody,prefix,json,updatedIndexes,isCheckout);addMissing(tbody,prefix,json,updatedIndexes,isCheckout);var c=tbody.children('tr');if(c.length==0){tbody.remove();}else{c.first().addClass('firstRow');}}
function createShoppingCartRow(tbody,prefix,productId,productUrlName,quantity,title,note,imageId,vmb,unitPrice,totalPrice,isCheckout){var noteString="";if(isCheckout){if(note.length>0){noteString='<span class="informationBig shippingDateNote" id="'+prefix+'checkoutShoppingCartNote'+productId+'"></span>';}else{noteString='<span class="informationBig shippingDateNote invisible" id="'+prefix+'checkoutShoppingCartNote'+productId+'"></span>';}}
var vmbString="";if(vmb&&isCheckout){vmbString="*";}
return'<tr class="shoppingCartRow" id="'+prefix+'ShoppingCartRow_productId'+productId+'_">'+'<td class="quantityColumn"><input id="'+prefix+'ShoppingCartQuantity_productId'+productId+'_" type="text" maxlength="5" value="'+quantity+'" class="text ui-widget-content ui-corner-all valid-number cartQuantity cartQuantity'+productId+'"/></td>'+'<td class="imageColumn"><img src="/image/'+imageId+'" alt="'+title+'" /></td>'+'<td class="productColumn"><a href="/kopa/produkt/'+productUrlName+'">'+title+'</a>'+vmbString+noteString+'</td>'+'<td class="unitPriceColumn" id="'+prefix+'ShoppingCartUnitPrice'+productId+'">'+unitPrice+'</td>'+'<td class="priceColumn" id="'+prefix+'ShoppingCartTotalPrice'+productId+'">'+totalPrice+'</td>'+'<td class="removeColumn"><button id="'+prefix+'RemoveCartEntry_productId'+productId+'_" class="button60 blackButton removeCartButton">'+removeShoppingCartEntryText+'</button></td>'+'</tr>';}
function updateShoppingCartRow(prefix,productId,note,quantity,unitPrice,totalPrice,isCheckout,quantityChanged){if(quantityChanged){var quantityInput=$('#'+prefix+'ShoppingCartQuantity_productId'+productId+'_');if(quantityInput==null){return false;}
quantityInput.val(quantity);}
$('#'+prefix+'ShoppingCartUnitPrice'+productId).html(unitPrice);$('#'+prefix+'ShoppingCartTotalPrice'+productId).html(totalPrice);if(isCheckout){if(note.length>0){$('#'+prefix+'ShoppingCartNote'+productId).show();$('#'+prefix+'ShoppingCartNote'+productId).tooltip({delay:0,showURL:false,bodyHandler:function(){return $('<span>'+note+'</span>');}});}else{$('#'+prefix+'ShoppingCartNote'+productId).hide();}}
return true;}
function clickRemoveCartButton(input){var buttonId=$(input).attr('id');var productId=parseProductId(buttonId);removeShoppingCartEntry(productId);}
function quantityChanged(elementalId){var C=$('#'+elementalId);var requestId=getNewShoppingCartRequestId();var id=C.attr('id');var productId=parseProductId(id);var quantityString=C.val();var quantity=parseInt(quantityString);if(!isNaN(quantity)){$('.cartQuantity'+productId).each(function(){if(id!=$(this).attr('id')){$(this).val(quantity);}});updateShoppingCartQuantity(productId,quantity,requestId);}}
var notifyShoppingCartUpdatedCallbacks=new Array(0);function notifyShoppingCartUpdate(){var i=0;for(i=0;i<notifyShoppingCartUpdatedCallbacks.length;i++)
{notifyShoppingCartUpdatedCallbacks[i]();}}
function registerShoppingCartUpdatedCallback(callback){notifyShoppingCartUpdatedCallbacks.push(callback);}
var isShoppingCartShowing=false;var addToCartDialog;function createAddToCartDialog(){addToCartDialog=createDialog();setTitleToDialog(addToCartDialog,shoppingCartAddToCartDialogTitle);addMessageDialog(addToCartDialog,shoppingCartAddToCartDialogMessage);addCheckBoxLeftToDialog(addToCartDialog,'dontshowagain',shoppingCartAddToCartDialogCheckBoxText,false);setDialogOKCallback(addToCartDialog,function(){if(isDialogCheckBoxChecked(addToCartDialog,'dontshowagain')){$.cookie('addToCartDontShow'+cookieSuffix,'true');}});}
function showAddToCartDialog(){showDialog(addToCartDialog,null,null);}
var showShoppingCartAnimation=null;function startShowShoppingCartAnimation(){if(showShoppingCartAnimation==null){showShoppingCartAnimation=setInterval(function(){if($('#toggleShoppingCartButton').is('.marked')){$('#toggleShoppingCartButton').removeClass('marked');}else{$('#toggleShoppingCartButton').addClass('marked');}},1000);}}
function stopShowShoppingCartAnimation(){if(showShoppingCartAnimation!=null){clearInterval(showShoppingCartAnimation);showShoppingCartAnimation=null;$('#toggleShoppingCartButton').removeClass('marked');}}
var shoppingCartQuantityTimers=new Array();$(document).ready(function(){$('.addToCartButton160').hover(function(){$(this).addClass("addToCartButton160hi");},function(){$(this).removeClass("addToCartButton160hi");}).mousedown(function(){$(this).addClass("addToCartButton160pr");}).mouseup(function(){$(this).removeClass("addToCartButton160pr");});createAddToCartDialog();registerShippingCountryUpdatedCallback(function(){refreshShoppingCart();});$(this).click(function(){if($('#shoppingCartBox').is(':visible'))
hideShoppingCart();});$('#shoppingCart').click(function(e){e.stopPropagation();});function showShoppingCart(){var options={direction:"up"};$("#shoppingCartBox").show();$('#toggleShoppingCartButton span').html(hideShoppingCartText);isShoppingCartShowing=true;};function hideShoppingCart(){var options={direction:"up"};$("#shoppingCartBox").hide();$('#toggleShoppingCartButton span').html(showShoppingCartText);isShoppingCartShowing=false;};function showShoppingCartCallback(){};function hideShoppingCartCallback(){};$('#toggleShoppingCartButton').click(function(){stopShowShoppingCartAnimation();if(!isShoppingCartShowing){showShoppingCart();}else{hideShoppingCart();}});$('.removeCartButton').click(function(){clickRemoveCartButton(this);return false;});$('.cartQuantity').live('keyup',function(event){if(event.keyCode<37||event.keyCode>40){var elementalId=$(this).attr('id');if(elementalId in shoppingCartQuantityTimers){clearTimeout(shoppingCartQuantityTimers[elementalId]);}
shoppingCartQuantityTimers[elementalId]=setTimeout("quantityChanged('"+elementalId+"');",200);}});$('.cartQuantity').live('keypress',function(e){return(e.which!=8&&e.which!=0&&(e.which<48||e.which>57))?false:true;});function adjustShoppingCartPos(){var base=$('#shoppingCartBar');var baseOffset=base.offset();if(baseOffset!=null){var baseRight=baseOffset.left+base.outerWidth();var box=$('#shoppingCartBox');var boxLeft=baseRight-box.outerWidth();box.css('left',boxLeft);}}
$('body').resize(adjustShoppingCartPos);adjustShoppingCartPos();});
$(document).ready(function(){$('input.valid-number').bind('keypress',function(e){return(e.which!=8&&e.which!=0&&(e.which<48||e.which>57))?false:true;});$('input.valid-number').bind('cut copy paste',function(e){e.preventDefault();});$('input.valid-decimal-number').bind('keypress',function(e){return(e.which!=8&&e.which!=0&&e.which!=44&&e.which!=46&&(e.which<48||e.which>57))?false:true;});$('input.valid-letters').bind('keypress',function(e){if(e.which==0||e.which==8){return true;}
if(e.which>=65&&e.which<=90){return true;}
if(e.which>=97&&e.which<=122){return true;}
return false;});$('input.urlname').bind('keypress',function(e){if(e.which==0||e.which==8){return true;}
if(e.which>=48&&e.which<=57){return true;}
if(e.which>=65&&e.which<=90){return true;}
if(e.which>=97&&e.which<=122){return true;}
if(e.which==32){return true;}
if(e.which==45){return true;}
if(e.which==95){return true;}
return false;});$('.button180').live('mouseover',function(){$(this).addClass("button180hi");}).live('mouseout',function(){$(this).removeClass("button180hi");}).live('mousedown',function(){$(this).addClass("button180pr");}).live('mouseup',function(){$(this).removeClass("button180pr");});$('.button150').live('mouseover',function(){$(this).addClass("button150hi");}).live('mouseout',function(){$(this).removeClass("button150hi");}).live('mousedown',function(){$(this).addClass("button150pr");}).live('mouseup',function(){$(this).removeClass("button150pr");});$('.button80').live('mouseover',function(){$(this).addClass("button80hi");}).live('mouseout',function(){$(this).removeClass("button80hi");}).live('mousedown',function(){$(this).addClass("button80pr");}).live('mouseup',function(){$(this).removeClass("button80pr");});$('.button60').live('mouseover',function(){$(this).addClass("button60hi");}).live('mouseout',function(){$(this).removeClass("button60hi");}).live('mousedown',function(){$(this).addClass("button60pr");}).live('mouseup',function(){$(this).removeClass("button60pr");});});function Field(Cname,C,F,V,defaultString){this.Cname=Cname;this.C=C;this.F=F;this.V=V;this.defaultString=defaultString;this.enabled=true;this.error=false;this.validateField=function(){if(!this.enabled){return true;}
if(this.F==null){return true;}else{return this.F(this.C);}};this.setFocus=function(){this.C.focus();};this.showError=function(errorMessage){V.html('<img src="/static/partners/libertysilver/images/common/form_warning.gif" title="'+errorMessage+'" alt="'+errorMessage+'" />');this.error=true;};this.showDefault=function(){V.html(defaultString);this.error=false;};this.disable=function(){this.enabled=false;};this.enable=function(){this.enabled=true;};}
function getVname(C){return C.attr('id')+'_validation';}
function ValidatedForm(){this.fields=new Array(0);this.registerField=function(Cname,defaultString){var C=$(Cname);var Vname=getVname(C);C.after('<span class="validation" id="'+Vname+'"></span>');var V=$('#'+Vname);var fi=new Field(Cname,C,null,V,defaultString);this.add(fi);fi.showDefault();return fi;};this.add=function(fi){var idx=this.fields.length;this.fields[idx]=fi;};this.optional=function(Cname){var fi=this.registerField(Cname,'');var C=fi.C;var F=function(I){fi.showDefault();return true;};C.blur(F);fi.F=F;return fi;};this.requiredString=function(Cname,msg){var fi=this.registerField(Cname,'*');var C=fi.C;var F=function(I){if(C.val().length>0){fi.showDefault();return true;}else{fi.showError(msg);return false;}};C.blur(F);fi.F=F;return fi;};this.requiredStringLength=function(Cname,minLength,msg,lengthMessage){var fi=this.registerField(Cname,'*');var C=fi.C;var F=function(I){if(C.val().length>=minLength){fi.showDefault();return true;}else if(C.val().length==0){fi.showError(msg);return false;}else{fi.showError(lengthMessage);return false;}};C.blur(F);fi.F=F;return fi;};this.requiredMatch=function(Cname,Mname,msg,matchMsg){var fi=this.registerField(Cname,'*');var C=fi.C;var M=$(Mname);var F=function(I){if(C.val()==""){fi.showError(msg);return false;}else if(C.val()!=M.val()){fi.showError(matchMsg);return false;}else{fi.showDefault();return true;}};C.blur(F);fi.F=F;return fi;};this.requiredEmail=function(Cname,msg,emailMsg){var fi=this.registerField(Cname,'*');var C=fi.C;var EmailRegExp=/.+@.+\..+/;var F=function(I){if(C.val()==""){fi.showError(msg);return false;}else if(!C.val().match(EmailRegExp)){fi.showError(emailMsg);return false;}else{fi.showDefault();return true;}};C.blur(F);fi.F=F;return fi;};this.validateForm=function(){var firstFailed=null;for(var i=0;i<this.fields.length;i++){var fi=this.fields[i];if(!fi.validateField()){if(firstFailed==null){firstFailed=fi;}}}
if(firstFailed!=null){firstFailed.setFocus();}else{return true;}};this.setFocus=function(){if(this.fields.length>0){var fi=this.fields[0];fi.setFocus();}};this.getFirstError=function(){for(var i=0;i<this.fields.length;i++){var fi=this.fields[i];if(fi.error){return fi;}}
return null;};this.setFocusFirstError=function(){for(var i=0;i<this.fields.length;i++){var fi=this.fields[i];if(fi.error){fi.setFocus();return;}}};this.showError=function(fieldName,errorMessage){for(var i=0;i<this.fields.length;i++){var fi=this.fields[i];if(fi.Cname==fieldName){fi.showError(errorMessage);fi.setFocus();}else{fi.showDefault();}}};}
function createUpdateButton(id){document.write('<input type="image" id="'+id+'" style="margin: 0 30px;" src="/static/partners/libertysilver/images/common/button_ok.gif" value="update" />');}
function createCancelButton(id){document.write('<input type="image" id="'+id+'" style="margin: 0 30px;" src="/static/partners/libertysilver/images/common/button_cancel.gif" value="cancel" />');}
function createAddButtonWithText(id,text){createButton(id,text);}
function createAddButton(id){document.write('<input type="image" id="'+id+'" style="margin: 0 30px;" src="/static/partners/libertysilver/images/common/button_add.gif" value="add" />');}
function createRefreshButton(id){document.write('<div id="'+id+'" class="button60 blackButton">Refresh</div>');}
function createButton(id,text){var type=text.length<5?'button60':(text.length<10?'button80':'button150');document.write('<div id="'+id+'" class="'+type+' blackButton">'+text+'</div>');}
function createButtonLink(id,text,url){var type=text.length<5?'button60':(text.length<10?'button80':'button150');document.write('<a id="'+id+'" href="'+url+'" class="'+type+' blackButton">'+text+'</a>');}
function appendDialogOKButtonString(e,id){e.append('<img src="/static/partners/libertysilver/images/common/button_ok.gif" class="jqmClose jqmBottomButton" id="'+id+'" style="width: auto; height: auto; float: none;" value="ok" />');}
function appendDialogCancelButtonString(e,id){e.append('<img src="/static/partners/libertysilver/images/common/button_cancel.gif" class="jqmClose jqmBottomButton" id="'+id+'" style="width: auto; height: auto; float: none;" value="cancel" />');}
