// Core

function loginAs(client_id,extra){var param="id=loginas&client_id="+client_id;var lajax=new ajax();lajax.syncchange(false);lajax.postsend("/system/login_ajax.php",param);if(extra!=undefined&&extra!=""){window.location.href=extra;}else
{window.location.href="/home.php";}}function getTemplateList(location,extra){if(extra==null||extra==undefined){extra="";}if(document.getElementById(location).style.display=='none'){$.ajax({url:"/ajax/cb/cb_ajax.php",type:"POST",data:{id:"gettemplatelist",resultscript:extra},beforeSend:function(){timer.startwait();},success:function(html){timer.stopwait();document.getElementById(location).innerHTML=html;$('.nohide').click(function(){$(this).next().toggle();});}});}else
{document.getElementById(location).innerHTML='';}toggle_visibility(location);}function printBilling(client_id,invoice){if(invoice){var i="&invoice="+invoice;}else
{var i="";}genpop("/systemadmin/popup/printbilling.php?client_id="+client_id+i,600,600)}progressTimer="";function startProgress(val,div,auto,setTimer){if(val==undefined||val==""){val=0;}if(val>30){return false;val=0;}if(auto==undefined||auto==""){auto=="N";}if(div==undefined||div==""){if(!document.getElementById('ProgressBar')){document.write('<div id="ProgressBar"></div>');}div="ProgressBar";}document.getElementById(div).innerHTML="";$(function(){$("#"+div).progressbar({value:val});});if(auto=="Y"){if(setTimer==undefined||setTimer==""){setTimer=1000;}parseInt(setTimer);var nval=parseInt(val)+10;progressTimer=setTimeout('moveProgress(\''+nval+'\',\''+div+'\',\'Y\','+setTimer+')',setTimer);}}function moveProgress(val,div,auto,setTimer){if(val==undefined||val==""){val=0;}if(val>100){val=0;}if(div==undefined||div==""){div=PrograssBar;}parseInt(val);$("#"+div).progressbar('option','value',val);if(auto=="Y"){var nval=parseInt(val)+5;progressTimer=setTimeout('moveProgress(\''+nval+'\',\''+div+'\',\'Y\','+setTimer+')',setTimer);}}function autoProgressUpdate(div,val){clearTimeout(progressTimer);if(div==undefined||div==''){div="ProgressBar";}if(val!=undefined&&val!=''){moveProgress(0,div,"Y",500);setTimeout('autoProgressUpdate(\''+div+'\')',1000);return false;}$.ajax({type:"POST",url:"/ajax/system/system_ajax.php",data:"id=progressstatus",success:function(html){setTimeout('autoProgressUpdate(\''+div+'\')',8000);moveProgress(html,div,"Y",1500);}});}function killProgress(div){clearTimeout(progressTimer);if(div==undefined||div==""){div="ProgressBar";}if(document.getElementById(div)){$("#"+div).progressbar('destroy');var p=document.getElementById(div);if(div=="ProgressBar"){var par=p.parentNode;par.removeChild(p);}}}function addcal(form,format){if(format==undefined||format==""){format="yy-mm-dd";}$(function(){$("#"+form).datepicker({dateFormat:format,constrainInput:false,showOn:'button',buttonImage:'/img/icon_date.gif',buttonImageOnly:true,changeMonth:true,changeYear:true})});}function country(div,value){var aj=new ajax();aj.postdump=output;aj.postsend("/gen.php","id=country&country="+value);function output(){document.getElementById(div).innerHTML=aj.http.responseText;}}function classSwap(id,classa,classb){if(document.getElementById(id).className==classa){document.getElementById(id).className=classb;}else
{document.getElementById(id).className=classa;}}function emailString(){return/([a-z0-9][\w.+-]*@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)+)/i;}function errorClean(id,subid){if(id!=undefined&&id!=""){if(document.getElementById(id)){document.getElementById(id).innerHTML="";toggle_visibility(id,'none');}}if(document.getElementById('errors')){document.getElementById('errors').innerHTML="";toggle_visibility('errors','none')}if(subid!=undefined&&subid!=""){if(document.getElementById(subid)){document.getElementById(subid).style.display="none";}}}function errorShow(errorslist,id,subid){if(errorslist!=""){var list=Array();if(isArray(errorslist)){var x=0;for(var a=0;a<errorslist.length;a++){if(errorslist[a]!=""){list[x]=errorslist[a];x++;}}}else
{list[0]=errorslist;}if(id!=undefined&&id!=""){if(document.getElementById(id)){var obj=document.getElementById(id);for(var a=0;a<list.length;a++){var er=document.createElement('li');er.innerHTML=list[a];obj.appendChild(er);}toggle_visibility(id,'show')}}else
{if(document.getElementById('errors')){var obj=document.getElementById('errors');for(var a=0;a<list.length;a++){var er=document.createElement('li');er.innerHTML=list[a];obj.appendChild(er);}toggle_visibility('errors','show')}}if(subid!=undefined&&subid!=""){if(document.getElementById(subid)){document.getElementById(subid).style.display="";}}}}function isArray(obj){if(obj.constructor.toString().indexOf("Array")==-1)return false;else
return true;}function showHide(hide,change,classa,classb,texta,textb){if(hide!=undefined&&hide!=""){if(document.getElementById(hide)){toggle_visibility(hide);}}if(classa!=undefined&&classa!=""&&classb!=undefined&&classb!=""){if(change!=undefined&&change!=""){if(document.getElementById(change)){classSwap(change,classa,classb);}}}if(texta!=undefined&&texta!=""&&textb!=undefined&&textb!=""){if(document.getElementById(change)){if(document.getElementById(change).innerHTML==texta){document.getElementById(change).innerHTML=textb;}else
{document.getElementById(change).innerHTML=texta;}}}}function trim(junk){if(junk!=undefined&&junk!=""){junk=junk.replace(/^\s\s*/,'').replace(/\s\s*$/,'');junk=junk.replace(/^\u00A0/,'').replace(/\u00A0/,'');return junk;}else
{return"";}}function autofill(table,key,value,div){if(value.length>0){var options={script:"/inc/classes/gen_ajax.php?id=autofill&table="+table+"&key="+key+"&value="+value.substr(0,value.length-1)+"&autofill=",varname:"input",json:false,cache:false,timeout:5000};new AutoSuggest(div,options);}return false;}function infoupdate(info){if(document.getElementById(info)){document.getElementById(info).style.display='';window.scrollTo(0,0);}}function selected(op){var sel="";for(i=0;i<op.length;++i){if(op.options[i].selected){sel+=op.options[i].value+","}}sel=sel.substr(0,sel.length-1);return sel;}function selector(op,value){if(value==undefined){return false;}for(i=0;i<op.length;++i){if(op.options[i].value==value){op.options[i].selected=true;return true;}}}function radioselect(op){if(op!=undefined){var x=op.length;if(isNaN(x)){if(op.checked==true){return op.value;}}for(var i=0;i<x;i++){if(op[i].checked==true){return op[i].value;}}return'';}}function toggle_visibility(id,hset){var e=document.getElementById(id);if(e){if((e.style.display==''&&hset!="show")||hset=="none"){e.style.display='none';}else
{e.style.display='';}}return false;}function datevalidate(date){var alerts="One of your date formats is wrong, please use the YYYY_mm-dd or mm/dd/YYYY format";var dt=date.split("-");if(dt.length==3){if(dt[0].length==4){if(dt[1]>12){if(date!=""){alert(alerts);}return false;}else
{return true;}}else
{if(date!=""){alert(alerts);}return false;}}else
{if(date!=""){alert(alerts);}return false;}}function datefix(date){if(date.indexOf('/')>0){var dt=date.split('/');while(dt[2].length<3){dt[2]="0"+dt[2];}if(dt[2].length<4){dt[2]="2"+dt[2];}while(dt[0].length<2){dt[0]="0"+dt[0];}while(dt[1].length<2){dt[1]="0"+dt[1];}return dt[2]+"-"+dt[0]+"-"+dt[1];}else
{return date;}}function onEnter(e,func,actionkey){if(actionkey==undefined){actionkey=13;}var key;if(e.which==undefined){key=window.event.keyCode;}else
{key=e.which;}if(key==actionkey){eval(func+"();");}}function loginbox(){var div=document.getElementById('login_box');if(div.style.display=="none"){div.style.display="";document.getElementById('loginscreen').focus();}else
{div.style.display="none";document.getElementById('loginscreen').value="";}}function genpop(url,width,height){var screenwidth=width/2;var screenheight=height/2;popup(url,'','location=no,menubar=no,scrollbars=yes,status=yes,resizable,height='+height+',width='+width+',screenX='+(midscreen('W')-(screenwidth))+',screenY='+(midscreen('H')-(screenheight))+',left='+(midscreen('W')-(screenwidth))+',top='+(midscreen('H')-(screenheight)),'');}function popup(newURL,newName,newFeatures,orgName){var remote=open(newURL,newName,newFeatures);if(remote.opener==null)remote.opener=window;remote.opener.name=orgName;return remote;}function crossdom(xmlString){var myDocument;if(document.implementation.createDocument){var parser=new DOMParser();myDocument=parser.parseFromString(xmlString,"text/xml");}else if(window.ActiveXObject){myDocument=new ActiveXObject("Microsoft.XMLDOM");myDocument.async="false";myDocument.loadXML(xmlString);}return myDocument;}function checkselect(op){var sel="";for(i=0;i<op.length;i++){if(op[i].checked==true){sel+=op[i].value+",";}}if(sel.length==0){return false;}else
{return sel.substring(0,sel.length-1);}}function midscreen(returnwhat){var screenW=screen.width;var screenH=screen.height;var scrn=new Array;scrn[0]=screenW/2;scrn[1]=screenH/2;if(returnwhat.toUpperCase=="H"){return scrn[1];}else if(returnwhat.toUpperCase()=="W"){return scrn[0];}else
{return scrn;}}function selected(op){var sel="";for(i=0;i<op.length;++i){if(op.options[i].selected){sel+=op.options[i].value+","}}sel=sel.substr(0,sel.length-1);return sel;}function toggleBox(szDivID,iState){var obj=document.layers?document.layers[szDivID]:document.getElementById?document.getElementById(szDivID).style:document.all[szDivID].style;obj.display=document.layers?(iState?"show":"hide"):(iState?"block":"none");}function showlayer(layer){var myLayer=document.getElementById(layer).style.display;if(myLayer=="none"){document.getElementById(layer).style.display="";}else{document.getElementById(layer).style.display="none";}}function checkAllRows(formName,chk){var count=document.forms[formName].elements.length;for(var i=0;i<count;i++){document.forms[formName].elements[i].checked=chk;}}

//Ajax

function ajax(timer){var me=this;var mainajaxdir="/ajax";var async=true;if(timer!=undefined){var autotimer=timer;}else
{var autotimer='';}this.ajax_timer="";this.http=getHTTPObject();this.done=true;this.postdump="";this.postdumpend="";this.func="";this.postsend=postsend;this.ajaxclean=ajaxclean;this.stringPageLoad=stringPageLoad
this.responseText="";this.responseXML="";this.syncchange=syncchange;function syncchange(change){async=change;}function getHTTPObject(){var xmlhttp;if(!xmlhttp&&typeof XMLHttpRequest!='undefined'){try{xmlhttp=new XMLHttpRequest();}catch(e){xmlhttp=false;}}return xmlhttp;}function ajaxclean(junk){if(junk){junk=encodeURIComponent(junk);return junk;}else
{return'';}}function stringPageLoad(page){var spj=getHTTPObject();spj.open("GET",page,false);spj.send(null);return spj.responseText;}function crossdom(xmlString){var myDocument;if(document.implementation.createDocument){var parser=new DOMParser();myDocument=parser.parseFromString(xmlString,"text/xml");}else if(window.ActiveXObject){myDocument=new ActiveXObject("Microsoft.XMLDOM");myDocument.async="false";myDocument.loadXML(xmlString);}return myDocument;}function postsend(url,params,func){if(me.done==true){me.func=func;if(autotimer!=""){timer.startwait();}url=mainajaxdir+url;clearTimeout(me.ajax_timer);me.ajax_timer=setTimeout(function(){ajax.done=true;},1000);me.done=false;me.http.open("POST",url,async);me.http.setRequestHeader("Content-type","application/x-www-form-urlencoded");if(browserfind()=="IE"){me.http.setRequestHeader("Content-length",params.length);}if(async==true){me.http.onreadystatechange=ajax_response;}me.http.send(params);if(async==false){if(autotimer!=""){timer.stopwait();}me.func="";me.done=true;me.responseText=trim(me.http.responseText);return me.http.responseText;}}}function ajax_response(){if(me.http.readyState==4&&me.http.status=="200"){if(autotimer!=""){timer.stopwait();}me.responseText=trim(me.http.responseText);me.responseXML=me.http.responseXML;clearTimeout(me.ajax_timer);if(me.postdump!=''){me.postdump();}me.done=true;me.http=getHTTPObject();if(me.postdumpend!=""){me.postdumpend();}me.func="";}}function xmlparser(xml,parent){while(parent.substr(0,1)=="/"){parent=parent.substr(1,parent.length);}var info=parent.split("/");var xmlDocument=xml;var root=xmlDocument.getElementsByTagName(info[0])[0];var julia=new Array();julia=nodes(root);return julia;}function nodes(xml,level){var nodearray=new Array();var z=0;for(var i=0;i<xml.childNodes.length;i++){var sibling=xml.childNodes.item(i);if(sibling.childNodes.length>1){nodearray[z]=new Array();nodearray[z][sibling.nodeName]=nodes(sibling);z++;}else
{if(sibling.childNodes.length==1){nodearray[sibling.nodeName]=sibling.childNodes.item(0).data;}if(sibling.childNodes.length==0&&sibling.nodeName.substr(0,1)!="#"){nodearray[sibling.nodeName]="";}}}return nodearray;}function browserfind(){if(navigator.appName=="Microsoft Internet Explorer"){browser="IE";}else
{browser="OTHER";}return browser;}}


//List Search

function ListSearch(fields){var searchfield=new Array();var searcharrow=new Array();var order=new Array();var me=this;this.SearchList_Nav=SearchList_Nav;this.ArrowSet=ArrowSet;this.SearchSort=SearchSort;this.search_nav='';this.search_grid='';this.navload=navload;this.gridload=gridload;this.Excel=Excel;this.LoadAjax=LoadAjax;this.SearchString=SearchString;this.Output=Output;var ajax="";var xsltclass="";var formval="";var divlist="";var formlist="";var lastfirst=0;this.limit="";if(fields!=undefined&&fields.length>0){SearchFields(fields);}function SearchList_Nav(amount){var list_show=parseInt(document.getElementById('list_show').innerHTML);var list_start=parseInt(document.getElementById('list_start').innerHTML);var list_max=parseInt(document.getElementById('list_max').innerHTML);var cc=parseInt(document.getElementById('current_count').innerHTML);list_start=list_start+amount;if(list_start<0||cc+amount<0){list_start=0;var newcc=0;}else if(cc+amount>list_max){var newcc=list_max-list_show;list_start=newcc;}else
{var newcc=cc+amount;list_start=cc+amount;}if((list_max-list_show)<list_start){list_start=list_max-list_show;}document.getElementById('current_count').innerHTML=newcc;if(list_start!=0){document.getElementById('search_back1').style.visibility="visible";document.getElementById('search_back3').style.visibility="visible";}else
{document.getElementById('search_back1').style.visibility="hidden";document.getElementById('search_back3').style.visibility="hidden";}if(list_start==list_max-list_show){document.getElementById('search_forward1').style.visibility="hidden";document.getElementById('search_forward3').style.visibility="hidden";}else
{document.getElementById('search_forward1').style.visibility="visible";document.getElementById('search_forward3').style.visibility="visible";}for(var a=0;a<list_start;a++){document.getElementById('search_box'+a).style.display='none';}for(var b=list_start;b<(list_start+list_show);b++){document.getElementById('search_box'+b).style.display='';}for(var c=(list_start+list_show);c<list_max;c++){document.getElementById('search_box'+c).style.display='none';}document.getElementById('list_start').innerHTML=list_start;return false;}function ArrowSet(){for(var i=0;i<order.length;i++){if(searcharrow[order[i]]!=''){if(document.getElementById(order[i])){document.getElementById(order[i]).innerHTML='<span style="float:right; padding-top:3px;">'+searcharrow[order[i]]+'</span>'+document.getElementById(order[i]).innerHTML;}}}}function SearchSort(field){if(field!=undefined&&field.length>0){if(!searchfield[field]){searchfield[field]='';searcharrow[field]='';}if(searchfield[field]=="ASC"){searchfield[field]="DESC";searcharrow[field]='<img src="/img/icons/icon_listdown.gif"></img>';if(arrayfind(order,field)==-1){order[order.length]=field;}}else if(searchfield[field]==''){searchfield[field]="ASC";searcharrow[field]='<img src="/img/icons/icon_listup.gif"></img>';if(arrayfind(order,field)==-1){order[order.length]=field;}}else
{searchfield[field]='';searcharrow[field]='';order[arrayfind(order,field)]='';order=ordersort(order);}}var final='';var j=0;for(var i=0;i<order.length;i++){if(searchfield[order[i]]!=''){final+=order[i]+" "+searchfield[order[i]]+",";}}if(final.length>0){final=final.substr(0,final.length-1);}return final}function ordersort(array){var tmp=Array();for(var a=0;a<array.length;a++){if(array[a]!=''){tmp[tmp.length]=array[a];}}return tmp;}function arrayfind(array,what){for(var a=0;a<array.length;a++){if(array[a]==what){return a;}}return-1;}function SearchFields(fields){if(fields!=undefined&&fields.length>0&&fields.indexOf(";")>0){var julia=fields.split(";");}else
{var julia=new Array(fields);}for(var a=0;a<julia.length;a++){searchfield[julia[a]]='';searcharrow[julia[a]]='';}}function navload(ajax,page){if(me.search_nav==''){me.search_nav=eval('ajax.stringPageLoad("'+page+'");');}return me.search_nav;}function gridload(ajax,page){if(me.search_grid==''){me.search_grid=eval('ajax.stringPageLoad("'+page+'");');}return me.search_grid;}function LoadAjax(najax,ndivlist,nformlist){ajax=najax;xsltclass=new xslt();formval=new formvalidate();divlist=ndivlist;formlist=nformlist;}function SearchString(first,field){if(ajax==""){alert("loadajax(ajax,div,form) required to use this function, ajax missing");return false;}if(!first||first==""){if(first!=0){first=lastfirst;}}if(!field||field.length==0){field='';}lastfirst=first;var line="&orderby="+me.SearchSort(field)+"&excel=N&first="+first;if(divlist!=""){line+="&"+formval.listpull(divlist,formlist);}return line;}function Excel(id,extra){if(id!=undefined&&id!=''){var line="id="+id+"&excel=Y&orderby="+me.SearchSort();if(extra!=undefined&&extra!=""){line+="&"+extra;}if(ajax!=""){if(divlist!=""&&formlist!=""){line+="&"+formval.listpull(divlist,formlist);}}return line;}}function Output(divgrid,divnav,grid,nav){if(ajax!=""){var xml=ajax.responseText;document.getElementById(divgrid).innerHTML=xsltclass.XSLproc(xml,me.gridload(ajax,grid));if(nav!=""){document.getElementById(divnav).innerHTML=xsltclass.XSLproc(xml,me.navload(ajax,nav));}me.ArrowSet();}else
{alert("Need LoadAjax(ajax,divlist,formlist) for this function to work");return false;}}}


//Login

function login(){var me=this;var url='/system/login_ajax.php';this.check=check;this.logoutpage="/index.php";this.goodlogin="";this.logout=logout;this.gohome=gohome;function check(login,passwd,page){if(login!=''){if(passwd!=''){var final=true;var param="id=login&user="+login+"&passwd="+passwd+"&page="+page;$.ajax({type:"POST",data:param,async:false,url:"/ajax/system/login_ajax.php",success:function(html){if(html=="0"){alert("Username or Password is wrong, please try again");final=false;}else if(html=="olduser"){alert("Username or Password is wrong. You could be a legacy Contact Beacon user, please go to http://legacy.contactbeacon.com/");final=false;}else if(html=="deactivate"){errorShow('This account was disabled.  Please <a href="/contact_support.php">contact us</a> to request account reactivation','loginerror','loginerrortr');final=false;}else if(html!="0"){goodlogin(html,page);final=true;}}});return final;}else
{alert("Please enter password");return false;}}else
{alert("Please enter login name");return false;}}function logout(){var param="id=goaway";$.ajax({type:"POST",url:"/ajax/system/login_ajax.php",data:{id:'goaway'},success:function(html){var info=trim(html);if(info==1){window.location.href="/systemadmin/index.php";}else
{window.location.href=me.logoutpage;}}});}function gohome(count,page){var url='';if(page==undefined){page='';}if(count=="tc"){document.getElementById('loginForm').action="/terms.php?"+page;return true;}else if(count>1){document.getElementById('loginForm').action="/pick_company.php?"+page;return true;}else if(count==1){document.getElementById('loginForm').action="/home.php?"+page;return true;}if(!url){return;}if(top.location!=self.location){var base=getHttpBaseUrl(top.location);url=base+url;top.location=url;}else
{var base=getHttpBaseUrl(window.location.href);url=base+url;window.location.href=url;}}function getHttpBaseUrl(url){var base=getBaseUrl(url);return"http://"+base;}function getHttpsBaseUrl(url){var base=getBaseUrl(url);return"https://"+base;}function getBaseUrl(url){var r=new RegExp("^https?://([\\w\\.]+)/");var matches=r.exec(url);return matches[1];}function goodlogin(count){gohome(count);}}

//Form Validate

function formvalidate(){this.listpull=listpull;this.validate=validate;this.jump=true;var red='#FF0000';var black='#000000';function getObj(obj,form,lit){if(form!=""&&form!=undefined){if(lit!=undefined){return"document.forms['"+form+"']."+obj;}else
{return eval('document.forms["'+form+'"].'+obj);}}else
{if(lit!=undefined){return"document.getElementById('"+obj+"')";}else
{return document.getElementById(obj);}}}function listpull(divs,form){var julia="";var div=divs.split(";");for(var a=0;a<div.length;a++){if(document.getElementById(div[a])==null){alert(div[a]+" does not exist!");return false;}var list=document.getElementById(div[a]).innerHTML;if(list.substr(list.length-1,1)==";"){list=list.substr(0,list.length-1);}list=list.replace(/ /g,'');var field=list.split(";");for(var b=0;b<field.length;b++){var type=trim(field[b].substr(0,field[b].indexOf(".")).toUpperCase());var tfield=trim(field[b].substr(field[b].indexOf(".")+1,field[b].length));var obj=getObj(tfield,form);if(type=="SELECT"){julia=julia+tfield+"="+ajaxclean(selected(obj))+"&";}else if(type=="CHECKBOX"){julia=julia+tfield+"="+checkselect(obj)+"&";}else if(type=="RADIO"){julia=julia+tfield+"="+radioselect(obj)+"&";}else
{if(field[b].indexOf(".")>0){var f=field[b].substr(field[b].indexOf(".")+1,field[b].length);}else
{var f=field[b];}julia=julia+f+"="+ajaxclean(obj.value)+"&";}}}julia=julia.substr(0,julia.length-1);return(julia);}function validate(divs,form){var div=divs.split(";");for(var a=0;a<div.length;a++){if(document.getElementById(div[a])==null){alert(div[a]+" "+a+" does not exist!");return false;}var test=document.getElementById(div[a]);if(test.tagName=='DIV'){var list=document.getElementById(div[a]).innerHTML;var field=list.split(";");}else
{var field=Array();field[0]=div[a];}for(var b=0;b<field.length;b++){var type=trim(field[b].substr(0,field[b].indexOf(".")).toUpperCase());var tfield=trim(field[b].substr(field[b].indexOf(".")+1,field[b].length));if(document.getElementById(tfield+"_title")){if(document.getElementById(tfield+"_title").className=="alert"){document.getElementById(tfield+"_title").className="";}}var obj=getObj(tfield,form);if(type=="SELECT"){if(selected(obj)==""){require(divs,form);return false;}}else if(type=="RADIO"){if(radioselect(obj)==''){require(divs,form);return false;}}else
{if(trim(obj.value)==''||obj.value==''||obj.value=='Required Field'){require(divs,form);return false;}}}}return true;}function require(divs,form){var div=divs.split(";");for(var a=0;a<div.length;a++){if(document.getElementById(div[a])==null){return false;}var test=document.getElementById(div[a]);if(test.tagName=='DIV'){var list=document.getElementById(div[a]).innerHTML;var field=list.split(";");}else
{var field=Array();field[0]=div[a];}for(var b=0;b<field.length;b++){var type=trim(field[b].substr(0,field[b].indexOf(".")).toUpperCase());var tfield=trim(field[b].substr(field[b].indexOf(".")+1,field[b].length));var obj=getObj(tfield,form);if(type=="SELECT"){if(selected(obj)===""){obj.style.color=red;obj.options[0].text='Required Field';eval(getObj(tfield,form,"Y")+".onblur = function() { var i = selected("+getObj(tfield,form,"Y")+"); "+getObj(tfield,form,"Y")+".style.color = '"+black+"'; reSelect("+getObj(tfield,form,"Y")+",i); }");if(document.getElementById(tfield+"_title")){document.getElementById(tfield+"_title").className="alert";}}else
{if(document.getElementById(tfield+"_title")){document.getElementById(tfield+"_title").className="";}obj.style.color=black;}}else if(type=="RADIO"){if(document.getElementById(tfield+"_title")){document.getElementById(tfield+"_title").className="alert";}}else
{if(trim(obj.value)===""||obj.value=='Required Field'||obj.value=='&#160;'||obj.value==" "){obj.style.color=red;obj.value='Required Field';var tobj=getObj(tfield,form,"Y");eval(tobj+".onfocus= function() { if("+tobj+".value == 'Required Field') { "+tobj+".value = ''; "+tobj+".style.color = '"+black+"'; } } ");eval(tobj+".onkeydown = function() { if("+tobj+".value == 'Required Field') { "+tobj+".value = ''; "+tobj+".style.color = '"+black+"'; } } ");if(document.getElementById(tfield+"_title")){document.getElementById(tfield+"_title").className="alert";}}else
{if(document.getElementById(tfield+"_title")){document.getElementById(tfield+"_title").className="";}obj.style.color=black;}}}}if(document.getElementById('infoerror')){document.getElementById('infoerror').style.display='';}if(this.jump==true){window.scrollTo(0,0);}}function radioselect(op){for(var i=0;i<op.length;i++){if(op[i].checked==true){return op[i].value;}}return'';}function isArray(obj){if(obj.constructor.toString().indexOf("Array")==-1)return false;else
return true;}function checkselect(op){if(op.checked==true){return op.value;}else
{return'';}}function trim(junk){junk=junk.replace(/^\s\s*/,'').replace(/\s\s*$/,'');junk=junk.replace(/^\u00A0/,'').replace(/\u00A0/,'');return junk;}function ltrim(junk){return junk.replace(/^\s+/,"");}function rtrim(junk){return junk.replace(/\s+$/,"");}function selected(op){var sel="";for(i=0;i<op.length;++i){if(op.options[i].selected){sel+=op.options[i].value+","}}sel=sel.substr(0,sel.length-1);return sel;}function reSelect(op,value){var tmp=Array();if(value.indexOf(",")!=-1){tmp=value.split(",");}else
{tmp[0]=value;}var sel="";for(i=0;i<op.length;++i){for(a=0;a<tmp.length;a++){if(op.options[i].value==tmp[a]){op.options[i].selected;}}}}function ajaxclean(junk){if(junk){junk=encodeURI(junk);return junk;}else
{return'';}}}

//xslt

function xslt(){var xmlcache=new Array();var xslcachepage="";var mainxsltdir="/";var xsltsortpage;var xsltsortxml;var xsltsortdiv;var xsltsortarrow;this.sorter='ascending';this.XSLproc=XSLTproc;this.XSLTsorter=XSLTsorter;this.XSLTsortSetup=XSLTsortSetup;this.XSLTsort=XSLTsort;var sortfield=new Array();function XSLTsortSetup(div,xslt,xml,arrow){xsltsortpage=xslt;xsltsortxml=xml;xsltsortdiv=div;xsltsortarrow=arrow;}function sorting(field,arrow){try
{var obj=sortfield[field];if(obj=="ascending"){obj="descending";}else if(obj=="descending"){obj='ascending';}else if(obj=="descending"&&arrow!=undefined&&arrow.length>0){obj="none";}else
{obj="ascending";}sortfield[field]=obj;}catch(ex){sortfield[field]="ascending";}return sortfield[field];}function XSLTsort(key,datatype,arrowdiv,xsldiv,xslt,xml){if(!xsldiv){me_div=xsltsortdiv;}else
{me_div=xsldiv;}if(!xslt){me_xslt=xsltsortpage;}else
{me_xslt=xslt;}if(!xml){me_xml=xsltsortxml;}else
{me_xml=xml;}if(me_div==undefined||me_div.length==0){alert("Bad div");return false;}if(me_xslt==undefined||me_xslt.length==0){alert("Bad XSLT page");return false;}if(me_xml==undefined||me_xml.length==0){alert("Bad XML");return false;}if(key==undefined||datatype==undefined){alert("Bad field name or datatype");return false;}var s=sorting(key);document.getElementById(me_div).innerHTML=XSLTproc(me_xml,me_xslt,key,s,datatype);if(arrowdiv!=undefined&&arrowdiv.length>0){if(xsltsortarrow!=undefined&&xsltsortarrow.length>0){if(s=="ascending"){document.getElementById(arrowdiv).innerHTML=document.getElementById(arrowdiv).innerHTML+'<img src="'+xsltsortarrow+"icon_listup.gif"+'"></img>';}else if(s=="descending"){document.getElementById(arrowdiv).innerHTML=document.getElementById(arrowdiv).innerHTML+'<img src="'+xsltsortarrow+"icon_listdown.gif"+'"/>';}else
{document.getElementById(arrowdiv).innerHTML=document.getElementById(arrowdiv).innerHTML+'';}}}return false;}function XSLTproc(oXML,xsl,key,sorter,datatype){var xslurl=mainxsltdir+xsl;bw=browserfind();if(xsl.toLowerCase().indexOf('?xml version="1.0" encoding="utf-8"?>')>0){var loadxsl=false;}else
{var loadxsl=true;}if(sorter==""){sorter="ascending";}if(bw=="IE"){var objXsl=new ActiveXObject('MSXML2.FreeThreadedDomDocument.3.0');objXsl.async=false;if(loadxsl==true){me.http.open("GET",xsl,false);me.http.send(null);xslStylesheet=me.http.responseText;}else
{xslStylesheet=xsl;}xslStylesheet=xsltclean(xslStylesheet);objXsl.loadXML(xslStylesheet);var xsp=new ActiveXObject('MSXML2.XSLTemplate.3.0');xsp.stylesheet=objXsl.documentElement;var xslpro=xsp.createProcessor;if(typeof oXML=='string'){var nXML=crossdom(oXML);}else
{var nXML=oXML;}xslpro.input=nXML;if(key!=""&&key!=undefined){xslpro.addParameter('sorting',sorter);xslpro.addParameter('rows',key);xslpro.addParameter('datatype',datatype);}xslpro.transform();var page=xslpro.output;}else
{if(loadxsl==true){me.http.open("GET",xsl,false);me.http.send(null);xslStylesheet=me.http.responseText;}else
{xslStylesheet=xsl;}xslStylesheet=xsltclean(xslStylesheet);var xsp=new XSLTProcessor();var xslDoc=crossdom(xslStylesheet);xsp.importStylesheet(xslDoc);if(key!=""&&key!=undefined){xsp.setParameter(null,"sorting",sorter);xsp.setParameter(null,"rows",key);xsp.setParameter(null,"datatype",datatype);}if(typeof oXML=="string"){var nXML=crossdom(oXML);}else
{var nXML=oXML;}var frag=xsp.transformToFragment(nXML,document);var page=new XMLSerializer().serializeToString(frag);}return page;}function crossdom(xmlString){var myDocument;if(document.implementation.createDocument){var parser=new DOMParser();myDocument=parser.parseFromString(xmlString,"text/xml");}else if(window.ActiveXObject){myDocument=new ActiveXObject("Microsoft.XMLDOM");myDocument.async="false";myDocument.loadXML(xmlString);}return myDocument;}function xsltclean(text){var p=new Array();var f=new Array();p[0]="&nbsp;";f[0]="&#160;";p[1]="&iexcl;";f[1]="&#161;";p[2]="&cent;";f[2]="&#162;";p[3]="&pound;";f[3]="&#163;";p[4]="&curren;";f[4]="&#164;";p[5]="&yen;";f[5]="&#165;";p[6]="&brvbar;";f[6]="&#166;";p[7]="&sect;";f[7]="&#167;";p[8]="&uml;";f[8]="&#168;";p[9]="&copy;";f[9]="&#169;";p[10]="&ordf;";f[10]="&#170;";p[11]="&laquo;";f[11]="&#171;";p[12]="&not;";f[12]="&#172;";p[13]="&shy;";f[13]="&#173;";p[14]="&reg;";f[14]="&#174;";p[15]="&macr;";f[15]="&#175;";p[16]="&deg;";f[16]="&#176;";p[17]="&plusmn;";f[17]="&#177;";p[18]="&sup2;";f[18]="&#178;";p[19]="&sup3;";f[19]="&#179;";p[20]="&acute;";f[20]="&#180;";p[21]="&micro;";f[21]="&#181;";p[22]="&para;";f[22]="&#182;";p[23]="&middot;";f[23]="&#183;";p[24]="&cedil;";f[24]="&#184;";p[25]="&sup1;";f[25]="&#185;";p[26]="&ordm;";f[26]="&#186;";p[27]="&raquo;";f[27]="&#187;";p[28]="&frac14;";f[28]="&#188;";p[29]="&frac12;";f[29]="&#189;";p[30]="&frac34;";f[30]="&#190;";p[31]="&iquest;";f[31]="&#191;";p[32]="&times;";f[32]="&#215;";p[33]="&divide;";f[33]="&#247;";p[34]="&gt;";f[34]="&#62;";p[35]="&lt;";f[35]="&#60;";for(var a=0;a<p.length;a++){text=text.replace(eval("/"+p[a]+"/g"),f[a]);}return text;}function XSLTsorter(div,xml,xsl,key,sorter,datatype){if(me.sorter==undefined){me.sorter="ascending";}if(me.sorter=="ascending"){me.sorter="descending";}else
{me.sorter="ascending";}document.getElementById(div).innerHTML=XSLTproc(xml,xsl,key,me.sorter,datatype);}function browserfind(){if(navigator.appName=="Microsoft Internet Explorer"){browser="IE";}else
{browser="OTHER";}return browser;}function unescapeHTML(html){var node=document.createElement("DIV");node.innerHTML=html;if(node.innerText){return node.innerText;}return node.textContent;}}


//Timer

function mnltimer(){var me=this;this.div="";this.waitdiv="";this.startwait=startwait;this.stopwait=stopwait;function browserfind(){if(navigator.appName=="Microsoft Internet Explorer"){browser="IE";}else
{browser="OTHER";}return browser;}function startwait(){if(document.getElementById(me.waitdiv)&&document.getElementById(me.waitdiv)!=null){document.getElementById(me.waitdiv).style.top=wheretop()+"px";document.getElementById(me.waitdiv).style.left=whereleft()+"px";document.getElementById(me.waitdiv).style.display='block';}}function stopwait(){if(document.getElementById(me.waitdiv)){document.getElementById(me.waitdiv).style.display="none";}}function wheretop(){if(browserfind()=="IE"){return(midscreen("H")+document.documentElement.scrollTop)-parseInt(document.getElementById(me.waitdiv).style.height);}else
{return(midscreen("H")+window.scrollY)-parseInt(document.getElementById(me.waitdiv).style.height);}}function whereleft(){var start=0;var mid=0;var boxsize=0;if(document.getElementById(me.div)){start=document.getElementById(me.div).offsetLeft;mid=document.getElementById(me.div).clientWidth/2;}boxsize=document.getElementById(me.waitdiv).clientWidth/2;return(start+mid)-boxsize;}function midscreen(returnwhat,div){if(!div){var screenW=screen.width;var screenH=screen.height;}else
{var screenW=document.getElementById(div).scrollWidth;var screenH=document.getElementById(div).scrollHeight;}var scrn=new Array;scrn[0]=screenW/2;scrn[1]=screenH/2;if(returnwhat.toUpperCase()=="H"){return scrn[1];}else if(returnwhat.toUpperCase()=="W"){return scrn[0];}else
{return scrn;}}}


//Folder Control Buttons

function folder_openfolder(folder_id,type){$.ajax({type:"POST",beforeSend:function(){startProgress(0,type+"_cpbox","Y",200);},success:function(html){killProgress(type+"_cpbox");reshowFolder(type,html);},url:"/ajax/cb/folder_ajax.php",data:({id:"openfolder",folder_id:folder_id,type:type})});}function folder_setParent(type,location){var formData=$("#"+type+"Form").serialize()+"&id=setparent";$.ajax({type:"POST",url:"/ajax/cb/folder_ajax.php",async:false,data:formData});window.location.href=location;}function folder_updateDynamic(type){var formData=$("#"+type+"Form").serialize()+"&id=updatedynamic";$.ajax({type:"POST",beforeSend:function(){startProgress(0,type+"_cpbox","Y",400);},success:function(html){killProgress(type+"_cpbox");reshowFolder(type,html);},url:"/ajax/cb/folder_ajax.php",data:formData});}function folder_refreshSelected(type){var formData=$("#"+type+"Form").serialize();var fd=formData+"&id=cacherefresh";$.ajax({type:"POST",beforeSend:function(){startProgress(0,type+"_cpbox","Y",200);},success:function(html){killProgress(type+"_cpbox");reshowFolder(type,html);},url:"/ajax/cb/folder_ajax.php",data:fd});}function folder_reportSelected(type){var formData=$("#"+type+"Form").serialize();var fd=formData+"&id=storereportdata";$.ajax({type:"POST",beforeSend:function(){},success:function(html){},url:"/ajax/cb/folder_ajax.php",data:fd,async:false});window.location.href="/ajax/cb/folder_ajax.php?id=reportselected&type=event";}function getCheckBox(form){errorClean(form+"_button_errors");var f=document.forms[form+"Form"];var total=Array();var count=f.elements.length;for(var i=0;i<count;i++){if(f.elements[i].checked==true){total[total.length]=f.elements[i].value;}}if(total.length>0){return total;}else
{return false;}}function hasSharedTemplate(type){if(type!='template'){return false;}var elem=document.getElementById('template_checked_-1');if(elem&&elem.checked){return true;}return false;}function sharedTemplateError(type){errorShow("You cannot perform this operation on a shared folder/template.",type+"_button_errors");}function BoxError(type){errorShow("You must make a selection",type+"_button_errors");}function showSelected(type,a){for(var b=0;b<a.length;b++){if(document.getElementById(type+"_link_"+a[b])){document.getElementById(type+"_link_"+a[b]).className="link_copy";}}}function folder_copyCut(type,useraction){var a=getCheckBox(type);if(a==false){BoxError(type);return false;}else if(useraction!='copy'&&hasSharedTemplate(type)){sharedTemplateError(type);return false;}else
{showSelected(type,a);var formData=$("#"+type+"Form").serialize()+"&id=copycut&useraction="+useraction;$.ajax({type:"POST",url:"/ajax/cb/folder_ajax.php",async:false,data:formData});showSelected(type,a);}}function folder_paste(type){var formData=$("#"+type+"Form").serialize()+"&id=paste";$.ajax({type:"POST",beforeSend:function(){startProgress(0,type+"_cpbox","Y",200);},success:function(html){killProgress(type+"_cpbox");reshowFolder(type,html);},url:"/ajax/cb/folder_ajax.php",async:true,data:formData});}function reshowFolder(type,msg){document.getElementById(type+"_showdiv").innerHTML=msg}function folder_nameChange(type){var formData=$("#"+type+"Form").serialize()+"&id=namechange";$.ajax({type:"POST",beforeSend:function(){startProgress(0,type+"_cpbox","Y",200);},success:function(html){killProgress(type+"_cpbox");reshowFolder(type,html);},url:"/ajax/cb/folder_ajax.php",data:formData});}function folder_newFolder(type){var formData=$("#"+type+"Form").serialize()+"&id=newfolder";$.ajax({type:"POST",beforeSend:function(){startProgress(0,type+"_cpbox","Y",200);},success:function(html){killProgress(type+"_cpbox");reshowFolder(type,html);},url:"/ajax/cb/folder_ajax.php",data:formData});}function folder_delete(type){var a=getCheckBox(type);if(a==false){BoxError(type);return false;}else if(hasSharedTemplate(type)){sharedTemplateError(type);return false;}else
{var julia=confirm("Are you sure you want to delete selected item(s)?");if(julia==true){var formData=$("#"+type+"Form").serialize()+"&id=delete";$.ajax({type:"POST",beforeSend:function(){startProgress(0,type+"_cpbox","Y",200);},success:function(html){killProgress(type+"_cpbox");reshowFolder(type,html);},url:"/ajax/cb/folder_ajax.php",data:formData});}}}function folder_newItem(type){var formData=$("#"+type+"Form").serialize()+"&id=newitem";var a=$.ajax({type:"POST",beforeSend:function(){startProgress(0,type+"_cpbox","Y",200);},complete:function(){killProgress(type+"_cpbox");},url:"/ajax/cb/folder_ajax.php",async:false,data:formData}).responseText;switch(type){case"contact_list":{window.location.href="/cb/contacts/list.php?contact_list_id="+a+"&get_results=1&subelm=contact";break;}case"survey":{var folder=document.forms[type+"Form"].folder_id.value;if(folder==0){folder="";}window.location.href="/cb/attribute/survey_edit.php?survey_id="+a+"&folder_id="+folder;break;}case"template":{var folder=document.forms[type+"Form"].folder_id.value;if(folder==0){folder="";}$.ajax({type:"POST",data:{id:'validemailcheck',type:type},beforeSend:function(){startProgress(0,type+"_cpbox","Y",200);},complete:function(){killProgress(type+"_cpbox");},url:"/ajax/cb/folder_ajax.php",success:function(html){if(isNaN(html)||html==0){window.location.href="/cb/validate/index.php?totemp="+a+"&folder_id="+folder;}else
{window.location.href="/cb/templates/edit.php?template_id="+a+"&folder_id="+folder;}}});}}}


//result nav

function resultNav(in_obj){var me=this;var search_id=false;var product_id=false;var sub_type=false;var extra=false;var view_id=false;var showerror=false;var formname=false;var val=new formvalidate();var class_name=false;var mailer="Mail System";var result_loc="";this.type=new Object();this.ajax=false;this.loc=window.location.href;this.checkAllPowercheck=checkAllPowercheck;this.downloadCSV=downloadCSV;this.topMainButton=topMainButton;this.deleteItems=deleteItems;this.saveCheck=saveCheck;this.getStaticList=getStaticList;this.contactListStatusChange=contactListStatusChange
this.removeContactBounceEmail=removeContactBounceEmail;this.removeBadEmail=removeBadEmail;this.singleRemoveBadEmail=singleRemoveBadEmail;this.listStatusChange=listStatusChange;this.mainSubmit=mainSubmit;this.reCheckList=reCheckList;this.setAllCheck=setAllCheck;this.getTemplateL=getTemplateL;this.deleteSurveyContact=deleteSurveyContact;this.loadParam=loadParam;this.addRecurring=addRecurring;this.nav=nav;this.additionalTableParams=additionalTableParams;var a=Array();a[0]='letter';a[1]='page_num';a[2]='page_size';a[3]='sort_field_id';a[4]='sort_desc';a[5]='search_id';a[6]='extra';a[7]='listtype';if(in_obj){for(var b=0;b<a.length;b++){if(in_obj[a[b]]){me.type[a[b]]=in_obj[a[b]];}else
{me.type[a[b]]='';}}}if(in_obj){if(!loadParam(in_obj)){return false;}}else
{alert("Search ID is required");return false;}function addRecurring(index_id,field_id){errorClean(class_name+'_dynamicrecurringlisterror',class_name+'_dynamicrecurringlisterror_tr');$.ajax({url:"/ajax/crm/crm_ajax.php",type:"POST",data:{id:"delcheck",search_id:search_id,product_id:product_id},beforeSend:function(){timer.startwait();},success:function(html){timer.stopwait();if(html=="false"){if(showerror==false){errorShow('Please select one or more records',class_name+'_dynamicrecurringlisterror',class_name+'_dynamicrecurringlisterror_tr');}}else
{$.ajax({url:"/ajax/crm/crm_ajax.php",type:"POST",data:{id:"addtorecurring",search_id:search_id,product_id:product_id,field_id:field_id,index_id:index_id},beforeSend:function(){timer.startwait();},success:function(html){timer.stopwait();errorShow('Users added to recurring list',class_name+'_dynamicrecurringlisterror',class_name+'_dynamicrecurringlisterror_tr');}});}}});}function getTemplateL(){getTemplateList(class_name+"_send_template",class_name);}function setAllCheck(check){$("#"+class_name+"_allchecked").attr('checked',check);}function reCheckList(list){for(var a=0;a<resultlist.length;a++){if(document.getElementById(class_name+'_powercheck['+list[a]+']')){document.getElementById(class_name+'_powercheck['+list[a]+']').checked=true;}}}function resultRequired(){if(view_id==false){alert("View ID is required and must be numeric");return false;}if(formname==false){alert("Form Name is Required");return false;}if(search_id==false){alert("Search ID is required");return false;}}function loadParam(in_obj){if(in_obj['search_id']){search_id=in_obj['search_id'];me.type['search_id']=search_id;}if(in_obj['product_id']){product_id=in_obj['product_id'];}else if(product_id==false){alert("Product ID is required");return false;}if(in_obj['view_id']){view_id=in_obj['view_id'];me.type['vi']=view_id;}if(in_obj['formname']){formname=in_obj['formname'];}if(in_obj['class_name']){class_name=in_obj['class_name'];}else if(class_name==false){alert("Class Name is  required");return false;}if(in_obj['sub_type']){sub_type=in_obj['sub_type'];}if(in_obj['extra']){extra=in_obj['extra'];}if(in_obj['mailer']){mailer=in_obj['mailer'];}if(in_obj['result_location']){result_loc=in_obj['result_location'];}}function mainSubmit(){errorClean(class_name+'_dynamiclisterror',class_name+'_dynamiclisterror_tr');if(sendDynamicList()==false){errorShow('No action preformed',class_name+'_dynamiclisterror',class_name+'_dynamiclisterror_tr');}}function sendDynamicList(){var name=document.getElementById(class_name+'_query_name').value;var dyn=false;if(document.getElementById(class_name+'_cb_list')){dyn=document.getElementById(class_name+'_cb_list').checked;}if(name==''){return false;}if(dyn==true){$.ajax({url:"/ajax/cb/cb_ajax.php",type:"POST",data:{id:"dynamicsendtobeacon",search_id:search_id,search_name:name},beforeSend:function(){timer.startwait();},success:function(){timer.stopwait();errorShow('Your dynamic list has been sent to '+mailer,class_name+'_dynamiclisterror',class_name+'_dynamiclisterror_tr');document.getElementById(class_name+'_query_name').value='';if(document.getElementById(class_name+'_cb_list')){document.getElementById(class_name+'_cb_list').checked=false;}}});}else
{$.ajax({url:"/ajax/crm/crm_ajax.php",type:"POST",data:{id:"savesearch",search_id:search_id,search_name:name},success:function(){errorShow('Your search has been saved',class_name+'_dynamiclisterror',class_name+'_dynamiclisterror_tr');document.getElementById(class_name+'_query_name').value='';if(document.getElementById(class_name+'_cb_list')){document.getElementById(class_name+'_cb_list').checked=false;}}});}}function checkAllPowercheck(checked){if(search_id&&product_id){$.ajax({type:"POST",url:"/ajax/crm/crm_ajax.php",data:{id:'allresultcheck',checked:checked,search_id:search_id,product_id:product_id},beforeSend:function(){timer.startwait();},success:function(html){timer.stopwait();}});}checkAllPower(checked);}function checkAllPower(checked){var elm=document.getElementsByTagName('input');for(var a=0;a<elm.length;a++){var id=elm[a].id;if(id.indexOf(class_name+'_powercheck')!=-1&&elm[a].type=="checkbox"){elm[a].checked=checked;}}}function downloadCSV(){errorClean(class_name+'_dynamiclisterror',class_name+'_dynamiclisterror_tr');$.ajax({url:"/ajax/crm/crm_ajax.php",type:"POST",data:{id:"delcheck",search_id:search_id,product_id:product_id},success:function(html){if(html=="false"){errorShow('Please select one or more records',class_name+'_dynamiclisterror',class_name+'_dynamiclisterror_tr');}else
{var loc_subtype='';var loc_extra='';if(sub_type){loc_subtype=sub_type;}if(extra){loc_extra=extra;}window.location.href="/ajax/crm/upload_ajax.php?id=querycsv&searchid="+search_id+"&viewid="+view_id+"&product="+product_id+"&subtype="+loc_subtype+"&extra="+loc_extra;}}});}function topMainButton(loc_extra){errorClean(class_name+'_dynamiclisterror',class_name+'_dynamiclisterror_tr');sendToList(loc_extra);}function sendToList(loc_extra){var listShow=checkList();showerror=false;if(listShow==true){var param=$("#"+formname).serialize()+"&id=addtolistandtemplate&search_id="+search_id+"&product_id="+product_id;if(loc_extra!=undefined&&loc_extra['contactlist']!=undefined){param+="&contactlist="+loc_extra['contactlist'];}param=param.replace(eval("/"+class_name+"_contact_list/g"),'contact_list');param=param.replace(eval("/"+class_name+"_template/g"),'template');$.ajax({url:"/ajax/cb/cb_ajax.php",type:"POST",data:param,beforeSend:function(){timer.startwait();},success:function(html){timer.stopwait();if(html=='false'){errorShow('Please select one or more records',class_name+'_dynamiclisterror',class_name+'_dynamiclisterror_tr');showerror=true;if($("#"+class_name+"_list_name").css('display')!='none'){createStaticList();}}else
{$("#"+class_name+'_allchecked').attr('checked',false);$("#"+class_name+'_send_template').html('');$("#"+class_name+'_add_to_static').html('');toggle_visibility(class_name+'_send_template','none');toggle_visibility(class_name+'_add_to_static','none');if($("#"+class_name+'_list_name').css('display')!='none'){createStaticList();}switch(html){case"0":{errorShow('Contacts added to pre-existing list',class_name+'_dynamiclisterror',class_name+'_dynamiclisterror_tr');break;}case"1":{errorShow('Contacts added to pre-existing list',class_name+'_dynamiclisterror',class_name+'_dynamiclisterror_tr');break;}case"2":{errorShow('Your Template has been sent',class_name+'_dynamiclisterror',class_name+'_dynamiclisterror_tr');break;}case"1,2":{errorShow('Contacts added to your pre-existing list',class_name+'_dynamiclisterror',class_name+'_dynamiclisterror_tr');errorShow('Your Template have been sent',class_name+'_dynamiclisterror',class_name+'_dynamiclisterror_tr');break;}case"3":{errorShow('No event was created because all emails selected were invalid',class_name+'_dynamiclisterror',class_name+'_dynamiclisterror_tr');break;}}}}});}else
{if($("#"+class_name+'_list_name').css('display')!='none'){createStaticList();}else
{var f=document.forms[formname];var elm=document.createElement("input");elm.setAttribute("type","hidden");elm.setAttribute("value","viewupdate");elm.setAttribute("id","viewupdate");elm.setAttribute("name","viewupdate");f.appendChild(elm);document.forms[formname].submit();}}}function createStaticList(){var listrun=true;val.jump=false;if(!val.validate(class_name+'_newresreq')){errorShow('Please enter a name for your new static list',class_name+'_dynamiclisterror',class_name+'_dynamiclisterror_tr');listrun=false;}val.jump=true;$.ajax({url:"/ajax/crm/crm_ajax.php",type:"POST",data:{id:"delcheck",search_id:search_id,product_id:product_id},beforeSend:function(){timer.startwait();},success:function(html){timer.stopwait();if(html=="false"){if(showerror==false){errorShow('Please select one or more records',class_name+'_dynamiclisterror',class_name+'_dynamiclisterror_tr');}}else
{if(listrun==true){var name=document.getElementById(class_name+'_staticlistname').value;$.ajax({url:"/ajax/cb/cb_ajax.php",type:"POST",data:{id:"addtostaticlist",staticlistname:name,search_id:search_id,product_id:product_id},beforeSend:function(){timer.startwait();},success:function(html){window.location.href="/cb/contacts/list.php?contact_list_id="+html+"&get_results=1&subelm=contact";}});}}}});}function deleteItems(nosubmit){$.ajax({url:"/ajax/crm/crm_ajax.php",type:"POST",data:{id:"delcheck",search_id:search_id,product_id:product_id},success:function(html){if(html=="false"){alert("Please select one or more records");}else
{var msg='';if(html=="true"){msg="Are you sure you want to delete these records?  This will permanently remove them from the database.";}else if(html=="all"){msg="Are you sure you want to delete all records in this search? This will permanently remove them from the database.";}if(msg!=''){var julia=confirm(msg);if(julia==true){var param="id=deleterecords&search_id="+search_id+"&product_id="+product_id;$.ajax({url:"/ajax/crm/crm_ajax.php",type:"POST",data:param,beforeSend:function(){timer.startwait();},success:function(){document.forms[formname].submit();}});}}}}});}function getStaticList(){if($("#"+class_name+'_add_to_static').css('display')=='none'){$.ajax({url:"/ajax/cb/cb_ajax.php",type:"POST",data:{id:"getstaticlist",class_name:class_name},beforeSend:function(){timer.startwait();},success:function(html){timer.stopwait();$("#"+class_name+'_add_to_static').html(html);$('.nohide').click(function(){$(this).next().toggle();});}});}toggle_visibility(class_name+'_add_to_static');}function saveCheck(check,value){if(search_id){var checked=0;if(check==true){checked=1;}var ko=new Date();ji=ko.getTime();$.ajax({type:"POST",url:"/ajax/crm/crm_ajax.php",data:{id:'resultcheck',checked:checked,contact_id:value,timestamp:ji,search_id:search_id,product:product_id}});}else
{alert("can't find search id");}if(check==false){document.getElementById(class_name+'_allchecked').checked=false;}}function checkList(){var elm=document.getElementsByTagName('input');for(var a=0;a<elm.length;a++){var id=elm[a].id;if(id.indexOf(class_name+'_contact_list')!=-1&&elm[a].checked==true){return true;}}var dob=eval("document.forms['"+formname+"']."+class_name+"_template");var b=radioselect(dob);if(b!=undefined&&b!=''){return true;}if(document.getElementById(class_name+'_list_name').style.display!='none'){return true;}return false;}function newList(subelm,id,type){$.ajax({type:'POST',data:{id:'newlist',subelm:subelm,item_id:id,type:type},url:"/ajax/cb/cb_ajax.php",beforeSend:function(){timer.startwait();},success:function(html){if(html!=""){window.location.href="/cb/contacts/list.php?contact_list_id="+html+"&subelm=contact&get_results=1";}}});}function deleteSurveyContact(type,list){var julia=confirm("Are you sure you want to remove selected from survey?");if(julia==true){me.contactListStatusChange(type,list);}}function contactListStatusChange(type,list){errorClean(class_name+'_dynamicemaillisterror',class_name+'_dynamicemaillisterror_tr');$.ajax({url:"/ajax/crm/crm_ajax.php",type:"POST",data:{id:"delcheck",search_id:search_id,product_id:product_id},beforeSend:function(){timer.startwait();},success:function(html){timer.stopwait();if(html=="false"){if(showerror==false){errorShow('Please select one or more records',class_name+'_dynamicemaillisterror',class_name+'_dynamicemaillisterror_tr');}}else
{$.ajax({url:"/ajax/cb/cb_ajax.php",type:"POST",data:{id:"contactliststatuschange",search_id:search_id,product_id:product_id,type:type,extra:extra},beforeSend:function(){timer.startwait();},success:function(html){document.getElementById(formname).submit();}});}}});}function removeContactBounceEmail(list){var msg=confirm("Are you sure you want to delete all selected contacts that all emails are invalid?");if(msg==true){errorClean('dynamicemaillisterror','dynamicemaillisterror_tr');$.ajax({url:"/ajax/crm/crm_ajax.php",type:"POST",data:{id:"delcheck",search_id:search_id,product_id:product_id},beforeSend:function(){timer.startwait();},success:function(html){timer.stopwait();if(html=="false"){if(showerror==false){errorShow('Please select one or more records','dynamicemaillisterror','dynamicemaillisterror_tr');}}else
{$.ajax({url:"/ajax/cb/cb_ajax.php",type:"POST",data:{id:"deleteBounceContacts",search_id:search_id,product_id:product_id},beforeSend:function(){timer.startwait();},success:function(html){timer.stopwait();document.getElementById(formname).submit();}});}}});}}function removeBadEmail(list){errorClean('dynamicemaillisterror','dynamicemaillisterror_tr');$.ajax({url:"/ajax/crm/crm_ajax.php",type:"POST",data:{id:"delcheck",search_id:search_id,product_id:product_id},beforeSend:function(){timer.startwait();},success:function(html){timer.stopwait();if(html=="false"){if(showerror==false){errorShow('Please select one or more records','dynamicemaillisterror','dynamicemaillisterror_tr');}}else
{$.ajax({url:"/ajax/cb/cb_ajax.php",type:"POST",data:{id:"removebademail",search_id:search_id,product_id:product_id},beforeSend:function(){timer.startwait();},success:function(html){timer.stopwait();document.getElementById(formname).submit();}});}}});}function singleRemoveBadEmail(contact,field){var julia=confirm("Are you sure you want to remove this email?");if(julia==true){$.ajax({url:"/ajax/cb/cb_ajax.php",type:"POST",data:{id:"singleremovebademail",contact:contact,field:field},beforeSend:function(){timer.startwait();},success:function(html){document.getElementById('viewform').submit();}});}}function listStatusChange(type,list,contact_id,email,email_id,field){$.ajax({type:"POST",url:"/ajax/cb/cb_ajax.php",data:{id:"singleemaillistmanager",type:type,list:list,contact_id:contact_id,email:email,email_id:email_id,field:field},beforeSend:function(){},success:function(html){if(html==1){switch(type){case"unsubList":{document.getElementById('statusimage'+contact_id+""+field).src="/img/icons/opt-in-faded.gif";break;}case"resubList":{document.getElementById('statusimage'+contact_id+""+field).src="/img/icons/opt-in.gif";break;}case"unsubGlob":{document.getElementById('statusimage'+contact_id+""+field).src="/img/icons/opt-out-red.gif";break;}case"resubGlob":{document.getElementById('statusimage'+contact_id+""+field).src="/img/icons/opt-in.gif";break;}case"remBounce":{document.getElementById('statusimage'+contact_id+""+field).src="/img/icons/opt-in.gif";break;}}}}});}function navJava(in_obj){if(in_obj){for(var key in in_obj){if((key=="sort_field_id"||key=="letter")&&me.type[key]!=in_obj[key]){me.type["page_num"]=1;}me.type[key]=in_obj[key];}}for(key in additional_table_params){me.type[key]=additional_table_params[key];}var info="";for(key in me.type){var kdata=me.type[key];if(kdata!=""){info+=key+"="+encodeURIComponent(kdata)+"&";}}return info;}function additionalTableParams(key,data){if(!data||!data.length){delete additional_table_params[key];}else
{additional_table_params[key]=data;}}function nav(obj){var loc=navJava(obj);if(me.ajax==false){var final=me.loc;if(final.indexOf('?')>-1){final+="&"+loc;}else
{final+="?"+loc;}window.location.href=final;}else
{if(me.resultloc==""){alert("Please add a result location");return false;}loc+="&id=getresults&resultscript="+class_name;if(me.type['extra']!=""){for(key in me.type['extra']){loc+="&extra["+key+"]="+encodeURIComponent(me.type['extra'][key]);}}if(result_loc==false){alert("Result Location was not set");return false;}$.ajax({url:"/ajax/crm/crm_ajax.php",type:"POST",data:loc,beforeSend:function(){},success:function(html){$("#"+result_loc).html(html);}});}}}