var cb={exp:"#mainNav,#comBox",expMax:".max",expMin:".min",expMinimize:".minimize",holdTime:10000,mouseOverTime:500,fadeInSpeed:"normal",fadeOutSpeedmax:2000,fadeOutSpeedmin:500,ccDefault:"49",TYPES:null,flashAvailable:true,modeTabExp:"#comBoxContent .flag li",modeExp:"#phoneMode,#smsMode,#phonebook",targetId:{phone:{a:"phoneA",b:"phoneB"},cc:{a:"ccA",b:"ccB",aSubmit:"ccASubmit",bSubmit:"ccBSubmit"},b:"targetB",callType:"callType",numberType:"numberType",country:{bSubmit:"countryBSubmit"}},triggerCallExp:"#btnCallnow",confirmBtnExp:"#btnConfirmB",activeFieldClass:"active",errorClass:"error",minInputLength:3,partyId:{a:"aParty",b:"bParty"},partySelExp:".partySelection",partySelEntryExp:"tbody > tr",formId:"frmCall",connDescExp:".connDesc",connModeExp:".connMode",countryExp:".country",typeExp:".type",countryListLinkId:"countryListLink",countryListId:"countryList",countryLinkExp:"li > a",keysListSelExpSelected:"selectionSelBox",keysListSelCurMouse:null,keysListSelPosition:0,keysListSelItemCount:2,keysListSelKeys:{up:38,down:40,enter:13,tab:9},keysLevel:window,partySelBoxOpen:false,partyFlagKeyUpChangeIe:false,init:function(){cb.handleKeysLevel();$(cb.modeTabExp+" a").click(function(e){$(cb.modeTabExp).removeClass(cb.activeFieldClass);$(this).parents(cb.modeTabExp).addClass(cb.activeFieldClass);$(cb.modeExp).hide();$($(this).attr("href")).show();e.preventDefault();if($(this).attr("href")=="#"+pb.contId){pb.loadContactData()}});$(cb.triggerCallExp+" a").live("click",function(e){e.preventDefault();$("#"+cb.formId).submit()});$(cb.exp).each(function(){var $this=$(this);cb.setTO(true,$this)}).find(cb.expMax).click(function(){var $par=$(this).parents(cb.exp);cb.setTO(false,$par);$par.data("locked",true)}).mouseover(function(){var $par=$(this).parents(cb.exp);cb.setTO(false,$par)}).mouseout(function(){var $par=$(this).parents(cb.exp);if(!$par.data("locked")){cb.setTO(true,$par)}}).find(cb.expMinimize).click(function(e){e.preventDefault();cb.hide($(this).parents(cb.exp))});$(cb.exp).find(cb.expMin).mouseover(function(){var $par=$(this).parents(cb.exp);$par.data("toDelay",setTimeout(function(){$par.data("locked",true);cb.show($par)},cb.mouseOverTime))}).mouseout(function(){var $par=$(this).parents(cb.exp);clearTimeout($par.data("toDelay"))}).click(function(){var $par=$(this).parents(cb.exp);$par.data("locked",true);cb.show($par)});$("#"+cb.targetId.phone.a).change(function(){cb.validateNumber("a")});$("#"+cb.targetId.b).keyup(function(e){if(e.which===cb.keysListSelKeys.enter&&$.browser.msie){cb.partyFlagKeyUpChangeIe=true}cb.handleKeyUp(e,$(this),"b")}).focus(function(){$(this).addClass(com.boldClass);var $par=$(this).parents(cb.exp);cb.setTO(false,$par);$par.data("locked",true)}).change(function(e){e.preventDefault();if(!cb.partyFlagKeyUpChangeIe){cb.validateNumber("b")}else{cb.partyFlagKeyUpChangeIe=false}});cb.bindKeyUpForA();$(cb.confirmBtnExp).click(function(e){e.preventDefault();cb.validateNumber("b")});$("#"+cb.formId).submit(function(e){e.preventDefault();if(cb.handleSubmit()){this.submit()}});$(cb.partySelExp).find(cb.partySelEntryExp).click(function(){cb.selectPartyEntry($(this));cb.bindKeyUpForA();cb.partySelBoxOpen=false});$("#"+cb.countryListLinkId).click(function(e){e.preventDefault();$("#"+cb.countryListId).show()});$(cb.connDescExp+" a").live("click",function(e){e.preventDefault();if($(this).parents("#"+cb.partyId.b).length>0){cb.applyBInput()}else{cb.openSelectParty()}});$("#"+cb.countryListId).find(cb.countryLinkExp).live("click",function(e){e.preventDefault();$("#"+cb.countryListId).hide();var cc=$(this).attr("cc");var country=$(this).text();if($("#"+cb.targetId.b+":visible").length>0){cb.applyBInput()}cb.insertBNumber(cc,"",country,"UNKNOWN");$("#"+cb.targetId.phone.b).focus()});cb.handleKeyUp(null,$("#"+cb.targetId.phone.a),"a");if(typeof(callback_after_cbInit)=="function"){callback_after_cbInit()}},show:function($o){if($.browser.mozilla&&$(cb.modeTabExp).hasClass(cb.activeFieldClass)){pb.mozFade($o,true)}$o.find(cb.expMax).slideDown(cb.fadeInSpeed);$o.find(cb.expMin).slideUp(cb.fadeOutSpeedmin)},hide:function($o){if($.browser.mozilla&&$(cb.modeTabExp).hasClass(cb.activeFieldClass)){pb.mozFade($o,false)}$o.find(cb.expMax).slideUp(cb.fadeOutSpeedmax);$o.find(cb.expMin).slideDown(cb.fadeInSpeed)},bindKeyUpForA:function(){$("#"+cb.targetId.phone.a).live("keyup",function(e){cb.handleKeyUp(e,$(this),"a")})},unbindKeyUpForA:function(){$("#"+cb.targetId.phone.a).die("keyup")},validateNumber:function(party){if(party=="b"){var cc=($("#"+cb.targetId.cc.b).val())?$("#"+cb.targetId.cc.b).val():"";var phone=($("#"+cb.targetId.phone.b).val())?$("#"+cb.targetId.phone.b).val():"";var term=($("#"+cb.targetId.b).val()&&!cc&&!phone)?$("#"+cb.targetId.b).val():"";$.ajax({url:"validateNumber.do",async:false,type:"GET",data:{cc:cc,phone:phone,term:term},dataType:"json",success:function(data){if($("#"+cb.targetId.b+":visible").length>0&&data.cc){cb.applyBInput()}if(data.phone!=""&&!$("#"+cb.partyId.a).find(cb.connDescExp).is(":visible")){cb.openSelectParty()}else{if(data.cc==""){$("#"+cb.countryListId).show()}else{if(data.phone==""){$("#"+cb.targetId.phone.b).focus()}else{if(data.cc!=""){cb.setFieldActivation("a",true)}}}}cb.insertBNumber(data.cc,data.phone,data.country,data.type)}})}else{if(party=="a"){var cc=($("#"+cb.targetId.cc.a).val())?$("#"+cb.targetId.cc.a).val():"";var phone=($("#"+cb.targetId.phone.a).val())?$("#"+cb.targetId.phone.a).val():"";$.ajax({url:"validateNumber.do",async:false,type:"GET",data:{cc:cc,phone:phone,term:""},dataType:"json",success:function(data){if(data.phone){$("#"+cb.targetId.phone.a).val(data.phone);$("#"+cb.targetId.numberType).val(data.type);$("#"+cb.partyId.a).find(cb.typeExp).text(cb.TYPES[data.type].a)}}})}}},openSelectParty:function(){cb.setKeyUpListener();$("#"+cb.partyId.a).find(cb.partySelExp).show();cb.unbindKeyUpForA();cb.handleKeyboardSelInit(0,2);$(cb.keysLevel).keydown(function(e){cb.partySelHandleKeyboardEvents(e)});$(cb.partySelExp).find(cb.partySelEntryExp).hover(function(){cb.keysListSelCurMouse=$(this);$(cb.partySelExp).find(cb.partySelEntryExp+":nth-child("+cb.keysListSelPosition+")").removeClass(cb.keysListSelExpSelected);$(this).addClass(cb.keysListSelExpSelected);cb.keysListSelPosition=$(cb.partySelEntryExp).index($(this))+1},function(){$(cb.partySelExp).find(cb.partySelEntryExp).each(function(){$(this).removeClass(cb.keysListSelExpSelected)});cb.keysListSelPosition=0})},partySelHandleKeyboardEvents:function($event){if($event.which===cb.keysListSelKeys.enter){$event.preventDefault();$event.stopPropagation();if(cb.keysListSelPosition!=0){cb.selectPartyEntry($(cb.partySelExp).find(cb.partySelEntryExp+":nth-child("+cb.keysListSelPosition+")"))}}cb.handleKeyboardListSelection($event,cb.partySelExp,cb.partySelEntryExp,cb.keysListSelExpSelected,cb.keysListSelKeys)},handleKeyboardListSelection:function($event,$generalClass,$specificItem,$selectedExp,$keys){$(cb.keysListSelCurMouse).removeClass($selectedExp);if($event.which===$keys.up){$event.preventDefault();$($generalClass).find($specificItem+":nth-child("+cb.keysListSelPosition+")").removeClass($selectedExp);if(cb.keysListSelPosition!=1&&cb.keysListSelPosition!=0){$($generalClass).find($specificItem+":nth-child("+cb.keysListSelPosition+")").prev().addClass($selectedExp);cb.keysListSelPosition=cb.keysListSelPosition-1}else{if(cb.keysListSelPosition===1||cb.keysListSelPosition===0){$($generalClass).find($specificItem+":last").addClass($selectedExp);cb.keysListSelPosition=cb.keysListSelItemCount}}}else{if($event.which===$keys.down){$event.preventDefault();$($generalClass).find($specificItem+":nth-child("+cb.keysListSelPosition+")").removeClass($selectedExp);if(cb.keysListSelPosition!=cb.keysListSelItemCount&&cb.keysListSelPosition!=0){$($generalClass).find($specificItem+":nth-child("+cb.keysListSelPosition+")").next().addClass($selectedExp);cb.keysListSelPosition=cb.keysListSelPosition+1}else{if(cb.keysListSelPosition===cb.keysListSelItemCount||cb.keysListSelPosition===0){$($generalClass).find($specificItem+":first").addClass($selectedExp);cb.keysListSelPosition=1}}}}},handleKeysLevel:function(){if($.browser.msie){cb.keysLevel=document}else{cb.keysLevel=window}},handleKeyboardSelInit:function($position,$listItemCount){cb.keysListSelPosition=$position;cb.keysListSelItemCount=$listItemCount},handleKeyboardSelUnbind:function($list){$(cb.keysLevel).unbind("keydown");cb.keysListSelPosition=0;$list.each(function(){$(this).removeClass(cb.keysListSelExpSelected)})},setKeyUpListener:function(){$(document).keyup(function(e){if(cb.keysListSelKeys.enter===e.which&&cb.partySelBoxOpen){$(document).unbind("keyup");cb.bindKeyUpForA();e.preventDefault();e.stopPropagation();cb.partySelBoxOpen=false}})},debugKeys:function($event){console.log("Event: "+$event.which);console.log("Selection List Item Count: "+cb.keysListSelItemCount);console.log("Selection Key Position: "+cb.keysListSelPosition)},selectPartyEntry:function($entry){cb.partySelBoxOpen=true;$("#"+cb.targetId.callType).val($entry.attr("callType"));$par=$entry.parents("#"+cb.partyId.a);$par.find(cb.connModeExp).text($entry.attr("connText"));cb.handleKeyboardSelUnbind($(cb.partySelExp).find(cb.partySelEntryExp));$par.find(cb.partySelExp).hide();$par.find(cb.connDescExp).show();cb.setFieldActivation("a",true)},applyBInput:function(){if($("#"+cb.targetId.b+":visible").length>0){$fcc=$(document.createElement("input")).attr({id:"ccB",type:"text",disabled:"disabled"}).addClass("ccB bold");$fphone=$(document.createElement("input")).attr({id:"phoneB",type:"text",name:"phoneB"}).addClass(com.touchedFieldClass+" bold");$("#"+cb.targetId.b).hide().after($fphone);$("#"+cb.targetId.phone.b).keyup(function(e){cb.handleKeyUp(e,$(this),"b")}).change(function(){cb.validateNumber("b")}).focus(function(){cb.handleFieldFocus($(this))}).blur(function(){cb.handleFieldBlur($(this))}).before($fcc);$("#"+cb.partyId.b).find("h2:first").hide().next().show()}else{$("#"+cb.targetId.cc.b).remove();$("#"+cb.targetId.phone.b).remove();$("#"+cb.targetId.b).val("").show().focus();$(cb.countryExp).text("");$(cb.typeExp).text("");$("#"+cb.targetId.country.bSubmit).val("");$("#"+cb.partyId.b).find(cb.connDescExp).hide();$("#"+cb.countryListLinkId).show();cb.setFieldActivation("a",false);$("#"+cb.partyId.b).find("h2:first").show().next().hide()}},insertBNumber:function(cc,phone,country,type){if($("#"+cb.targetId.phone.b+":visible").length>0){$("#"+cb.targetId.cc.b).val("+"+cc);$("#"+cb.targetId.cc.bSubmit).val("+"+cc);$("#"+cb.targetId.phone.b).val(phone);cb.handleKeyUp(null,$("#"+cb.targetId.phone.b),"b");$(cb.confirmBtnExp).hide();$(cb.countryExp).text(country);if(cb.TYPES[type].b){$("#"+cb.partyId.b).find(cb.typeExp).text(cb.TYPES[type].b+", ")}else{$("#"+cb.partyId.b).find(cb.typeExp).text(cb.TYPES[type].b)}$("#"+cb.targetId.country.bSubmit).val(country);$("#"+cb.countryListLinkId).hide();$("#"+cb.partyId.b).find(cb.connDescExp).show()}else{$("#"+cb.targetId.b).val(cc+phone)}},setFieldActivation:function(party,flag){if(flag){$("#"+cb.targetId.phone[party]).attr({disabled:""}).focus().parents("#"+cb.partyId[party]).addClass(cb.activeFieldClass);if(party=="a"&&$("#"+cb.targetId.phone.a).val().length>=cb.minInputLength&&cb.flashAvailable){cb.toggleCallButton(true)}}else{$("#"+cb.targetId.phone[party]).attr({disabled:"disabled"}).parents("#"+cb.partyId[party]).removeClass(cb.activeFieldClass)}var $par=$("#"+cb.targetId.phone[party]).parents(cb.exp);cb.setTO(false,$par);$par.data("locked",true)},handleSubmit:function(){if(!ma.userKnown||ma.yobNeeded){ma.rightBeforeCall=true;com.open($("#"+ma.myProfileId));return false}else{cb.toggleCallButton(false);try{pz_popunder()}catch(E){}return true}},handleKeyUp:function(event,$o,party){if(event){var charCode=(event.charCode)?event.charCode:((event.which)?event.which:event.keyCode);$tgt=$(event.target);if($tgt.val().length>=cb.minInputLength){if(party=="b"&&$("#"+cb.partyId.a).find(cb.partySelExp).is(":hidden")){$(cb.confirmBtnExp).show()}if(((party=="b"&&$("#"+cb.targetId.phone.a).val().length>=cb.minInputLength)||(party=="a"&&($("#"+cb.targetId.phone.b+":visible").length==0||$("#"+cb.targetId.phone.b).val().length>=cb.minInputLength)))&&cb.flashAvailable){cb.toggleCallButton(true)}}else{if(party=="b"){$(cb.confirmBtnExp).hide()}cb.toggleCallButton(false)}if(charCode==cb.keysListSelKeys.enter){event.preventDefault();event.stopPropagation();if(party=="b"&&!$.browser.mozilla){cb.validateNumber(party)}if(party=="a"&&cb.handleSubmit()){$("#"+cb.formId).submit()}}}},toggleCallButton:function(flag){var txt=$(cb.triggerCallExp).text();if(flag){$(cb.triggerCallExp).removeClass(com.btnInactiveClass).find("label").replaceWith($(document.createElement("a")).attr("href","").text(txt))}else{$(cb.triggerCallExp).addClass(com.btnInactiveClass).find("a").replaceWith($(document.createElement("label")).text(txt))}},handleFieldFocus:function($e){com.handleFieldFocus($e)},handleFieldBlur:function($e){com.handleFieldBlur($e)},setTO:function(set,$o){window.clearTimeout($o.data("toDisplay"));if(set){$o.data("toDisplay",window.setTimeout(function(){cb.hide($o)},cb.holdTime))}}};$(function(){cb.init()});