/*! * Depends on jQuery JavaScript Library v1.6 */ /** * hideObj('seletor1', 'selector2', ...) */ function hideObj() { for (i =0 ; i < arguments.length; i++) { $(arguments[i]).addClass('hidden'); } } /** * showObj('seletor1', 'selector2', ...) */ function showObj() { for (i =0 ; i < arguments.length; i++) { $(arguments[i]).removeClass('hidden'); } } /** @param type default 'text' supported type refer to: http://docs.jquery.com/Selectors */ function getFormFieldValue(name, type) { var $field; if('radio'==type) { var $field = $("input:radio[name="+name+"][checked]"); if($field.length>0) return $field.val(); } else { $field = $(":input[name="+name+"]"); } if($field && $field.length)return $field.val(); else return ""; } //validate function isEmpty(value) { return /^[\s]*$/.test(value); } function isPositiveNumber(value) { return parseInt(value)>0; } function isPositiveFloat(value) { return parseFloat(value)>0; } /** only a-z and space is allow*/ function isBlankAlpha(value) { return /^[a-zA-Z\s]*$/.test(value); } /** only a-z,0-1,# and space is allow*/ function isAddress(value) { return /^[-().,#a-zA-Z0-9\s]*$/.test(value); } function isEmail(str){ var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; return filter.test(str); } function updateWarning(country, suffix, selectElem) { hideObj('#warning_'+suffix); $(':text').each(function(){this.disabled=false}); $(':radio').each(function(){this.disabled=false}); $(':button').each(function(){this.disabled=false}); $(':submit').each(function(){this.disabled=false}); $('select').each(function(){this.disabled=false}); if('Canada'==country || 'United States'==country || 'Virgin Islands (U.S.)'==country) { $("#warning_"+suffix+"> .emphasis").text("Citizens and residents of the "+country+" may not open trading accounts with FX|Clearing. We apologize for any inconvenience this may cause you."); showObj("#warning_"+suffix); $(':text').each(function(){this.disabled=true}); $(':radio').each(function(){this.disabled=true}); $(':button').each(function(){this.disabled=true}); $(':submit').each(function(){this.disabled=true}); $('select').not(selectElem).each(function(){this.disabled=true}); } } function syncAjaxResponse(url, params, method) { $.ajaxSetup({async:false}); var ajaxMethod = $.get; if('post'==method) ajaxMethod = $.post; var data = null; ajaxMethod(url, params, function(response){data = response;}); $.ajaxSetup({async:true}); //set back return data; } /** Display errors on displayBlock @errors array @tabId int @displayBlock string selector, default #errors-block */ function displayError(errors, tabId, displayBlock) { if(!displayBlock) displayBlock="#errors-block"; $(displayBlock).html(""); //clear error messages if(errors.length>0) { tabOn(tabId); //go to tab for(var i=0; i"+errors[i]+""); } } } /** Case insensitive @return '' if success, else return the supposed initials */ function checkInitials(firstName, lastName, initial) { if(!firstName)firstName = ''; if(!lastName)lastName = ''; if(!initial)initial = ''; i = firstName.charAt(0) + lastName.charAt(0); if(initial.toUpperCase() != i.toUpperCase()) { return i; } return ''; } function popup(url,id,width,height) { id = id||new Date().getTime(); width = width||800; height= height||600; var conf = "width="+width+",height="+height; window.open(url,id,conf); } function popUp(url) { day = new Date(); id = day.getTime(); eval("page" + id + " = window.open(url, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=800, height=600');"); } /** errors must be array */ function ulErrors(errors) { if(!errors || !errors.length)return ""; var ul = ""; return ul; } function changeCaptcha(containerId){ var url='/captcha/default/'+new Date().getTime(); $("#"+containerId+">img")[0].src=url; } function checkCaptcha(captcha) { var data = syncAjaxResponse('/fxccon/checkCaptcha/'+new Date().getTime(), {captcha_response: captcha}); return '1' == data; } function setTab(name,cursel,n){ for(i=1;i<=n;i++){ var menu=document.getElementById(name+i); var con=document.getElementById("con_"+name+"_"+i); menu.className=(i==cursel?"hover":""); con.style.display=(i==cursel?"block":"none"); } }