var isPricingWindow=false; //Used for...?
var displayWindowWidth=442; //Used for...?
var displayWindowHeight=290; //Used for...?

/**
 *  Disable right click
 */
var message="This function is deactivated.";
function click(e) {
    if (document.all) {
        if (event.button == 2) {
            alert(message);
            return false;
        }
    }
    if (document.layers) {
        if (e.which == 3) {
            alert(message);
            return false;
        }
    }
}
if (document.layers) {
    document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
//END Disable right click


/**
 *  Disable ctrl keys
 */
function disableCtrlKeyCombination(e)
{
    //list all CTRL + key combinations you want to disable
    var forbiddenKeys = new Array('a', 'n', 'c', 'x', 'v', 'j');
    var key;
    var isCtrl;

    if(window.event)
    {
        key = window.event.keyCode;     //IE
        if(window.event.ctrlKey)
            isCtrl = true;
        else
            isCtrl = false;
    }
    else
    {
        key = e.which;     //firefox
        if(e.ctrlKey)
            isCtrl = true;
        else
            isCtrl = false;
    }

    //if ctrl is pressed check if other key is in forbidenKeys array
    if(isCtrl)
    {
        for(i=0; i<forbiddenKeys.length; i++)
        {
            //case-insensitive comparation
            if(forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase())
            {
                alert('Key combination CTRL + '
                    +String.fromCharCode(key)
                    +' has been disabled.');
                return false;
            }
        }
    }
    return true;
}
// end of disable ctrl keys


/**
 *  Select all checkboxes
 */
function selectAll(check, checkName){        
    var form1 = check.form;
    var field = form1.elements(checkName);
    for(var i=0; i<field.length; i++){
        field[i].checked=check.checked;
    }
}
//END Select all checkboxes


/**
 *
 */
function doPost(path){
    document.forms[1].method.value=path;        
    document.forms[1].submit();
}   

function validateCheck(check,checkName,flag){
    var form1 = check.form;
    var field = form1.elements(checkName);
    count = 0;
    for(var i=0; i<field.length; i++){
        if(field[i].checked)
            count++;
    }
    if(flag == 0){
        if(count==0) return false;
    }else{
        if(count !=1)return false;
    }
    return true;
}

function textCounter(field,cntfield,maxlimit) {
    if (field.value.length > maxlimit)
        field.value = field.value.substring(0, maxlimit);
    else
        cntfield.value = maxlimit - field.value.length;
}

function limitText(field,maxlimit) {
    var counter=field.value.split('\n').length-1;
    if (field.value.length > maxlimit - counter){
        field.value = field.value.substring(0, maxlimit-counter);
    }
}

function oNumero(numero)
{
    //Propiedades 
    this.valor = numero || 0
    this.dec = -1;
    //Métodos 
    this.formato = numFormat;
    this.ponValor = ponValor;
    //Definición de los métodos 
    function ponValor(cad)
    {
        if (cad =='-' || cad=='+') return
        if (cad.length ==0) return
      
        if (cad.indexOf('.') >=0)
            this.valor = parseFloat(cad);
        else 
            this.valor = parseInt(cad);
    } 

    function numFormat(dec, miles)
    {
        var num = this.valor, signo=3, expr;
        var cad = ""+this.valor;
        var ceros = "", pos, pdec, i;
        for (i=0; i < dec; i++)
            ceros += '0';
        pos = cad.indexOf('.')
        if (pos < 0)
            cad = cad+"."+ceros;
        else
        {
            pdec = cad.length - pos -1;
            if (pdec <= dec)
            {
                for (i=0; i< (dec-pdec); i++)
                    cad += '0';
            }
            else
            {
                num = num*Math.pow(10, dec);
                num = Math.round(num);
                num = num/Math.pow(10, dec);
                cad = new String(num);
            }
        }
        pos = cad.indexOf('.')
        if (pos < 0) pos = cad.lentgh
        if (cad.substr(0,1)=='-' || cad.substr(0,1) == '+') 
            signo = 4;
        if (miles && pos > signo)
            do{
                expr = /([+-]?\d)(\d{3}[\.\,]\d*)/
                cad.match(expr)
                cad=cad.replace(expr, RegExp.$1+','+RegExp.$2)
            }
            while (cad.indexOf(',') > signo)
        if (dec<0) cad = cad.replace(/\./,'')
        return cad;
    }
}

function trim(cad){
    for(i=0; i<cad.length; )
    {
        if(cad.charAt(i)==" ")
            cad=cad.substring(i+1, cad.length);
        else
            break;
    }

    for(i=cad.length-1; i>=0; i=cad.length-1)
    {
        if(cad.charAt(i)==" ")
            cad=cad.substring(0,i);
        else
            break;
    }

    return cad;
}

 
function jsSoloNumerosEnteros(){ 
	
    if (window.event && window.event.keyCode == 13)
        return true
    if (window.event && window.event.keyCode >= 48 && window.event.keyCode <= 57 )
        return true
    return false
}


function masksonly(cadena, myfield, e, dec)
{
    var key;
    var keychar;
 
    if (window.event)
        key = window.event.keyCode;
    else if (e)
        key = e.which;
    else
        return true;
    keychar = String.fromCharCode(key);
 
    if ((key==null) || (key==0) || (key==8) ||
        (key==9) || (key==13) || (key==27) )
        return true;

    else if (((cadena).indexOf(keychar) > -1))
        return true;
 
    else if (dec && (keychar == "."))
    {
        myfield.form.elements[dec].focus();
        return false;
    }
    else
        return false;
}
function formatMoney (theNumber,theCurrency,theThousands,theDecimal) {
    theNumber = theNumber.replace(/,/g,"");
    var strNumber = "";
    var theDecimalDigits = "00";
    if ( theNumber.indexOf('.') >= 0 ) {
        strNumber = theNumber.split('.');
        theDecimalDigits = strNumber[1];
        if (strNumber[0]=='') theNumber = '0'
        else theNumber = ""+Math.floor(theNumber);
        if (theDecimalDigits=='') theDecimalDigits='00';
    }
    if (theNumber=='') theNumber = '0'
    else theNumber = ""+Math.floor(theNumber);
    /*
            var theDecimalDigits = Math.round( (theNumber*100) - (Math.floor(theNumber)*100));
            theDecimalDigits= ""+ (theDecimalDigits + "0").substring(0,2);
            */
    var theOutput = theCurrency;
    for (x=0; x<theNumber.length; x++) {
        theOutput += theNumber.substring(x,x+1);
        if (isThousands(theNumber.length-x-1) && (theNumber.length-x-1!=0)) {
            theOutput += theThousands;
        };
    };
    theOutput += theDecimal + theDecimalDigits;
    return theOutput;
}


function isThousands(position)
{
    if (Math.floor(position/3)*3==position) return true;
    return false;
};

function jsOnlyAlfaNumeric(){
    if (window.event && window.event.keyCode == 13)
        return true;
    if (window.event && window.event.keyCode >= 65 && window.event.keyCode <= 90 )
        return true;
    if (window.event && window.event.keyCode >= 97 && window.event.keyCode <= 122 )
        return true;
    if (window.event && window.event.keyCode >= 48 && window.event.keyCode <= 57 )
        return true;
    if (window.event && window.event.keyCode == 209 )
        return true;
    if (window.event && window.event.keyCode == 241 )
        return true;
    return false;
}  
  
function isNumberKey(evt,objvalue)
{
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode!=46) )
        return false;
    if ( (charCode==46) && (objvalue.indexOf('.') != -1) ) {
        return false;
    }
    return true;
}  

function isNumberKey(evt,objvalue,numofdecimals)
{
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode==8 || charCode==37 || charCode==38 || charCode==39 || charCode==40)
        return true;
    if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode!=46))
        return false;
    if ( (charCode==46) && (objvalue.indexOf('.') != -1) ) {
        return false;
    }
            
    if(objvalue.indexOf('.') != -1 && objvalue.substring(objvalue.indexOf('.'),objvalue.length).length > numofdecimals )
        return false;

    return true;
}
    
function keypress(keypressEvent,method){
    if(isEnterKeypress(keypressEvent)){
        doPost(method);
    }
}
    
function isEnterKeypress(keypressEvent){
    if(window.event && window.event.keyCode == 13){
        window.event.keyCode=0;
        return true;
    }else{
        if(keypressEvent && keypressEvent.which == 13){
            return true;
        }
    }
    return false;
}

//setting ssl pages
function redirectToHttps() {         
    if (window.location.port != ''){
        var httpURL = window.location.hostname + ":" + window.location.port + window.location.pathname;
    } else {
        var httpURL = window.location.hostname + window.location.pathname;
    }
    var httpsURL = "https://" + httpURL ; 
    //alert(httpsURL);
    top.location = httpsURL ; 
} 

//if (sslpage) { redirectToHttps();}

//It's used when the user edits the messages of "SMS Trusted", "SMS Reminder" and "SMS Acknowledge"
function filterKeyPressed(e) {
    var key;
    if(window.event)
        key=window.event.keyCode;
    else
        key = e.which;

    if ( (key < 48 || key > 58) && (key < 65 || key > 90) && (key < 97 || key > 122)
        && (key !=46) && (key !=8) && (key !=60) && (key !=62) && (key !=32) && (key !=45) && (key !=95)){

        if(window.event)
            window.event.keyCode=0;
        return false;
    }
    return true;
}
//

//validate the "SMS Trusted", "SMS Reminder" and "SMS Acknowledge"
function validateSMSText(text){
    var pattern=/^(([a-zA-Z0-9._-]|:)*(<[a-zA-Z_-]+>)*)*$/;

    var arrayOfStrings =text.split(' ');
    for (var i=0; i < arrayOfStrings.length; i++) {
        if(!pattern.test(arrayOfStrings[i]))
            return false;
    }
    return true;
}

function formatText(element){
    if(navigator.appName != "Microsoft Internet Explorer"){
        if (element)
            element.innerHTML = element.textContent.split('').join('<wbr>');
    }else{
        if (element)
            element.style.wordBreak="break-all";
    }
}

/**
 *  OpenNew window
 */
function NewWindow(mypage,myname,w,h,scrollbar,resi){
LeftPosition = (screen.width-w)/2
TopPosition = (screen.height-h)/2
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scrollbar+',resizable='+resi+''
window.open(mypage,myname,settings)
}


/**
 * Flash without link
 */
function viewFla2(ruta,ancho,alto,nombre)
{	document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='" + ancho + "' height='" +  alto + "'  name='" +  nombre + "'>");
    document.write("<param name='movie' value='" + ruta + "'>");
    document.write("<param name='quality' value='high'>");
	document.write("<param name='wmode' value='transparent'>");
    document.write("<embed src='" + ruta + "' quality='high' pluginspage='https://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + ancho + "' height='" +  alto + "' wmode='transparent'></embed>");
    document.write("</object>");
}

function viewFlaMenu(ruta,ancho,alto,nombre)
{	document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='" + ancho + "' height='" +  alto + "'  name='" +  nombre + "' id='menu'>");
    document.write("<param name='movie' value='" + ruta + "'>");
    document.write("<param name='quality' value='high'>");
	document.write("<param name='wmode' value='transparent'>");
    document.write("<embed  name='menu' swLiveConnect='true' src='" + ruta + "' quality='high' pluginspage='https://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + ancho + "' height='" +  alto + "' wmode='transparent'></embed>");
    document.write("</object>");
}

/**
 * Flash with link /temporally unavailable
 */
function viewFlaURL(ruta,ancho,alto,nombre,url) {
    document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='" + ancho + "' height='" +  alto + "'  name='" +  nombre + "'>");
    document.write("<param name='movie' value='" + ruta + "'>");
    document.write("<param name='quality' value='high'>");
    document.write("<param name='FlashVars' value='bann_url=" + url + "'/>");
    document.write("<param name='wmode' value='transparent'>");
    document.write("<embed src='" + ruta + "' FlashVars='bann_url=" + url + "' quality='high' pluginspage='https://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + ancho + "' height='" +  alto + "' wmode='transparent'></embed>");
    document.write("</object>");
}

/**
 * function to change language
 */
function changeLocale(){
    document.LocaleForm.submit();
}

var sslpage = false; //used for...?

/**
 * functions to replace html anchors, iexplorer puts # in the title when the browser is refreshed.
 */
function goTo(anchor){
    document.location.href = anchor;
}
function goToTop(){
    window.scrollTo(0, 0);
}

function generate_address( username, showname ) {
    var domain = "loc-aid.com";
    var atsign = "&#64;";
    var addr = username + atsign + domain;
    if (showname == "") {showname=addr}
    var showaddr = showname;
    document.write(
      "<" + "a" + " " + "href=" + "mail" + "to:" + addr + ">" +
      showaddr +
      "<\/a>");
}

function generate_address2( username, showname ) {
    var domain = "LOC-AID.com";
    var atsign = "&#64;";
    var addr = username + atsign + domain;
    if (showname == "") {showname=addr}
    var showaddr = showname;
    document.write(
      "<" + "a" + " " + "href=" + "mail" + "to:" + addr + ">" +
      showaddr +
      "<\/a>");
}