var url=window.location.href;
var label=null;
var bmdiv=null;
var topdiv="<div class='topdiv'><div class='intopdiv'><div id='closeDiv' class='close' title='Close'><font sixe='4' color='#ffffff'><b>X&nbsp;</b></font></div></div><div align='center' class='innertopdiv'><b><font color='#ffffff' size='2px'>Add To MyFavourites</font></b></div></div>";
var isLoggedin=null;
function mybookmarks(){isLoggedin=getCookie("SMSESSION");
var B=getCookie("JARRITAACCESS");
var A=getCookie("BTWOSFINTREG");
if(isLoggedin!=null&&isLoggedin!=""&&isLoggedin!="LOGGEDOFF"){if(B!=null&&B!=""){document.getElementById("mybookmarks").innerHTML='<INPUT class=greebuttonmybookmark id=flr_h2leftbSpan title=Add&nbsp;to&nbsp;MyFavourites style="CURSOR: pointer" accessKey=4 type=submit value=Add&nbsp;to&nbsp;MyFavourites>';
showDiv1("mybookmarks")
}}}function closeEvent(){$("#closeDiv").click(function(){hideBookmarkDiv()
})
}function set_Cookie(B,G,C,E,F,D){var A=escape(B)+"="+escape(G);
A+=(C?"; EXPIRES="+C.toGMTString():"");
A+=(E?"; PATH="+E:"");
A+=(F?"; DOMAIN="+F:"");
A+=(D?"; SECURE":"");
document.cookie=A
}function get_Cookie(C){var D=null;
if(document.cookie){var A=document.cookie.split((escape(C)+"="));
if(2<=A.length){var B=A[1].split(";");
D=unescape(B[0])
}}return D
}function delete_Cookie(A){var B=get_Cookie(A);
if(B){set_Cookie(A,B,(new Date(1)),"/")
}}$(document).ready(function(){$("#mybookmarks").click(function(){label=document.title;
$("#bookmarkForm_errorloc").show();
$("#bookmarksDialog").height(200);
createDivLayers();
bmdiv=topdiv;
bmdiv+="<div class='centered'><img src='/pages/media/logo/wait.gif' /></div>";
$("#bookmarksDialog").html(bmdiv).fadeIn("slow");
closeEvent();
var A="";
A+="<option value='Please Select'>Please Select</option>";
$.ajax({type:"GET",url:"/container-gadget-display/gadgetdisplay/getUserBookmarks.do",data:"url="+url+"",dataType:"json",timeout:15000,async:true,cache:false,error:function(C,B){if(B=="timeout"){bmdiv=topdiv;
bmdiv+="<div class='centered'><h6><font color='red'>Sorry,your request has timed out, Please try again later.</font></h6></div>";
$("#bookmarksDialog").html(bmdiv).fadeIn("slow");
closeEvent();
setTimeout("hideBookmarkDiv()",3000)
}else{if(C.status=="200"&&B=="parsererror"){isLoggedin=getCookie("SMSESSION");
if(isLoggedin=="LOGGEDOFF"){bmdiv=topdiv;
bmdiv+="<div class='centered'><h6><font color='red'>Sorry, your session has timed out.Please log in again.</font></h6></div>";
$("#bookmarksDialog").html(bmdiv);
closeEvent();
setTimeout("hideBookmarkDiv_refresh()",3000)
}else{delete_Cookie("JARRITAACCESS");
bmdiv=topdiv;
bmdiv+="<div class='centered'><h6><font color='red'>It appears that you do not have access to MyPage. Please contact mypage@bt.com for more information.</font></h6></div>";
$("#bookmarksDialog").html(bmdiv).fadeIn("slow");
closeEvent();
setTimeout("hideBookmarkDiv_refresh()",3000)
}}else{bmdiv=topdiv;
bmdiv+="<div class='centered'><h6><font color='red'>BTWholesale is experiencing some problems with the Server, Please try again later.</font></h6></div>";
$("#bookmarksDialog").html(bmdiv).fadeIn("slow");
closeEvent();
setTimeout("hideBookmarkDiv()",3000)
}}},success:function(C){if(C.btw_bookmarks){var D=null;
var E="private";
if(C.btw_bookmarks.currentbookmark.category){D=C.btw_bookmarks.currentbookmark.category;
if(C.btw_bookmarks.currentbookmark.keyword){E=C.btw_bookmarks.currentbookmark.keyword
}if(C.btw_bookmarks.currentbookmark.label){label=C.btw_bookmarks.currentbookmark.label
}}$.each(C.btw_bookmarks.categories.category.sort(charOrdA),function(G,F){A+="<option "+((D==F)?"SELECTED":"")+">"+F+"</option>"
});
A+="<option value='OTHER'>New Category</option>";
bmdiv=topdiv;
bmdiv+="<div id='bookmarkForm_errorloc' class='error_strings'></div>";
bmdiv+="<form id='bookmarkForm' name='bookmarkForm' action='javascript:makeRequest();' method='get'><div class='bookmarkform'><table width='100%; align='left'><div id='test'><tr width='100%'><td><font color='#666666'>Category</font></td><td><select name='category' id='category' style='width:202px;' onchange='enableOther(this);'>"+A+"</select></td></tr>";
bmdiv+="<tr width='100%'><td width='30%'><font color='#666666'>New Category</td><td></font><input type='text' name='otherCategory' id='otherCategory' maxlength='19' disabled='disabled' onKeyPress='return disableEnterKey(event)' style='width:198px;' onfocus='clearFieldFirstTime(this)'/></td></tr>";
bmdiv+="<tr><td><font color='#666666'>Label</font></td><td><input type='text' id='label' name='label' style='width:198px;' maxlength='50' value='"+label+"' onKeyPress='return disableEnterKey(event)'></input></td></tr>";
bmdiv+="<tr><td><font color='#666666'>Share with My Colleagues</font></td><td><input type='radio' name='accessType' value='public' onKeyPress='return disableEnterKey(event)' "+((E=="public")?"CHECKED":"")+"></input><font color='#666666'>Yes</font>&nbsp;&nbsp;<input type='radio' name='accessType' id='accessType' value='private' onKeyPress='return disableEnterKey(event)'"+((E=="private")?"CHECKED":"")+"></input><font color='#666666'>No</font></td></tr>";
bmdiv+="<tr><td></td><td align='right'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='Submit' name='bookmarkFormSubmit' class='submitbuttonmybookmark' title='Submit' id='bookmarkFormSubmit' value='Submit'></input></tr></table><div></form>";
$("#bookmarksDialog").html(bmdiv).fadeIn("slow");
closeEvent();
var B=new Validator("bookmarkForm");
B.EnableOnPageErrorDisplaySingleBox();
B.addValidation("category","dontselect=0","Please select a category!");
B.addValidation("label","req","Please enter a label!");
B.addValidation("label","alnum_s","Sorry, following characters are not allowed {&pound; ' ^ # % $ ~ * < >  [ ] / +}");
B.addValidation("label","maxlen=50","Label cannot be of more than 50 chars!");
B.addValidation("otherCategory","req","Please enter a category name!");
B.addValidation("otherCategory","alnum_s","Sorry, following characters are not allowed {&pound; ' ^ # % $ ~ * < >  [ ] / +}");
B.addValidation("accessType","selone_radio","Please select access type!")
}else{if(C.errorMyPageAccess){bmdiv=topdiv;
bmdiv+="<div class='centered'><h6><font color='red'>"+C.errorMyPageAccess+"</font></h6></div>";
$("#bookmarksDialog").html(bmdiv).fadeIn("slow");
closeEvent();
setTimeout("hideBookmarkDiv()",3000)
}}}})
})
});
function charOrdA(B,A){B=B.toLowerCase();
A=A.toLowerCase();
if(B>A){return 1
}if(B<A){return -1
}return 0
}function charOrdD(B,A){B=B.toLowerCase();
A=A.toLowerCase();
if(B<A){return 1
}if(B>A){return -1
}return 0
}function paintDivLayer(C,B,A,H){var G=0;
var D=0;
var E=document.getElementById(C);
if(E.offsetParent){while(E.offsetParent){G+=E.offsetLeft;
E=E.offsetParent
}}else{if(E.x){G+=E.x
}}document.getElementById(B).style.left=parseInt(G+A)+"px";
var F=document.getElementById(C);
if(F.offsetParent){while(F.offsetParent){D+=F.offsetTop;
F=F.offsetParent
}}else{if(F.y){D+=F.y
}}document.getElementById(B).style.top=parseInt(D+H)+"px";
B="#"+B;
$(B).fadeIn("slow")
}function loadPopup(){$("#trans_div").css({opacity:"0.7"});
$("#bookmarksDialog").fadeIn("slow");
$("#trans_div").fadeIn("slow")
}function showDiv1(A){document.getElementById(A).style.display="block"
}function hideDiv1(A){var B="#"+A;
$(B).fadeOut("slow")
}function hideBookmarkDiv(){hideDiv1("bookmarksDialog");
hideDiv1("trans_div")
}function hideBookmarkDiv_refresh(){hideDiv1("bookmarksDialog");
hideDiv1("trans_div");
location.reload(true)
}function createDivLayers(){var A=Number(document.body.offsetWidth||document.body.clientWidth);
var B=Number(document.body.offsetHeight||document.body.clientHeight);
createDiv("bookmarksDialog");
createDiv("trans_div","none",A,B);
paintDivLayer("base","bookmarksDialog",220,60);
loadPopup();
return false
}function disableEnterKey(B){var A;
if(window.event){A=window.event.keyCode
}else{A=B.which
}if(A==13){return false
}else{return true
}}function createDiv(E,C,B,A){var D=document.createElement("div");
D.id=E;
D.setAttribute("align","center");
D.style.margin="0px auto";
if(C){D.style.display=C
}if(B){D.style.width=B+"px"
}if(A){D.style.height=A+"px"
}document.body.appendChild(D)
}function enableOther(A){textObj=document.getElementById("otherCategory");
if(A.options[A.selectedIndex].value=="OTHER"){textObj.disabled=false;
textObj.value="<Please Enter>"
}else{textObj.disabled=true;
textObj.value=""
}return 
}function clearFieldFirstTime(A){if(A.value=="<Please Enter>"){A.value=""
}}function trim(A){return A.replace(/^\s+|\s+$/g,"")
}function makeRequest(){$("#bookmarkForm_errorloc").hide();
$("#bookmarksDialog").height(200);
var A=$("#bookmarksDialog").find("form");
$.ajax({type:A.attr("method"),url:"/container-gadget-display/gadgetdisplay/updateUserBookmarks.do?url="+url+"",dataType:"json",timeout:15000,async:true,cache:false,data:A.serialize(),success:function(B){if(B.errorMyPageAccess){bmdiv=topdiv;
bmdiv+="<div class='centered'><h6><font color='red'>"+B.errorMyPageAccess+"</font></h6><br/><input type='button'  value='Close' style='WIDTH:50px;' onClick='hideBookmarkDiv()'></div>";
$("#bookmarksDialog").html(bmdiv).fadeIn("slow");
closeEvent();
setTimeout("hideBookmarkDiv()",3000)
}else{bmdiv=topdiv;
bmdiv+="<div class='centered'><h6><font color='green'>"+B.successString+"</font></h6></div>";
$("#bookmarksDialog").html(bmdiv).fadeIn("slow");
closeEvent();
setTimeout("hideBookmarkDiv()",3000)
}},error:function(){bmdiv=topdiv;
bmdiv+="<div class='centered'><h6><font color='red'>BTWholesale is experiencing some problems with the Server, Please try again later.</font></h6><br/><input type='button'  value='OK' style='WIDTH:50px;' onClick='hideBookmarkDiv()'></div>";
$("#bookmarksDialog").html(bmdiv).fadeIn("slow");
closeEvent();
setTimeout("hideBookmarkDiv()",3000)
}})
}function Validator(A){this.formobj=document.forms[A];
if(!this.formobj){alert("Error: couldnot get Form object "+A);
return 
}if(this.formobj.onsubmit){this.formobj.old_onsubmit=this.formobj.onsubmit;
this.formobj.onsubmit=null
}else{this.formobj.old_onsubmit=null
}this.formobj._sfm_form_name=A;
this.formobj.onsubmit=form_submit_handler;
this.addValidation=add_validation;
this.setAddnlValidationFunction=set_addnl_vfunction;
this.clearAllValidations=clear_all_validations;
this.disable_validations=false;
document.error_disp_handler=new sfm_ErrorDisplayHandler();
this.EnableOnPageErrorDisplay=validator_enable_OPED;
this.EnableOnPageErrorDisplaySingleBox=validator_enable_OPED_SB;
this.show_errors_together=true;
this.EnableMsgsTogether=sfm_enable_show_msgs_together
}function set_addnl_vfunction(A){this.formobj.addnlvalidation=A
}function sfm_enable_show_msgs_together(){this.show_errors_together=true;
this.formobj.show_errors_together=true
}function clear_all_validations(){for(var A=0;
A<this.formobj.elements.length;
A++){this.formobj.elements[A].validationset=null
}}function form_submit_handler(){var bRet=true;
document.error_disp_handler.clear_msgs();
for(var itr=0;
itr<this.elements.length;
itr++){if(this.elements[itr].validationset&&!this.elements[itr].validationset.validate()){bRet=false
}if(!bRet&&!this.show_errors_together){break
}}if(!bRet){document.error_disp_handler.FinalShowMsg();
return false
}if(this.addnlvalidation){str=" var ret = "+this.addnlvalidation+"()";
eval(str);
if(!ret){return ret
}}return true
}function add_validation(E,B,D){var C=null;
if(arguments.length>3){C=arguments[3]
}if(!this.formobj){alert("Error: The form object is not set properly");
return 
}var A=this.formobj[E];
if(A.length&&isNaN(A.selectedIndex)){A=A[0]
}if(!A){alert("Error: Couldnot get the input object named: "+E);
return 
}if(!A.validationset){A.validationset=new ValidationSet(A,this.show_errors_together)
}A.validationset.add(B,D,C);
A.validatorobj=this
}function validator_enable_OPED(){document.error_disp_handler.EnableOnPageDisplay(false)
}function validator_enable_OPED_SB(){document.error_disp_handler.EnableOnPageDisplay(true)
}function sfm_ErrorDisplayHandler(){this.msgdisplay=new AlertMsgDisplayer();
this.EnableOnPageDisplay=edh_EnableOnPageDisplay;
this.ShowMsg=edh_ShowMsg;
this.FinalShowMsg=edh_FinalShowMsg;
this.all_msgs=new Array();
this.clear_msgs=edh_clear_msgs
}function edh_clear_msgs(){this.msgdisplay.clearmsg(this.all_msgs);
this.all_msgs=new Array()
}function edh_FinalShowMsg(){this.msgdisplay.showmsg(this.all_msgs)
}function edh_EnableOnPageDisplay(A){if(true==A){this.msgdisplay=new SingleBoxErrorDisplay()
}else{this.msgdisplay=new DivMsgDisplayer()
}}function edh_ShowMsg(C,B){var A=new Array();
A.input_element=B;
A.msg=C;
this.all_msgs.push(A)
}function AlertMsgDisplayer(){this.showmsg=alert_showmsg;
this.clearmsg=alert_clearmsg
}function alert_clearmsg(A){}function alert_showmsg(C){var D="";
var B=null;
for(var A in C){if(null==B){B=C[A]["input_element"]
}D+=C[A]["msg"]+"\n"
}alert(D);
if(null!=B){B.focus()
}}function sfm_show_error_msg(B,A){document.error_disp_handler.ShowMsg(B,A)
}function SingleBoxErrorDisplay(){this.showmsg=sb_div_showmsg;
this.clearmsg=sb_div_clearmsg
}function sb_div_clearmsg(A){var B=form_error_div_name(A);
show_div_msg(B,"")
}function sb_div_showmsg(B){$("#bookmarksDialog").height(220);
var D="";
for(var A in B){D+="<font color='#B70000'>"+B[A]["msg"]+"</font>\n"
}var C=form_error_div_name(B);
if(!C){C="bookmarkForm_errorloc"
}show_div_msg(C,D);
$("#bookmarkForm_errorloc").hide();
$("#bookmarkForm_errorloc").slideDown("slow")
}function form_error_div_name(B){var C=null;
for(var A in B){C=B[A]["input_element"];
if(C){break
}}var D="";
if(C){D=C.form._sfm_form_name+"_errorloc"
}return D
}function DivMsgDisplayer(){this.showmsg=div_showmsg;
this.clearmsg=div_clearmsg
}function div_clearmsg(B){for(var A in B){var C=element_div_name(B[A]["input_element"]);
show_div_msg(C,"")
}}function element_div_name(A){var B=A.form._sfm_form_name+"_"+A.name+"_errorloc";
B=B.replace(/[\[\]]/gi,"");
return B
}function div_showmsg(C){var E;
var B=null;
for(var A in C){if(null==B){B=C[A]["input_element"]
}var D=element_div_name(C[A]["input_element"]);
show_div_msg(D,C[A]["msg"])
}if(null!=B){B.focus()
}}function show_div_msg(B,A){if(B.length<=0){return false
}if(document.layers){divlayer=document.layers[B];
if(!divlayer){return 
}divlayer.document.open();
divlayer.document.write(A);
divlayer.document.close()
}else{if(document.all){divlayer=document.all[B];
if(!divlayer){return 
}divlayer.innerHTML=A
}else{if(document.getElementById){divlayer=document.getElementById(B);
if(!divlayer){return 
}divlayer.innerHTML=A
}}}divlayer.style.visibility="visible";
return false
}function ValidationDesc(C,B,A,D){this.desc=B;
this.error=A;
this.itemobj=C;
this.condition=D;
this.validate=vdesc_validate
}function vdesc_validate(){if(this.condition!=null){if(!eval(this.condition)){return true
}}if(!validateInput(this.desc,this.itemobj,this.error)){this.itemobj.validatorobj.disable_validations=true;
this.itemobj.focus();
return false
}return true
}function ValidationSet(B,A){this.vSet=new Array();
this.add=add_validationdesc;
this.validate=vset_validate;
this.itemobj=B;
this.msgs_together=A
}function add_validationdesc(B,A,C){this.vSet[this.vSet.length]=new ValidationDesc(this.itemobj,B,A,C)
}function vset_validate(){var A=true;
for(var B=0;
B<this.vSet.length;
B++){A=A&&this.vSet[B].validate();
if(!A&&!this.msgs_together){break
}}return A
}function TestRequiredInput(objValue,strError){var ret=true;
var val=objValue.value;
val=val.replace(/^\s+|\s+$/g,"");
if(eval(val.length)==0){if(!strError||strError.length==0){strError=objValue.name+" : Required Field"
}sfm_show_error_msg(strError,objValue);
ret=false
}return ret
}function TestMaxLen(objValue,strMaxLen,strError){var ret=true;
if(eval(objValue.value.length)>eval(strMaxLen)){if(!strError||strError.length==0){strError=objValue.name+" : "+strMaxLen+" characters maximum "
}sfm_show_error_msg(strError,objValue);
ret=false
}return ret
}function TestInputType(A,C,D,F){var B=true;
var E=A.value.search(C);
if(A.value.length>0&&E>=0){if(!D||D.length==0){D=F
}sfm_show_error_msg(D,A);
B=false
}return B
}function TestDontSelect(objValue,dont_sel_index,strError){var ret=true;
if(objValue.selectedIndex==null){sfm_show_error_msg("ERROR: dontselect command for non-select Item");
ret=false
}if(objValue.selectedIndex==eval(dont_sel_index)){if(!strError||strError.length==0){strError=objValue.name+": Please Select one option "
}sfm_show_error_msg(strError);
ret=false
}return ret
}function TestSelectOneRadio(A,C){var B=A.form.elements[A.name];
var E=false;
for(var D=0;
D<B.length;
D++){if(B[D].checked=="1"){E=true;
break
}}if(false==E){if(!C||C.length==0){C="Please select one option from "+A.name
}sfm_show_error_msg(C,A)
}return E
}function validateInput(G,A,E){var C=true;
var D=G.search("=");
var F="";
var B="";
if(D>=0){F=G.substring(0,D);
B=G.substr(D+1)
}else{F=G
}switch(F){case"req":case"required":if(A.disabled==false){C=TestRequiredInput(A,E);
break
}else{break
}case"maxlength":case"maxlen":C=TestMaxLen(A,B,E);
break;
case"alnum_s":case"alphanumeric_space":C=TestInputType(A,"[^A-Za-z0-9-_;:&()@!|?.,\\s]",E,A.name+": Only alpha-numeric characters and space allowed ");
break;
case"dontselect":C=TestDontSelect(A,B,E);
break;
case"selone_radio":C=TestSelectOneRadio(A,E);
break
}return C
};