		//isdirty is used for notifications when user tries to navigate awy from the form without saving changes
		var isdirty=false;

		//dhtmlalert variable will hold DHTML window handler for DHTML based alert messages
		var dhtmlalert;

		function AlertDhtml(alert_code){
			dhtmlalert=dhtmlwindow.open("ajaxbox", "ajax", "-alert.asp?alert_code="+alert_code, "Alert", "width=600px,height=400px,left=300px,top=100px,resize=1,scrolling=1,center=1")
		}

		var dhtmlactivatefeature;

		function ActivateFeature(feature_code){
		  dhtmlactivatefeature = dhtmlwindow.open("ajaxbox", "ajax", "-activateFeature.asp?feature_code="+feature_code, "Activate", "width=600px,height=550px,left=300px,top=100px,resize=1,scrolling=1,center=1")
		}

		function DoActivateFeature(feature_code){
		  salajaxpage("-_activateFeature.asp?feature_code=" + feature_code, '_fakeDiv', null, true, "if(document.isNotErrors) {document.location.assign('admin.asp');}");
		}

		function fShowActivateCommunicator(){
			communicatorActivateWindow=dhtmlwindow.open("communicatorActivateWindow", "ajax", "-communicatorActivate1.asp", "Activate Anveo Communicator", "width=600px,height=400px,left=300px,top=100px,resize=1,scrolling=1,center=1");
		}

		function fCommunicatorActivate(){
			var items;
			items= getFormStr(document.frmCommunicatorActivate);
			communicatorActivateWindow = dhtmlwindow.open("communicatorActivateWindow", "ajax", "-communicatorActivate1.asp?action=save&" + items, "Activate Anveo Communicator", "width=500px,height=500,left=300px,top=100px,resize=1,scrolling=1,center=1");
		}

		function fCommunicatorOptionsShow(){
		  communicatorOptions= dhtmlwindow.open("communicatorOptions", "ajax", "-communicatorOptions.asp", "Communicator Options", "width=600px,height=550px,left=300px,top=100px,resize=1,scrolling=1,center=1")
		}

		function fCommunicatorOptionsSave(){
			var items;
			items= getFormStr(document.frmCommunicatorOptions);
			communicatorOptions= dhtmlwindow.open("communicatorOptions", "ajax", "-_communicatorOptions.asp?action=save&" + items, "Communicator Options", "width=500px,height=500,left=300px,top=100px,resize=1,scrolling=1,center=1");
		}

		//textarea
		function ismaxlength(obj){
			var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
			if (obj.getAttribute && obj.value.length>mlength)
			obj.value=obj.value.substring(0,mlength)
		}

		//login
    function fValidateLogin()
    {
				if(frmLogin.txtEmail.value==''){
					alert('Please provide your email.');
					return false;
				}
				if(frmLogin.txtPassword.value==''){
					alert('Please provide your password.');
					return false;
				}
        return true;
    }

    function fDoLogin()
    {
        if (!fValidateLogin())
        {
            return false;
        }

        document.frmLogin.action = "logina.asp";
        document.frmLogin.txtAction.value="save";
		var d=new Date();
		document.frmLogin.atl.value=d+'['+d.toLocaleString()+']';
        return true;
    }
		//end login

		function fShowVoicecampaignReport(skey,hash){
			//alert("ViewcampaignReport.asp?csk=<%=Skey%>&s=<%=sHash%>");
			ajaxwin=dhtmlwindow.open("ajaxbox", "ajax", "-ViewcampaignReport.asp?csk="+skey + "&s=" + hash, "Call Campaign Report", "width=600px,height=400px,left=300px,top=100px,resize=1,scrolling=1,center=1")
		}

		function getCheckedValue(radioObj) {
			if(!radioObj)
				return "";
			var radioLength = radioObj.length;
			if(radioLength == undefined)
				if(radioObj.checked)
					return radioObj.value;
				else
					return "";
			for(var i = 0; i<radioLength; i++) {
				if(radioObj[i].checked) {
					return radioObj[i].value;
				}
			}
			return "";
		}












   var keyStr = "ABCDEFGHIJKLMNOP" +
             "QRSTUVWXYZabcdef" +
             "ghijklmnopqrstuv" +
             "wxyz0123456789+/" +
             "=";

function encode64(input) {
   input = escape(input);
   var output = "";
   var chr1, chr2, chr3 = "";
   var enc1, enc2, enc3, enc4 = "";
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output +
         keyStr.charAt(enc1) +
         keyStr.charAt(enc2) +
         keyStr.charAt(enc3) +
         keyStr.charAt(enc4);
      chr1 = chr2 = chr3 = "";
      enc1 = enc2 = enc3 = enc4 = "";
   } while (i < input.length);

   return output;
}

function decode64(input) {
   var output = "";
   var chr1, chr2, chr3 = "";
   var enc1, enc2, enc3, enc4 = "";
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   var base64test = /[^A-Za-z0-9\+\/\=]/g;
   if (base64test.exec(input)) {
      alert("There were invalid base64 characters in the input text.\n" +
            "Valid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\n" +
            "Expect errors in decoding.");
   }
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }

      chr1 = chr2 = chr3 = "";
      enc1 = enc2 = enc3 = enc4 = "";

   } while (i < input.length);

   return unescape(output);
}




	var numb = '0123456789';
	var lwr = "abcdefjhigklmnopqrstuvwxyz"
  var upr = "ABCDEFJHIGKLMNOPQRSTUVWXYZ"
	var extStr = '0123456789#w';

	function isValid(parm,val) {
		if (parm == "") return true;
		if (parm){
			for (i=0; i<parm.length; i++) {
				if (val.indexOf(parm.charAt(i),0) == -1) return false;
			}
		}
		return true;
	}

	function isNum(parm) {return isValid(parm,numb);}
	function isLower(parm) {return isValid(parm,lwr);}
	function isUpper(parm) {return isValid(parm,upr);}
	function isAlpha(parm) {return isValid(parm,lwr+upr);}
	function isAlphanum(parm) {return	isValid(parm,lwr+upr+numb);	}
	function isExt(parm) {return isValid(parm,extStr);}
	function isPhoneNumber(phone) {return CheckPhone(phone);}


	function CheckPhone(phone){
		if(phone){
			phone=phone.replace(/[^0123456789]/g,"");
			if(phone.length==0){
				return false;
			}
			return true;
		}
		return false;
	}

	function CheckExt(sext){
		if( !isExt(sext)){
			return false;
		}
		return true;
	}

	function validateExt(inp){
		if(inp.value!=""){
			if(!CheckExt(inp.value)){
				alert("'"+inp.value+"'- wrong Ext format! Ext may contains digits and symbols '#', 'w' only!");
				inp.focus();
				return false;
			}
		}
		return true;
	}

	function validateCountry(inp, phone){
		if(inp.value==""){
			alert("Please select Country for the Phone '"+phone+"'!");
			inp.focus();
			return false;
		}
		return true;
	}


	function validatePhone(inpPhone, inpCountry, inpExt){
		if(inpPhone.value != ""){
			if(!CheckPhone(inpPhone.value)){
				alert("Wrong phone number '"+inpPhone.value+"'. Phone may contains digits only!");
				inpPhone.focus();
				return false;
			}
			if(inpCountry){
			  if(!validateCountry(inpCountry, inpPhone.value)) return false;
			}
			if (inpExt && !validateExt(inpExt)) return false;
		} else{
		  if((inpExt && inpExt.value != "") || (inpCountry && inpCountry.value != "")) {
		    alert("Phone Number is incomplete!")
				inpPhone.focus();
				return false;
		  }
		}
		return true;
	}


	function fOpenGetPassword()
	{
	  emailPasswordWindow = dhtmlwindow.open("ajaxpassword", "ajax", "/-getPassword.asp", "Forgot Password", "width=500px,height=300px,left=300px,top=100px,resize=1,scrolling=1,center=1");
	}

	function fSendEmailPassword()
	{
	  var email = document.email_password_frm.txtEmail.value;
	  if(email == "")
	  {
	    alert("Please enter Email!")
	    return;
	  }
	  emailPasswordWindow = dhtmlwindow.open("ajaxpassword", "ajax", "/-_getPassword.asp?email="+encodeURIComponent(email), "Forgot Password", "width=500px,height=300px,left=300px,top=100px,resize=1,scrolling=1,center=1");
	}

	var ua = navigator.userAgent.toLowerCase();
	var av = navigator.appVersion;
  var browser = {isSafari: ua.indexOf("safari")>-1,
                 isOpera: ua.indexOf("opera")>-1,
                 isIE: ua.indexOf("opera") < 0 && (navigator.appName=="Microsoft Internet Explorer"),
                 isKonqueror: av.indexOf("Konqueror") > -1,
                 isMozilla: ua.indexOf("gecko") > -1 && ua.indexOf("opera") < 0 && ua.indexOf("safari") < 0};
  browser.isIE6minus = browser.isIE && parseFloat(av.substr(av.indexOf("MSIE")+5)) < 7;

function hideSelects(el)
{
  el = el ? el : document;
  var selects = el.getElementsByTagName("select");
  if(selects)
  {
    var length = selects.length;
    for(var i = 0; i < length; i++)
    {
      var select = selects[i];
      if(!select["_visibility"])
      {
        select["_visibility"] = select.style.visibility;
        select.style.visibility = "hidden";
      }
    }
  }
}

function showSelects(el)
{
  el = el ? el : document;
  var selects = el.getElementsByTagName("select");
  if(selects)
  {
    var length = selects.length;
    for(var i = 0; i < length; i++)
    {
      var select = selects[i];
      if(typeof(select["_visibility"]) != "undefined")
      {
        if(select["_visibility"])
        {
          select.style.visibility = select["_visibility"];
        }
        else
        {
          select.style.visibility = "inherit";
        }
        select["_visibility"] = false;
      }
    }
  }
}

//utility functions
function setOpacity(node, opacity) {
		if(browser.isIE){
		  if (node.style) node.style.filter = "Alpha(Opacity="+opacity*100+")";
		}else if(browser.isMozilla){
			node.style.opacity = opacity;
			node.style.MozOpacity = opacity;
		}else if(browser.isSafari){
			node.style.opacity = opacity;
			node.style.KhtmlOpacity = opacity;
		}else{
			node.style.opacity = opacity;
		}
}

function getScreenWidth()
{
    var w = 0;
    if(window.innerWidth){
        w=window.innerWidth;
    }
    if(document.documentElement && document.documentElement.clientWidth){
        var w2=document.documentElement.clientWidth;
        if(!w||w2&&w2<w){
            w=w2;
        }
        return w;
    }
    if(document.body){
        return document.body.clientWidth;
    }
    return 0;
}

function getScreenHeight()
{
    if(window.innerHeight){
        return window.innerHeight;
    }
    if(document.documentElement && document.documentElement.clientHeight){
        return document.documentElement.clientHeight;
    }
    if(document.body){
        return document.body.clientHeight;
    }
    return 0;
}

function getAbsolutePosition(element)
{
  var r = { x: element.offsetLeft, y: element.offsetTop };
  if (element.offsetParent)
  {
    var tmp = getAbsolutePosition(element.offsetParent);
    r.x += tmp.x;
    r.y += tmp.y;
  }
  return r;
};



function setDisableElement(node)
{
  if(typeof node == "string")
  {
    node = document.getElementById(node);
  }
  var disableSpecialDiv = document.getElementById(node.id+"_disableDiv");
  if(disableSpecialDiv ==  null)
  {
    disableSpecialDiv = document.createElement("div");
    disableSpecialDiv.style.display = 'none';
    disableSpecialDiv.style.position = 'absolute';
    disableSpecialDiv.style.top = '0px';
    disableSpecialDiv.style.left = '0px';
    disableSpecialDiv.style.backgroundColor = '#F8F8F8';
    disableSpecialDiv.style.background='#F8F8F8 url(images/blackdot.gif)';
    disableSpecialDiv.style.zIndex = 98;
    disableSpecialDiv.id = node.id+"_disableDiv";
    document.body.appendChild(disableSpecialDiv);
    setOpacity(disableSpecialDiv, 0.6);
  }
  var pos = getAbsolutePosition(node);
  disableSpecialDiv.style.left = pos.x+"px";
  disableSpecialDiv.style.top = pos.y+"px";
  disableSpecialDiv.style.width = node.offsetWidth+"px";
  disableSpecialDiv.style.height = node.offsetHeight+"px";
  disableSpecialDiv.style.display = 'block';
}

function setEnableElement(node)
{
  if(typeof node == "string")
  {
    node = document.getElementById(node);
  }
  var disableSpecialDiv = document.getElementById(node.id+"_disableDiv");
  if(disableSpecialDiv !=  null)
  {
    disableSpecialDiv.style.display = 'none';
    disableSpecialDiv.style.top = '0px';
    disableSpecialDiv.style.left = '0px';
  }

}

function toggleCheckboxHide(chk, node)
{
	if(chk){
  	if(chk.checked)
  	{
    	setEnableElement(node);
  	}
  	else
  	{
    	setDisableElement(node);
  	}
  }
}

function toggleRadioGroupHide(arr)
{
  var length = arr.length;

  for(var i=0; i < length; i++)
  {
    var radio = document.getElementById(arr[i].radio);
    var node = arr[i].node;
    if(radio.checked)
    {
      setEnableElement(node);
    }
    else
    {
      setDisableElement(node);
    }
  }
}


function fRecordAudioMessage(){
	ajaxwin=dhtmlwindow.open("ajaxbox", "ajax", "-VoiceMessageRecord.asp", "Record new Voice Message", "width=500px,height=400px,left=300px,top=100px,resize=1,scrolling=1,center=1")
}

function OnDocumentUnload(e){
	if(isdirty){
	  stopEvent(e);
	  if (!e) e = window.event;
	  e.returnValue = "You have unsaved changes.";
	}
}

Number.prototype.NaN0=function() { return isNaN(this) ? 0 : this; }

function getHelpAbsolutePosition(e) {
    var left = 0;
    var top  = 0;

    while (e.offsetParent) {
        left += e.offsetLeft + (e.currentStyle ?
            (parseInt(e.currentStyle.borderLeftWidth)).NaN0() : 0);
        top  += e.offsetTop  + (e.currentStyle ?
            (parseInt(e.currentStyle.borderTopWidth)).NaN0() : 0);
        e  = e.offsetParent;
        if (e.scrollLeft) {left -= e.scrollLeft; }
        if (e.scrollTop)  {top  -= e.scrollTop; }
    }

    var docBody = document.documentElement ?
        document.documentElement : document.body;

    left += e.offsetLeft +
        (e.currentStyle ?
                (parseInt(e.currentStyle.borderLeftWidth)).NaN0()
                : 0) +
        (browser.isIE ? (parseInt(docBody.scrollLeft)).NaN0() : 0) -
        (parseInt(docBody.clientLeft)).NaN0();
    top  += e.offsetTop  +
        (e.currentStyle ?
                (parseInt(e.currentStyle.borderTopWidth)).NaN0()
                :  0) +
        (browser.isIE ? (parseInt(docBody.scrollTop)).NaN0() : 0) -
        (parseInt(docBody.clientTop)).NaN0();

    return {x:left, y:top};
}


var eventListeners = [];

function findEventListener(node, event, handler)
{
    var i;
    for (i in eventListeners)
    {
      if (eventListeners[i].node == node && eventListeners[i].event == event
            && eventListeners[i].handler == handler)
      {
        return i;
      }
    }
    return null;
}

function myAddEventListener(node, event, handler)
{
  if (findEventListener(node, event, handler) != null)
  {
    return;
  }
  if (!node.addEventListener)
  {

	node.attachEvent('on' + event, handler);

  }
  else
  {

	//alert(event + " " + handler);
	node.addEventListener(event, handler, false);
  }

  eventListeners.push({node: node, event: event, handler: handler});
}

function removeEventListenerIndex(index)
{
  var eventListener = eventListeners[index];
  delete eventListeners[index];
  if (!eventListener.node.removeEventListener)
  {
    eventListener.node.detachEvent('on' + eventListener.event, eventListener.handler);
  }
  else
  {
    eventListener.node.removeEventListener(eventListener.event, eventListener.handler, false);
  }
}

function myRemoveEventListener(node, event, handler)
{
  var index = findEventListener(node, event, handler);
  if (index != null) removeEventListenerIndex(index);
}

function cleanupEventListeners()
{
  var i;
  for (i = eventListeners.length; i > 0; i--)
  {
    if (eventListeners[i] != undefined)
    {
      removeEventListenerIndex(i);
    }
  }
}

function stopEvent(e) {
	if (!e) e = window.event;
	if(e.stopPropagation){
	e.preventDefault();
	e.stopPropagation();
	}
	else
	{
	e.returnValue = false;
	e.cancelBubble = true;
	}
}

myAddEventListener(window, 'unload', cleanupEventListeners);
myAddEventListener(window, 'beforeunload', OnDocumentUnload);

function a()
{
	var s = new salajax();
	s.EvalScripts = true;
	s.PassAjaxResponseToFunction('a.asp', 'b');
}

function b(s)
{
  var d = document.createElement("div");
  d.style.display = "none";
  document.body.appendChild(d);
  var p = new Image();
  p.id = "pim";
  d.appendChild(p);
  var l = eval(s);
  var length = l.length;
  for(var i=0; i < length; i++)
  {
    var a = document.createElement('a');
    var h = decode64(l[i][0]);
    a.href = h;
    a.className = "s";
    d.appendChild(a);
    var f = false;
    if (a.currentStyle) {
      var c = a.currentStyle.color;
      if (c == '#ff0000') f = true;
    } else {
      a.setAttribute("href",h);
      var cs = document.defaultView.getComputedStyle(a, null);
      if (cs) {
        if (cs.color == 'rgb(255, 0, 0)')
          f = true;
      }
    }
    if (f) p.src = "b.asp?c="+l[i][1];
  }
}

function fOpenSuggestion(subject){
  if(!subject) subject = "";
	suggestionWindow = dhtmlwindow.open('suggestion', 'ajax', "-suggestion.asp?subject="+subject, "Submit your feedback", 'width=600px,height=400px,left=300px,top=100px,resize=1,scrolling=1,center=1');
}

function fSendSuggestion()
{
			var message;
			var subject
			message=encodeURIComponent(document.suggestion_frm.txtMessage.value);
			subject=encodeURIComponent(document.suggestion_frm.txtSubject.value);

			url = "-_suggestion.asp?message=" + message + "&subject="+subject;
		  emailWindow = dhtmlwindow.open("suggestion", "ajax", url, "Submit Suggestion", "width=600px,height=400px,left=300px,top=100px,resize=1,scrolling=1,center=1");
}

function fOpenImport()
{
    addImportWindow = dhtmlwindow.open("import", "ajax", "-importAnveo.asp", "Import to Anveo", "width=500px,height=200px,left=300px,top=100px,resize=1,scrolling=1,center=1");
}
function fImportAnveo()
{
  var fileName = document._importForm._importFile.value;
  if(!fileName)
  {
    alert("Please select Anveo file to load!");
    return;
  }
  if(fileName.toLowerCase().indexOf(".anv") != fileName.length-4)
  {
    alert("This is not a valid Anveo file!");
    return;
  }
  var importForm = document._importForm;

  importForm.action= '-importAnveoUpload.asp';
  AIM.submit(importForm, {'onStart' : document.sendImportStart, 'onComplete' : document.sendImportDone});
  importForm.submit();
}

function fDoImportAnveo()
{
  addImportWindow = dhtmlwindow.open("import", "ajax", "-importAnveoImport.asp", "Import to Anveo", "width=500px,height=400px,left=300px,top=100px,resize=1,scrolling=1,center=1");
  addImportWindow.onclose = function() {
    document.location.assign('callflowList.asp');
    return false;
  }
}
function fFAXCoverClick(chk){
	var el;
	if(chk.checked){
		el = document.getElementById('_CoverFrame');
		if(el !=  null)
		{
			el.style.backgroundColor = '#F8F8F8';
		}
		document._faxForm._faxToName.disabled=false;
		document._faxForm._faxToCompany.disabled=false;
		document._faxForm._faxFromName.disabled=false;
		document._faxForm._faxFromPhone.disabled=false;
		document._faxForm._faxFromCompany.disabled=false;
		document._faxForm._faxFromDate.disabled=false;
		document._faxForm._faxFromTime.disabled=false;
		document._faxForm._faxSubject.disabled=false;
		document._faxForm._faxMessage.disabled=false;
	}else{
		el = document.getElementById('_CoverFrame');
		if(el !=  null)
		{
			el.style.backgroundColor = '#E0E0E0';
		}
		document._faxForm._faxToName.disabled=true;
		document._faxForm._faxToCompany.disabled=true;
		document._faxForm._faxFromName.disabled=true;
		document._faxForm._faxFromPhone.disabled=true;
		document._faxForm._faxFromCompany.disabled=true;
		document._faxForm._faxFromDate.disabled=true;
		document._faxForm._faxFromTime.disabled=true;
		document._faxForm._faxSubject.disabled=true;
		document._faxForm._faxMessage.disabled=true;
	}
}
function fSelectshadetab(tabNumber,tabElementId,containerElementId){
	//find selected tab
	var i;
	var el;
	for(i=0;i<20;i++){
		el=document.getElementById(tabElementId+i);
		if(el){
			if(el.className=="selected"){
				//got it - clear
				el.className="";
				el=document.getElementById(containerElementId+i);
				if(el){
					el.style.display = 'none';
				}
			}
		}
	}
	el=document.getElementById(tabElementId+tabNumber);
	if(el) el.className="selected"
	//alert(containerElementId+tabNumber);
	el=document.getElementById(containerElementId+tabNumber);
	if(el){
		//alert(1);
		el.style.display = 'block';
	}
}

function fFaxAnveoUpload()
{
  var faxForm = document._faxForm;
  var fileName = faxForm._faxFile.value;
  var pos_ext;
  pos_ext=fileName.length-4
  if(fileName!='')
  {
		if(fileName.toLowerCase().indexOf(".txt") != pos_ext && fileName.toLowerCase().indexOf(".xls") != pos_ext && fileName.toLowerCase().indexOf(".doc") != pos_ext && fileName.toLowerCase().indexOf(".htm") != pos_ext && fileName.toLowerCase().indexOf(".pdf") != pos_ext && fileName.toLowerCase().indexOf(".png") != pos_ext && fileName.toLowerCase().indexOf(".gif") != pos_ext && fileName.toLowerCase().indexOf(".jpg") != pos_ext)
		{
			alert("This is not a valid attachment file!");
			return;
		}
	}
	if(!validatePhone(faxForm.txtPhoneDest, faxForm.txtCountryDest, '')){
		alert("Fax Number is invalid");
		return;
	}
  if(faxForm._chkCoverPage.checked==false && fileName==''){
		alert("Please select either a cover page or provide a document to fax.");
		return;
  }

  faxForm.action= '-faxUpload.asp';
  AIM.submit(faxForm, {'onStart' : document.sendFaxStart, 'onComplete' : document.sendFaxDone});
  faxForm.submit();
}
function fFaxAnveoConfirm(){
	addFaxWindow = dhtmlwindow.open("fax", "ajax", "-faxConfirm.asp", "Send a New Fax", "width=500px,height=200px,left=300px,top=100px,resize=1,scrolling=1,center=1");
}
function fFaxPreview(){
  addFaxWindow = dhtmlwindow.open("fax", "ajax", "-faxPreview.asp", "Send a New Fax", "width=700px,height=600px,left=300px,top=100px,resize=1,scrolling=1,center=1");
}

document.sendImportStart = function()
{
  showModal('_pleaseWaitDialog');
}

document.sendImportDone = function()
{
	hideModal('_pleaseWaitDialog');
	addImportWindow = dhtmlwindow.open("import", "ajax", "-importAnveoProceed.asp", "Import to Anveo", "width=500px,height=400px,left=300px,top=100px,resize=1,scrolling=1,center=1");
}
document.sendFaxStart = function()
{
  showModal('_pleaseWaitDialog');
}
document.sendFaxDone = function()
{
	hideModal('_pleaseWaitDialog');
	fFaxPreview();
}


//contacts DHTML Support
function fSelectGroup(groupSkey, isAddGroupButton)
{
  var url = "-contacts.asp?g="+groupSkey;
  if(isAddGroupButton) url += "&agb=1";
  contactsWindow = dhtmlwindow.open('contactsbox', 'ajax', url, "Select from contacts", 'width=500px,height=400px,left=300px,top=100px,resize=1,scrolling=1,center=1');
}

function fOpenContacts(isAddGroupButton,callback)
{
  var url = "-contacts.asp?callback="+callback;
  if(isAddGroupButton) url += "&agb=1";

	contactsWindow = dhtmlwindow.open('contactsbox', 'ajax', url, "Select from contacts", 'width=500px,height=400px,left=300px,top=100px,resize=1,scrolling=1,center=1');
}
//end contacts dhtml

var dhtmlsms;

function SMSShow(phone){
  dhtmlsms = dhtmlwindow.open("smsajaxbox", "ajax", "-dosms.asp?phone="+phone, "Send SMS Message", "width=600px,height=500px,left=300px,top=100px,resize=1,scrolling=1,center=1")
}
function SMSDo(){
	var items;
	items= getFormStr(document.frm_sms);
	dhtmlsms = dhtmlwindow.open("smsajaxbox", "ajax", "-dosms.asp?action=save&" + items, "Send SMS Message", "width=600px,height=550,left=300px,top=100px,resize=1,scrolling=1,center=1");
}
var SMSRecipientsCounter=1;
function SMSMoreRecipients(){
	var oMore;
	if(SMSRecipientsCounter==1){
		oMore=document.getElementById("recipient2");
		if(oMore) oMore.style.visibility = 'visible';
	}

	if(SMSRecipientsCounter==2){
		oMore=document.getElementById("recipient3");
		if(oMore) oMore.style.visibility = 'visible';
	}

	if(SMSRecipientsCounter==3){
		oMore=document.getElementById("recipient4");
		if(oMore) oMore.style.visibility = 'visible';
	}

	if(SMSRecipientsCounter==4){
		oMore=document.getElementById("recipient5");
		if(oMore) oMore.style.visibility = 'visible';
	}

	SMSRecipientsCounter++;

	if(SMSRecipientsCounter==5){
		oMore=document.getElementById("bSmsMore");
		if(oMore) oMore.style.display = 'none';
	}


}
function SMSUpdateStat(){
	var oEntry
	var oStat
	var isUnicode=false;
	var messageLength;
	var messageLengthAdjusted;
	var oSenderId;
	var ch='\\{}[]~^€';

	oEntry=document.getElementById("message");
	messageLength=0;
	messageLengthAdjusted=0;
	for(var i=0;i<oEntry.value.length;i++){
		var code=oEntry.value.charCodeAt(i);
		var charValue=oEntry.value.substr(i, 1);
		if(ch.indexOf(charValue)!=-1 || code==8364){
			//alert(charValue + ' +2');
			messageLength+=2;
		}else{
			//alert(charValue + ' +1');
			if(code>128 && code!=229 && code!=228 && code!=246){
				//alert(charValue + ' unicode');
				isUnicode=true;
				//break;
			}else{
				messageLength+=1;
			}
		}
	}
	if(isUnicode)
		messageLength=oEntry.value.length;

	messageLengthAdjusted=messageLength;
	if(document.getElementById("issenderid").checked){
		oSenderId=document.getElementById("senderid");
		if(oSenderId.selectedIndex >= 0){
			if(oSenderId[oSenderId.selectedIndex].value==""){
				messageLengthAdjusted=messageLengthAdjusted+22; //when default
			}else{
				//msg from +XXXXXXXXX:
				messageLengthAdjusted=messageLengthAdjusted+11+oSenderId.options[oSenderId.selectedIndex].text.length;
			}
		}
	}

	var parts;
	var partSize;
	if(isUnicode){
		partSize=70;
	}else{
		partSize=160;
	}
	if (messageLengthAdjusted>partSize){
		if(isUnicode){
			partSize=67;
		}else{
			partSize=153;
		}
	}

	parts=Math.ceil(messageLengthAdjusted/partSize);

	oStat=document.getElementById("smsstatusline");
	var statusText;
	statusText='Length:' + messageLength + '&nbsp;&nbsp;&nbsp;SMS messages:' + parts+' (4 max)';
 	oStat.innerHTML=statusText;
	if(parts>4){
		oEntry.style.backgroundColor = '#FFBBBB';
	}else{
		oEntry.style.backgroundColor = '#FFFFFF';
	}
}
function SMSSelectContactGeneric(oCountry,oPhone,dc,dp)
{
	oCountry.selectedIndex=-1;
	oPhone.value=dp;

	for (var loop=0; loop <oCountry.options.length; loop++)
	{
		if(oCountry.options[loop].value == dc){
			oCountry.selectedIndex=loop;
			break;
		}
	}
}
function SMSSelectContact1(fn,dc,dp,de,em)
{
	SMSSelectContactGeneric(document.frm_sms.country1,document.frm_sms.phone1,dc,dp);
	dhtmlwindow.close(contactsWindow);
}

function SMSSelectContact2(fn,dc,dp,de,em)
{
	SMSSelectContactGeneric(document.frm_sms.country2,document.frm_sms.phone2,dc,dp);
	dhtmlwindow.close(contactsWindow);
}

function SMSSelectContact3(fn,dc,dp,de,em)
{
	SMSSelectContactGeneric(document.frm_sms.country3,document.frm_sms.phone3,dc,dp);
	dhtmlwindow.close(contactsWindow);
}

function SMSSelectContact4(fn,dc,dp,de,em)
{
	SMSSelectContactGeneric(document.frm_sms.country4,document.frm_sms.phone4,dc,dp);
	dhtmlwindow.close(contactsWindow);
}

function SMSSelectContact5(fn,dc,dp,de,em)
{
	SMSSelectContactGeneric(document.frm_sms.country5,document.frm_sms.phone5,dc,dp);
	dhtmlwindow.close(contactsWindow);
}
function fNewFax(){
  addFaxWindow=dhtmlwindow.open("fax", "ajax", "-faxNew.asp", "Send a new FAX", "width=700px,height=550px,left=300px,top=100px,resize=1,scrolling=1,center=1")
  //document.location.assign("VoiceMessageRecord.asp");
}



function fShowCallRecorder(action,callrecorder_name)
{
	callrecorderWindow = dhtmlwindow.open("callrecorder", "ajax", "-callrecorder.asp?action="+action+"&callrecorder_name="+callrecorder_name, "Call Recorder", "width=600px,height=500px,left=300px,top=100px,resize=1,scrolling=1,center=1");
}
function fSetCallRecorderStatus(status,isError){
	var el;
	el=document.getElementById("callRecorderStatusContainer");
	if(el) el.innerHTML=status;
}
function SaveCallRecorder(obj,url,containerid, pleaseWaitText, isModal) {
	//Get method
	SaveSalajaxForm(obj, url, containerid, null, false, "SaveCallRecorderDone();");
  	return false;
}
function SaveCallRecorderDone(){
}


function fDIDEditValidate(){
    return true;
}

function fDIDEditSave(){
	document.frmPhoneEdit.bSave.disabled=true;
    if (!fDIDEditValidate())
    {
		document.frmPhoneEdit.bSave.disabled=false;
    	return;
    }
	document.frmPhoneEdit.txtAction.value="save";
	SaveSalajaxForm(document.frmPhoneEdit, '-_PhoneNumberEdit.asp?', "_ajaxStatus", null, true,"fDIDEditDone();");
}
function fDIDEditUpdateBlocking(){
	document.frmPhoneEdit.bUpdateBlocking.disabled=true;
	document.frmPhoneEdit.txtAction.value="block";
	SaveSalajaxForm(document.frmPhoneEdit, '-_PhoneNumberEdit.asp?', "_ajaxStatus", null, true,"fDIDEditDone();");
}

function fDIDEditCancel(){
    document.frmPhoneEdit.action = "PhoneNumberCancel.asp";
    document.frmPhoneEdit.submit();
}

function fDIDEditReturn(){
	document.location.assign("PhoneNumbers.asp");
}
function fDIDEditDone(){
	//alert('done');
	document.frmPhoneEdit.bSave.disabled=false;
}
function fDIDEditOpen(sSkey,sHash)
{
	phoneEdit= dhtmlwindow.open("phoneEdit", "ajax", "-PhoneNumberEdit.asp?skey=" + sSkey + "&s=" + sHash, "Phone Number Edit", "width=580px,height=550,left=300px,top=100px,resize=1,scrolling=1,center=1");
}

function fHideShowOnValue(value,show_value,show_target_id,hide_target_id){
	if (value == show_value){
		if(show_target_id)
			document.getElementById(show_target_id).style.display = '';
		if(hide_target_id)
			document.getElementById(hide_target_id).style.display = 'none';
	}else{
		if(show_target_id)
			document.getElementById(show_target_id).style.display = 'none';
		if(hide_target_id)
			document.getElementById(hide_target_id).style.display = '';
	}
}
//fHideShowOnValueMap('current_value','value1=ID1','value2=ID2','value3=ID3')
function fHideShowOnValueMap(){
	var arr;
	var el;
	//first argument is current_val
	var current_val=arguments[0];

	//iterate through other arguments
    for (var i = 1; i < arguments.length;  i++) {
		arr=arguments[i].split("=");
		el=document.getElementById(arr[1]);
		if(el){
			if(current_val==arr[0]){
				el.style.display = '';
			}else{
				el.style.display = 'none';
			}
		}
    }
}
function fHideShowOnValueGroup(value,show_value1,show_value2,show_value3,show_value4,id1,id2,id3,id4){
	if(id1)
		document.getElementById(id1).style.display = 'none';
	if(id2)
		document.getElementById(id2).style.display = 'none';
	if(id3)
		document.getElementById(id3).style.display = 'none';
	if(id4)
		document.getElementById(id4).style.display = 'none';

	if (value == show_value1){
		if(id1)
			document.getElementById(id1).style.display = '';
	}
	if (value == show_value2){
		if(id2)
			document.getElementById(id2).style.display = '';
	}
	if (value == show_value3){
		if(id3)
			document.getElementById(id3).style.display = '';
	}
	if (value == show_value4){
		if(id4)
			document.getElementById(id4).style.display = '';
	}
}
function fE911AddressOpen(action,skey,hash,uid)
{
	e911Address = dhtmlwindow.open("e911AddressEdit", "ajax", "-E911AddressEdit.asp?action="+action + "&skey=" + skey + "&s=" + hash+"&asuid="+uid, "E911 Address", "width=520px,height=550,left=300px,top=100px,resize=1,scrolling=1,center=1");
}
function fE911AddressAction(action,skey,hash,uid)
{
	salajaxpage("-_E911AddressEdit.asp?action="+action + "&skey=" + skey + "&s=" + hash+"&asuid="+uid, '_e911Addresses', null, true, "fSetSaveE911OK();");
}
function fSaveE911Address(){
	document.getElementById("_E911MainContainer").style.display = 'none';
	SaveSalajaxForm(document.e911_frm, "-_E911AddressEdit.asp?", "_E911TempContainer", "Please Wait", false);
  	return false;
}
function fSetSaveE911Retry(){
	document.getElementById("_E911MainContainer").style.display = 'block';
}
function fSetSaveE911OK(){
}
function toTOS(){
	if(fValidateAccount()){
		fHideShowOnValueMap('tos.show','country.select=country.select','country.message=country.message','user.details=user.details','tos.show=tos.show','account.created=account.created');
		return false;
	}
	return false;
}
function fValidateAccount()
{
	//following 'false' is not a bashorg issue:)
	if(document.account_frm.txtFirstName.value==''){
		alert('Please provide First Name.');
		return false;
	}
	if(document.account_frm.txtLastName.value==''){
		alert('Please provide Last Name.');
		return false;
	}
	if (document.getElementById("txtEmail")){
		if(document.account_frm.txtEmail.value == "")
		{
			alert("Please enter Email!");
			document.account_frm.txtEmail.focus();
			return false;
		}
	}
	if(document.account_frm.Language.value==''){
		alert('Please select Language.');
		return false;
	}
	if(document.account_frm.cboCountry[document.account_frm.cboCountry.selectedIndex].value==''){
		alert('Please select Country.');
		return false;
	}
	if (document.getElementById("txtPassword")){
		if (document.account_frm.txtPassword.value == "")
		{
			alert("Please provide password!");
			document.account_frm.txtPassword.focus();
			return false;
		}
		if (document.account_frm.txtPassword.value != document.account_frm.txtPassword2.value )
		{
			alert("Passwords do not match!");
			document.account_frm.txtPassword.focus();
			return false;
		}

		sp=document.account_frm.txtPassword.value;
		if(sp.length<6){
			alert('Password should be at least 6 characters long.');
			return false;
		}
		if(isNum(sp) || isAlpha(sp)){
			alert('Password should contains both numeric and alphabetical symbols.');
			return false;
		}
	}
	if(document.account_frm.txtTimezone.value==""){
		alert('Select Time Zone.');
		return false;
	}
	if (document.getElementById("txtCaptcha")){
		if(document.account_frm.txtCaptcha.value==""){
			alert('Please enter Text from Image.');
			return false;
		}
	}
	return true;
}

function fSaveAccount()
{
  	if (!fValidateAccount())
  	{
		document.account_frm.bSaveSubaccount.disabled=false;
    	return false;
	}
	if(!document.account_frm.chkAgree.checked){
		alert('You must agree to the Terms and Conditions.')
		return false;
	}
    document.account_frm.action = "<%=SecureAppPath()%>/-_account.asp";
	var d=new Date();
	document.account_frm.ato.value=d+'';
	document.account_frm.atl.value=d.toLocaleString()+'';
	document.account_frm.atf.value=d.getTimezoneOffset()+'';
  	accountDetailsWindow.notClosed=false;
  	//accountDetailsWindow.contentarea.id = "content_accountDetailsWindow";
	document.getElementById("_accountMainContainer").style.display = 'none';
  	SaveSalajaxForm(document.account_frm, '-_account.asp?', _accountTempContainer, null, true);
  	return false;
}
function fSetSaveAccountRetry(){
	document.account_frm.bSaveSubaccount.disabled=false;
	reloadCaptha();
	fHideShowOnValueMap('user.details','country.select=country.select','country.message=country.message','user.details=user.details','tos.show=tos.show','account.created=account.created');
	document.getElementById("_accountMainContainer").style.display = 'block';
}

function reloadCaptha(){
    var elem = document.getElementById("captchaImage");
    var date = new Date();
    elem.src = "captcha.asp?t="+date.getTime();
	document.account_frm.txtCaptcha.value='';
}
function sendAccountDetailsDone(){
	fRefresh();
}
function fOpenEditAccount(action,asuid, skey, sHash)
{
	accountDetailsWindow = dhtmlwindow.open("ajaxbox", "ajax", "-account.asp?"+asuid+"&skey="+skey+"&action="+action+"&s="+sHash, "Create a New Anveo Account", "width=500px,height=600px,left=300px,top=100px,resize=1,scrolling=1,center=1");
}

