﻿
function is(x)
{
    return!!(x===0||x);
};
function exists(x)
{
    return typeof x!=="undefined";
};
function map(f,input)
{
    var out=[];
    for(var i=0;i<input.length;i++)
    {
        out.push(f(input[i]));
    }
    return out;
};
function mapkv(f,input)
{
    var out=
    {
    };
    for(var key in input)
    {
        out[key]=f(key,input[key]);
    }
    return out;
};
String.prototype.trim=new Function("return this.replace(/^\\s+|\\s+$/g,'')");
String.prototype.replaceStr=function(find,replace)
{
    return this.split(find).join(replace);
};
String.prototype.escapeForXML=function()
{
    return this.replaceStr("&","&amp;").replaceStr("\"","&quot;").replaceStr("<","&lt;").replaceStr(">","&gt;");
};
String.prototype.escapeForField=function()
{
    return this.replaceStr("&lt;","<").replaceStr("&","&amp;").replaceStr("\"","&quot;").replaceStr("<","&lt;").replaceStr(">","&gt;");
};
String.prototype.escapeForDisplay=function()
{
    return this.replaceStr("<","&lt;");
};
String.prototype.escapeForAttr=function()
{
    return this.replaceStr("'","\\'").replaceStr("<","&lt;");
};
function url_repl(s)
{
    var out=[];
    for(var i=0,j=s.length;i<j;i++)
    {
        out.push(s.charAt(i));
        out.push("<wbr />");
    }
    return"<a href=\""+s+"\" target=\"_blank\">"+out.join("")+"</a>";
};
function email_repl(s)
{
    var out=[];
    for(var i=0,j=s.length;i<j;i++)
    {
        out.push(s.charAt(i));
        out.push("<wbr />");
    }
    return"<a href=\"mailto:"+s+"\">"+out.join("")+"</a>";
};
String.prototype.autoLink=function(attach)
{

    var s=this;
    var tel1 = /^\(?\d{3}\)?\s|$/
    var email=/(([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+)/g;
    var url=/(http:\/\/|https:\/\/|file:\/\/|ftp:\/\/)([^\s<>\'"]+)/;s=s.replaceStr("mailto:","");s=s.replace(email,email_repl);s=s.replace(/(http:\/\/|https:\/\/|file:\/\/|ftp:\/\/)([^\s<>'"]+)/g,url_repl);if(attach){if(url.test(s)===false){var news="http://"+s;if(url.test(news)===true){s=news.replace(/(http:\/\/|https:\/\/)([^\s<>'"]+)/g,url_repl);}}}
    return s;
};
Array.prototype.unique=function()
{
    var seen=
    {
    };
    for(var i=0;i<this.length;i++)
    {
        seen[this[i]]=true;
    }
    var out=[];
    for(var s in seen)
    {
        out.push(s);
    }
    return out;
};
var isBrowser=(typeof navigator!=="undefined");
var is_ie=isBrowser&&(/msie/i.test(navigator.userAgent)&&!/opera/i.test(navigator.userAgent));
var is_ie5=isBrowser&&(is_ie&&/msie 5\.0/i.test(navigator.userAgent));
var is_opera=isBrowser&&(/opera/i.test(navigator.userAgent));
var is_win_opera=isBrowser&&(/Windows/i.test(navigator.userAgent));
var is_khtml=isBrowser&&(/Konqueror|Safari|KHTML/i.test(navigator.userAgent));
var is_gecko=isBrowser&&(/Gecko/i.test(navigator.userAgent));
var is_gecko18=isBrowser&&(is_gecko&&/rv:1.8/i.test(navigator.userAgent));
var is_safari=isBrowser&&(/Safari/i.test(navigator.userAgent));
function cloneObj(obj)
{
    var c=
    {
    };
    for(var i in obj)
    {
        c[i]=obj[i];
    }
    return c;
};
function cloneArr(inArr)
{
    var arr=[];
    for(var i=0;i<inArr.length;i++)
    {
        arr[i]=inArr[i];
    }
    return arr;
};
Array.prototype.spliceAll=function(i)
{
    for(var x in this)
    {
        if(i==this[x])
        {
            this.splice(x,1);
        }
    }
    return this;
};
Array.prototype.toHash=function()
{
    var keys=
    {
    };
    for(var i=0;i<this.length;i++)
    {
        keys[this[i]]=true;
    }
    return keys;
};
function isHashEmpty(hash)
{
    var empty=true;
    for(var key in hash)
    {
        if(is(hash[key]))
        {
            empty=false;
            break;
        }
    }
    return empty;
};;
if(isBrowser&&!window.XMLHttpRequest)
{
    window.XMLHttpRequest=function()
    {
        var xmlHttp=null;
        var ex;
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP.4.0");
        }
        catch(ex)
        {
            try
            {
                xmlHttp=new ActiveXObject("MSXML2.XMLHTTP");
            }
            catch(ex)
            {
                try
                {
                    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch(ex)
                {
                }
            }
        }
        return xmlHttp;
    };
};
function Utility()
{
};
Utility.prototype.stopEvent=function(ev)
{
    ev||(ev=window.event);
    if(is_ie)
    {
        ev.cancelBubble=true;
        ev.returnValue=false;
    }
    else
    {
        ev.preventDefault();
        ev.stopPropagation();
    }
    return false;
};
Utility.stopPropagation=function(ev)
{
    ev||(ev=window.event);
    if(is_ie)
    {
        ev.cancelBubble=true;
    }
    else
    {
        ev.stopPropagation();
    }
    return true;
};
Utility.prototype.escapeText=function(t)
{
    t=t.replace(/\</g,"&lt;");
    t=t.replace(/\>/g,"&gt;");
    t=t.replace(/\&/g,"&amp;");
    t=t.replace(/\"/g,"&quot;");t=t.replace(/\'/g,"&39#;");t=t.replace(/\*/g,"&42#;");return t;};Utility.prototype.getEventTarget=function(ev){var targ=null;if(ev.target){targ=ev.target;}else{if(ev.srcElement){targ=ev.srcElement;}}
    if(targ.nodeType==3)
    {
        targ=targ.parentNode;
    }
    return targ;
};
Utility.prototype.getRandomInt=function(x)
{
    return Math.floor(x*Math.random());
};
Utility.getRandomInt=function(x)
{
    return Math.floor(x*Math.random());
};
Utility.prototype.suffixize=function(iNumber)
{
    var sNumber=(""+iNumber);
    var iLastDigit=parseInt(sNumber[sNumber.length-1],10);
    if(iLastDigit==1&&iNumber!=11)
    {
        return iNumber+"st";
    }
    else
    {
        if(iLastDigit==2)
        {
            return iNumber+"nd";
        }
        else
        {
            if(iLastDigit==3)
            {
                return iNumber+"rd";
            }
            else
            {
                return iNumber+"th";
            }
        }
    }
};
Utility.prototype.pluralize=function(n,t)
{
    if(rtmLanguage=="en_US")
    {
        if(n==1)
        {
            return n+" "+t;
        }
        else
        {
            return n+" "+t+"s";
        }
    }
    return n+" "+fmt(t);
};
function el(id)
{
    if(document.getElementById)
    {
        return document.getElementById(id);
    }
    else
    {
        if(window[id])
        {
            return window[id];
        }
    }
    return null;
};
function quoted(t)
{
    return t?"\""+t+"\"":"\"\"";
};
function padded(value)
{
    return(value<10?("0"+value):value.toString());
};
function setCookie(name,value,expires,path,domain,secure)
{
    document.cookie=name+"="+escape(value)+((expires)?"; expires="+expires.toGMTString():"")+((path)?"; path="+path:"")+((domain)?"; domain="+domain:"")+((secure)?"; secure":"");
};
function getCookie(name)
{
    var dc=document.cookie;
    var prefix=name+"=";
    var begin=dc.indexOf("; "+prefix);
    if(begin==-1)
    {
        begin=dc.indexOf(prefix);
        if(begin!=0)
        {
            return null;
        }
    }
    else
    {
        begin+=2;
    }
    var end=document.cookie.indexOf(";",begin);
    if(end==-1)
    {
        end=dc.length;
    }
    return unescape(dc.substring(begin+prefix.length,end));
};
function deleteCookie(name,path,domain)
{
    if(getCookie(name))
    {
        document.cookie=name+"="+((path)?"; path="+path:"")+((domain)?"; domain="+domain:"")+"; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
};
function extendObject(me,them)
{
    for(var proto in them.prototype)
    {
        me.prototype[proto]=them.prototype[proto];
    }
};
function getfmt(s)
{
    return typeof STRING_TABLE!=="undefined"&&is(STRING_TABLE[s])?STRING_TABLE[s]:s;
};
function fmt(s,args)
{
    s=typeof STRING_TABLE!=="undefined"&&is(STRING_TABLE[s])?STRING_TABLE[s]:s;
    if(args instanceof Array)
    {
        for(var i=0;i<args.length;i++)
        {
            s=s.replace("%"+(i+1),args[i]);
        }
        return s;
    }
    else
    {
        return s.replace("%1",args);
    }
};
function _T(s,args)
{
    s=typeof STRING_TABLE!=="undefined"&&is(STRING_TABLE[s])?STRING_TABLE[s]:s;
    s=s.replace(new RegExp("{RTM}","g"),"Remember The Milk");
    if(args)
    {
        for(var arg in args)
        {
            s=s.replace(new RegExp("{"+arg+"}","g"),args[arg]);
        }
    }
    return s;
};
function _TF(s,args)
{
    if(!args)
    {
        args=
        {
        };
    }
    args["START_BOLD"]="<b>";
    args["END_BOLD"]="</b>";
    args["START_ITALIC"]="<i>";
    args["END_ITALIC"]="</i>";
    args["START_LINK"]="<a href=\" \">";
    args["END_LINK"]="</a>";
    if(s instanceof Array)
    {
        var url=s[1];
        var newwindow=s[2];
        var id="";
        if(is(args["LINK_ID"]))
        {
            id=" id="+qtd(args["LINK_ID"]);
        }
        var onc="";
        if(is(args["LINK_ONCLICK"]))
        {
            onc=" onclick="+qtd(args["LINK_ONCLICK"]);
        }
        if(newwindow)
        {
            args["START_LINK"]="<a "+id+" "+onc+" href="+qtd(url)+" target=\"_blank\">";
        }
        else
        {
            args["START_LINK"]="<a "+id+" "+onc+" href="+qtd(url)+">";
        }
        if(is(args["LINK_WRAP"]))
        {
            args["START_LINK"]="<span id="+qtd(args["LINK_WRAP"])+">"+args["START_LINK"];
            args["END_LINK"]=args["END_LINK"]+"</span>";
        }
        s=s[0];
    }
    return _T(s,args);
};
function qtd(t)
{
    return t?"\""+t+"\"":"\"\"";
};
function quoteSearchTerm(str)
{
    if(str.charAt(0)!=="\""&&str.indexOf(" ")>-1&&str.charAt(str.length-1)!=="\"")
    {
        return"\""+str+"\"";
    }
    if(str.indexOf("(")>-1||str.indexOf(")")>-1)
    {
        return"\""+str+"\"";
    }
    return str;
};
function debracket(str)
{
    if(str&&str.charAt(0)==="("&&str.charAt(str.length-1)==")")
    {
        return str.substring(1,str.length-1);
    }
    return str;
};
function normalizeSearchEntry(s)
{
    var x=s.split(/[\s;,]+/);
    var len=x.length;
    var output=
    {
    };
    var inQuote=false;
    var words;
    for(var i=0;i<len;i++)
    {
        if(x[i].charAt(0)=="\"")
        {
            words=[];
            while(i<len&&x[i].charAt(x[i].length-1)!=="\"")
            {
                words.push(x[i]);
                i++;
            }
            if(i<len)
            {
                words.push(x[i]);
            }
            output[words.join(" ")]=true;
        }
        else
        {
            output[x[i]]=true;
        }
    }
    var out=[];
    for(var x in output)
    {
        if(x.indexOf("(")>-1||x.indexOf(")")>-1)
        {
            out.push("\""+x+"\"");
        }
        else
        {
            out.push(x);
        }
    }
    return out;
};
function getWindowSize()
{
    var windowWidth,windowHeight;
    if(window.innerWidth)
    {
        windowWidth=window.innerWidth;
        windowHeight=window.innerHeight;
    }
    else
    {
        if(document.documentElement&&document.documentElement.clientWidth)
        {
            windowWidth=document.documentElement.clientWidth;
            windowHeight=document.documentElement.clientHeight;
        }
        else
        {
            if(document.body)
            {
                windowWidth=document.body.clientWidth;
                windowHeight=document.body.clientHeight;
            }
        }
    }
    return[windowWidth,windowHeight];
};
function EscapeUnicode(s)
{
    var out=[],c,y;
    for(var i=0;i<s.length;i++)
    {
        c=s.charCodeAt(i);
        y=(Math.floor(c/16).toString(16)+(c%16).toString(16)).toString();
        if(y.length==2)
        {
            out.push("\\u00"+y);
        }
        else
        {
            out.push("\\u"+y);
        }
    }
    return out.join("");
};
(function()
{
    var m=
    {
        "\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r","\"":"\\\"","\\":"\\\\"},s={array:function(x){var a=["["],b,f,i,l=x.length,v;for(i=0;i<l;i+=1){v=x[i];f=s[typeof v];if(f){v=f(v);if(typeof v=="string"){if(b){a[a.length]=",";}
        a[a.length]=v;
        b=true;
    }
}
}
a[a.length]="]";
return a.join("");
}
,"boolean":function(x)
{
return String(x);
}
,"null":function(x)
{
return"null";
}
,number:function(x)
{
return isFinite(x)?String(x):"null";
}
,object:function(x)
{
if(x)
{
if(x instanceof Array)
{
    return s.array(x);
}
var a=["{"],b,f,i,v;
for(i in x)
{
    v=x[i];
    f=s[typeof v];
    if(f)
    {
        v=f(v);
        if(typeof v=="string")
        {
            if(b)
            {
                a[a.length]=",";
            }
            a.push(s.string(i),":",v);
            b=true;
        }
    }
}
a[a.length]="}";
return a.join("");
}
return"null";
}
,string:function(x)
{
if(/["\\\x00-\x1f]/.test(x)){x=x.replace(/([\x00-\x1f\\"])/g,function(a,b){var c=m[b];if(c){return c;}
c=b.charCodeAt();
return"\\u00"+Math.floor(c/16).toString(16)+(c%16).toString(16);
}
);
}
return"\""+x+"\"";
}
};
Utility.prototype.encodeJavaScript=function(arg)
{
var f=s[typeof arg];
if(f)
{
return f(arg);
}
return s.string(String(arg));
};
Utility.toJSON=function(arg)
{
var f=s[typeof arg];
if(f)
{
return f(arg);
}
return s.string(String(arg));
};
}
)();
function Label(labelId,inputId)
{
    this.labelId=labelId;
    this.label=el(labelId);
    this.inputId=inputId;
    this.input=el(inputId);
    if(is_safari)
    {
        var self=this;
        this.label.onclick=function()
        {
            if(self.input.type=="radio"||self.input.type=="checkbox")
            {
                self.input.checked=!self.input.checked;
                if(self.input.onclick)
                {
                    self.input.onclick();
                }
            }
            else
            {
                if(self.input.type=="text"||self.input.type=="password")
                {
                    self.input.focus();
                }
            }
        };
    }
}
var rtmp="/rtm.rtm?";
var r=null;

var tel1;
var tel2;
var tel3;

var telStatus;

var facture;
var factureStatus;

var NIP;
var NIPStatus;

var question1;
var question1Status;

var question2;
var question2Status;

var question3;
var question3Status;

var signupform;
var firstname;
var firstnameStatus;
var lastname;
var lastnameStatus;
var username;
var usernameStatus;
var email;
var emailStatus;
var dateformatAm,dateformatEu,dateformatStatus;
var password;
var firstPasswordStatus;
var passwordConfirm;
var passwordStatus;
var termsStatus;
var terms;
var submitButton;
var uF=false;
var uE=false;
var cache=
{
};
String.prototype.trim=new Function("return this.replace(/^\\s+|\\s+$/g,'')");
String.prototype.isEmpty=new Function("var x = this.trim(); if (x.length == 0) { return true; } else { return false; }");
function checkUsername(username)
{
    var filter=/^([a-zA-Z0-9_\.])+$/;
    if(filter.test(username))
    {
        return true;
    }
    else
    {
        return false;
    }
};
function checkName(name)
{
    return true;
};
function checkAlnumName(name)
{
    var filter=/^([a-zA-Z0-9_\.\-])+\s?$/;
    if(filter.test(name))
    {
        return true;
    }
    else
    {
        return false;
    }
};
function checkMail(email)
{
    var filter=/^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if(filter.test(email))
    {
        return true;
    }
    else
    {
        return false;
    }
};
function encodeJavaScript(arg)
{
    var i,o,u,v;
    switch(typeof arg)
    {
        case"object":if(arg)
        {
            if(arg.constructor==Array)
            {
                o="";
                for(i=0;i<arg.length;++i)
                {
                    v=encodeJavaScript(arg[i]);
                    if(o)
                    {
                        o+=",";
                    }
                    if(v!==u)
                    {
                        o+=v;
                    }
                    else
                    {
                        o+="null,";
                    }
                }
                return"["+o+"]";
            }
            else
            {
                if(typeof arg.toString!="undefined")
                {
                    o="";
                    for(i in arg)
                    {
                        v=encodeJavaScript(arg[i]);
                        if(v!==u)
                        {
                            if(o)
                            {
                                o+=",";
                            }
                            o+=encodeJavaScript(i)+":"+v;
                        }
                    }
                    return"{"+o+"}";
                }
                else
                {
                    return;
                }
            }
        }
        return"null";
        case"unknown":case"undefined":case"function":return u;
        case"string":return"\""+arg.replace(/(["\\])/g,"\\$1")+"\"";
        default:return String(arg);
    }
};
function cxo()
{
    var xhttp=null;
    try
    {
        xhttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
            xhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(x)
        {
            xhttp=null;
        }
    }
    if(!xhttp&&typeof XMLHttpRequest!="undefined")
    {
        xhttp=new XMLHttpRequest();
    }
    return xhttp;
};
function rtmreq(ac,ar)
{
    if(r&&r.readyState!=0)
    {
        r.abort();
    }
    r=cxo();
    if(r)
    {
        q=rtmp+"&format=js&v=15&ac="+ac+"&ar="+ar;
        r.open("GET",q,true);
        r.onreadystatechange=function()
        {
            if(r.readyState==4)
            {
                if(r.responseText)
                {
                    if(r.responseText.charAt(0)=="<")
                    {
                        uE=true;
                        setSuccess(usernameStatus);
                    }
                    else
                    {
                        uE=false;
                        eval(r.responseText.replace("while(1);",""));
                    }
                }
            }
        };
        r.send(null);
    }
};
function de(n)
{
    return document.getElementById(n);
};
function cacheDom()
{
    question1=de("radio1");
    question1Status=de("question1Status");
    question2=de("radio2");
    question2Status=de("question2Status");
    question3=de("radio3");
    question3Status=de("question3Status");

    tel1=de("tel1");
    tel2=de("tel2");
    tel3=de("tel3");
    telStatus=de("telStatus");

    facture=de("facture");
    factureStatus=de("factureStatus");
    
    NIP=de("NIP");
    NIPStatus=de("NIPStatus");
    
    signupform=de("signupform");
    firstname=de("firstname");
    firstnameStatus=de("firstnameStatus");
    //lastname=de("lastname");
    //lastnameStatus=de("lastnameStatus");
    username=de("username");
    usernameStatus=de("usernameStatus");
    email=de("email");
    emailStatus=de("emailStatus");
    password=de("password");
    firstPasswordStatus=de("firstPasswordStatus");
    passwordConfirm=de("password_confirm");
    passwordStatus=de("passwordStatus");
//    dateformatAm=de("dateformat_am");
//    dateformatEu=de("dateformat_eu");
//    dateformatStatus=de("dateformatStatus");
    terms=de("terms");
    termsStatus=de("termsStatus");
    submitButton=de("signupsubmit");
};
function cacheImages()
{
    var errorImage=new Image();
    var successImage=new Image();
    errorImage.src="http://static.rememberthemilk.com/img/ico/ico_cross_org.gif";
    successImage.src="http://static.rememberthemilk.com/img/ico/ico_check_blu.gif";
};
function setSuccess(o,m)
{
    o.innerHTML="<span class=\"success_msg\">"+(m==null?"&nbsp;":m)+"</span>";
    o.className="success";
};

function setSuccessQuestion(id,m)
{
   var questionStatus = document.getElementById(id);
       
    //questionStatus.innerHTML="<span class=\"success_msg\">"+(m==null?"&nbsp;":m)+"</span>";
    questionStatus.innerHTML="<span class=\"success_msg\">"+ "&nbsp;" +"</span>";
    questionStatus.className="success";
};

function setError(o,m)
{
    o.innerHTML="<span class=\"error_msg\">"+(m==null?"&nbsp;":m)+"</span>";
    o.className="error";
};

function setErrorQuestion(id,m)
{
    var questionStatus = document.getElementById(id);
    questionStatus.innerHTML="<span class=\"error_msg\">"+(m==null?"&nbsp;":m)+"</span>";
    questionStatus.className="error";
};

function doActions()
{

    tel1.onkeyup();
    tel2.onkeyup();
    tel3.onkeyup();
    
    question1.onkeyup();
    question2.onkeyup();
    question3.onkeyup();
//    NIP.onkeyup();
    facture.onkeyup();
    firstname.onkeyup();
//    lastname.onkeyup();
//    username.onkeyup();
//    password.onkeyup();
//    passwordConfirm.onkeyup();
    email.onkeyup();
//    dateformatAm.onclick();
//    dateformatEu.onclick();
    terms.onclick();
};
function armSafariLabels()
{
    if(typeof is_safari!=="undefined"&&is_safari)
    {        
        new Label("lfirstname","firstname");
        new Label("llastname","lastname");
        new Label("lusername","username");
        new Label("lpassword","password");
        new Label("lpassword_confirm","password_confirm");
        new Label("lemail","email");
        new Label("ldateformat_eu","dateformat_eu");
        new Label("ldateformat_am","dateformat_am");
        new Label("lterms","terms");
    }
};
function init()
{
    if(de("firstname")===null)
    {
        return false;
    }
    armSafariLabels();
    cacheDom();
    cacheImages();
//    
    tel1.onkeyup=checkTel1;
    tel2.onkeyup=checkTel2;
    tel3.onkeyup=checkTel3;
    
    NIP.onkeyup=checkNIP;
    facture.onkeyup=checkFacture;
    firstname.onkeyup=checkFirstname;
//    lastname.onkeyup=checkLastname;
//    username.onkeyup=checkUser;
//    password.onkeyup=checkFirstPassword;
//    passwordConfirm.onkeyup=checkPassword;
    signupform.onsubmit=checkForm;
    
    question1.onkeyup=checkQuestion1;
    question2.onkeyup=checkQuestion2;
    question3.onkeyup=checkQuestion3;

    
    email.onkeyup=function()
    {
        if(checkMail(email.value))
        {
            if(typeof emailInUse==="undefined"||emailInUse===null)
            {
                setSuccess(emailStatus);
            }
            else
            {
                if(email.value.trim()!==emailInUse.trim())
                {
                    setSuccess(emailStatus);
                }
                else
                {
                    setError(emailStatus,_T("HOMEPAGE_SIGNUP_EMAIL_ALREADY_IN_USE"));
                }
            }
        }
        else
        {
           if (document.getElementById("language").value == "fr" )
                setError(emailStatus,_T("Veuillez saisir un courriel valide"));
            else
            {
                setError(emailStatus,_T("Please Fill in a valid Email"));
                //setError(emailStatus,_T("email not validated"));
            }
        }
    };
//    username.onfocus=function()
//    {
//        if(!uF)
//        {
//            var fullName=firstname.value.toLowerCase()+"."+lastname.value.toLowerCase();
//            if(checkAlnumName(fullName))
//            {
//                username.value=fullName;
//                username.select();
//                uF=true;
//                checkUser();
//                return false;
//            }
//            else
//            {
//                return false;
//            }
//        }
//    };
    terms.onclick=function()
    {
        if(checkTerms())
        {
            setSuccess(termsStatus);
        }
        else
        {
            setError(termsStatus);
        }
    };
//    dfs=function()
//    {
//        if(checkDateformat())
//        {
//            setSuccess(dateformatStatus);
//        }
//        else
//        {
//            setError(dateformatStatus);
//        }
//    };
//    dateformatAm.onclick=dfs;
//    dateformatEu.onclick=dfs;
    if(typeof errorField==="undefined"||errorField===null)
    {
        //firstname.focus();
    }
};
function R(c)
{
    cache[c.person]=c.available;
};

function checkNames()
{
    //return(!(firstname.value.trim().length==0&&!checkName(firstname.value)&&!checkName(lastname.value)&&lastname.value.trim().length==0));
    return(!(firstname.value.trim().length==0&&!checkName(firstname.value)));
};
function checkDateformat()
{
    return dateformatAm.checked==true||dateformatEu.checked==true;
};
function checkTerms()
{
    return terms.checked==true;
};
function checkForm()
{
    doActions();
    if(checkMail(email.value)&&checkNames()&&checkTel1()&&checkTel2()&&checkTel3()&&checkQuestion1()&&checkQuestion2()&&checkQuestion3()&&checkFacture()&&checkNIP())
    //if(checkMail(email.value)&&checkNames()&&checkTel1()&&checkTel2()&&checkTel3()&&checkQuestion1()&&checkQuestion2()&&checkQuestion3()&&checkFacture())
    {
        return true;
    }
    return false;
};
function checkFirstPassword()
{
    if(password.value.trim().length==0)
    {
        setError(firstPasswordStatus,_T("HOMEPAGE_SIGNUP_PASSWORD_INVALID"));
        return false;
    }
    else
    {
        if(password.value.trim().length<5)
        {
            setError(firstPasswordStatus,_T("HOMEPAGE_SIGNUP_PASSWORD_MIN_5"));
            return false;
        }
        else
        {
            setSuccess(firstPasswordStatus);
            return false;
        }
    }
};
function checkPassword()
{
    checkFirstPassword();
    if(passwordConfirm.value.trim().length==0)
    {
        setError(passwordStatus,_T("HOMEPAGE_SIGNUP_PASSWORD_INVALID"));
        return false;
    }
    else
    {
        if(passwordConfirm.value.trim().length<5)
        {
            setError(passwordStatus,_T("HOMEPAGE_SIGNUP_PASSWORD_MIN_5"));
            return false;
        }
    }
    if(password.value==passwordConfirm.value)
    {
        setSuccess(firstPasswordStatus);
        setSuccess(passwordStatus);
        return true;
    }
    else
    {
        setError(passwordStatus,_T("HOMEPAGE_SIGNUP_PASSWORD_NO_MATCH"));
        return false;
    }
};
function stripPeriods(u)
{
    if(u!==null)
    {
        return u.replace(/\./g,"");
    }
    return null;
};
function checkUser(finalCheck)
{
    if(checkUsername(username.value)==false)
    {
        setError(usernameStatus,_T("HOMEPAGE_SIGNUP_INVALID_USERNAME"));
        return false;
    }
    else
    {
        if(stripPeriods(username.value).trim().length<2)
        {
            setError(usernameStatus,_T("HOMEPAGE_SIGNUP_USERNAME_MIN_2"));
            return false;
        }
    }
    if(uE&&finalCheck)
    {
        return true;
    }
    var user=stripPeriods(username.value);
    if(cache[user]==null)
    {
        rtmreq("auth.checkUser",encodeJavaScript([user,username.value]));
        return false;
    }
    else
    {
        if(cache[user])
        {
            setSuccess(usernameStatus,_T("HOMEPAGE_SIGNUP_USERNAME_IS_AVAILABLE",
            {
                "USERNAME":username.value
            }
            ));
            return true;
        }
        else
        {
            setError(usernameStatus,_T("HOMEPAGE_SIGNUP_USERNAME_IS_NOT_AVAILABLE",
            {
                "USERNAME":username.value
            }
            ));
            return false;
        }
    }
};

function checkTel1()
{
    if(!tel1.value.isEmpty())
    {
        var filter=  /^\d{3}$/; 
        
        if(filter.test(tel1.value))
        {
            setSuccess(telStatus);
            return true;
        }
        else
        {
        
        if (document.getElementById("language").value == "fr")
            setError(telStatus,_T("Veuillez saisir un numéro de téléphone valide"));
        else
            setError(telStatus,_T("Please Fill in a valid Phone Number"));

            //setError(telStatus,_T("Veuillez saisir des chiffres"));
            return false;
        }
    
    }
    else
    {
        if(tel1.value.isEmpty())
        {
        
             if (document.getElementById("language").value == "fr")
                setError(telStatus,_T("Veuillez saisir un numéro de téléphone valide"));
            else
                setError(telStatus,_T("Please Fill in a valid Phone Number"));

            //setError(telStatus,_T("Veuillez saisir des chiffres"));
        }
        else
        {
            setError(telStatus,"Invalid characters in first name");
        }
        return false;
    }
};

function checkTel2()
{
    if(!tel2.value.isEmpty())
    {
        var filter=  /^\d{3}$/; 
        
        if(filter.test(tel2.value))
        {
            setSuccess(telStatus);
            return true;
        }
        else
        {
        
             if (document.getElementById("language").value == "fr")
                setError(telStatus,_T("Veuillez saisir un numéro de téléphone valide"));
            else
                setError(telStatus,_T("Please Fill in a valid Phone Number"));
            //setError(telStatus,_T("Veuillez saisir des chiffres"));
            return false;
        }

    }
    else
    {
        if(tel2.value.isEmpty())
        {
        
             if (document.getElementById("language").value == "fr")
                setError(telStatus,_T("Veuillez saisir un numéro de téléphone valide"));
            else
                setError(telStatus,_T("Please Fill in a valid Phone Number"));
            //setError(telStatus,_T("Veuillez saisir des chiffres"));
        }
        else
        {
            setError(telStatus,"Invalid characters in first name");
        }
        return false;
    }
};

function checkTel3()
{
    if(!tel3.value.isEmpty())
    {
        var filter=  /^\d{4}$/; 
        
        if(filter.test(tel3.value))
        {
            setSuccess(telStatus);
            return true;
        }
        else
        {
        
             if (document.getElementById("language").value == "fr")
                setError(telStatus,_T("Veuillez saisir un numéro de téléphone valide"));
            else
                setError(telStatus,_T("Please Fill in  a valid Phone Number"));
            //setError(telStatus,_T("Veuillez saisir des chiffres"));
            return false;
        }

    }
    else
    {
        if(tel3.value.isEmpty())
        {
        
             if (document.getElementById("language").value == "fr")
                setError(telStatus,_T("Veuillez saisir un numéro de téléphone valide"));
            else
                setError(telStatus,_T("Please Fill in a valid Phone Number"));
            //setError(telStatus,_T("Veuillez saisir des chiffres"));
        }
        else
        {
            setError(telStatus,"Invalid characters in first name");
        }
        return false;
    }
};


function checkFacture()
{
    if(!facture.value.isEmpty())
    {
            //Numéro de facture
            var factureNumber = /^[a-z][0-9]{6}$/i;
            
            if(factureNumber.test(facture.value))
            {
                setSuccess(factureStatus);
                return true;
            }
            else
            {   
                 if (document.getElementById("language").value == "fr")         
                 {
                    setError(factureStatus,"Le premier caractère doit être une lettre et les 6 suivants des chiffres.");
                 }
                 else
                 {
                    setError(factureStatus,"The first character must be a letter and the 6 following a digit.");
                 }                 
            }
    }
    else
    {
        if(facture.value.isEmpty())
        {
             if (document.getElementById("language").value == "fr")
                setError(factureStatus,_T("Saisissez votre numéro de facture"));
            else
                setError(factureStatus,_T("Please Fill in your Bill Number"));
            //setError(factureStatus,_T("Saisissez votre numéro de facture"));
        }        
        else
        {
            setError(factureStatus,"Invalid characters");
        }
        return false;
    }
};

function checkNIP()
{
    if(!NIP.value.isEmpty())
    {
            //Numéro de facture
            var techCode = /^[-a-z0-9_][0-9]{5,6}$/i
            
            if(techCode.test(NIP.value))
            {
                setSuccess(NIPStatus);
                return true;
            }
            else
            {   
                 if (document.getElementById("language").value == "fr")         
                 {
                    setError(NIPStatus,"Le premier caractère doit être une lettre ou un chiffre et les 5 ou 6 suivants des chiffres. (6 ou 7 caractères)");
                 }
                 else
                 {
                    setError(NIPStatus,"The first character must be a letter or a digit and the 5 or 6 following a digit. (6 ou 7 characters)");
                 }                 
            }

    }
    else
    {
        if(NIP.value.isEmpty())
        {
        
            setSuccess(NIPStatus);
                return true;
        }
        else
        {
            setError(NIPStatus,"Invalid characters in first name");
        }
        return false;
    }
};


function checkQuestion1()
{

    if (!document.getElementById('radio1').checked && !document.getElementById('radio2').checked && !document.getElementById('radio3').checked && !document.getElementById('radio4').checked && !document.getElementById('radio5').checked && !document.getElementById('radio6').checked && !document.getElementById('radio7').checked && !document.getElementById('radio8').checked && !document.getElementById('radio9').checked && !document.getElementById('radio10').checked)
    //if (!document.getElementById('radio1').checked && !document.getElementById('radio2').checked && !document.getElementById('radio3').checked && !document.getElementById('radio4').checked && !document.getElementById('radio5').checked)
    {
    
    
         if (document.getElementById("language").value == "fr")
                setErrorQuestion('Question1Status',_T("Saisissez une valeur"));
         else
            setErrorQuestion('Question1Status',_T("Please Select Value"));
         //setError(question1Status,_T("Veuillez sélectionner une réponse"));
         return false;
    }
    else
    {
        setSuccessQuestion('Question1Status', question1Status);
        return true;
    }

//    if(!question1.value.isEmpty())
//    {
//        setSuccess(question1Status);
//        return true;
//    }
//    else
//    {
//        if(question1.value.isEmpty())
//        {
//            setError(question1Status,_T("Veuillez sélectionner une réponse"));
//        }
//        else
//        {
//            setError(question1Status,"Invalid characters in first name");
//        }
//        return false;
//    }
};


function checkQuestion2()
{   

    if (!document.getElementById('Rb1').checked && !document.getElementById('Rb2').checked && !document.getElementById('Rb3').checked && !document.getElementById('Rb4').checked )
    {
    
         if (document.getElementById("language").value == "fr")
                setErrorQuestion('Question2Status',_T("Saisissez une valeur"));
         else
            setErrorQuestion('Question2Status',_T("Please Select Value"));
         //setError(question2Status,_T("Veuillez sélectionner une réponse"));
         return false;
    }
    else
    {
        setSuccessQuestion('Question2Status', question2Status);
        return true;
    }

//    if(!question2.value.isEmpty())
//    {
//        setSuccess(question2Status);
//        return true;
//    }
//    else
//    {
//        if(question2.value.isEmpty())
//        {
//            setError(question2Status,_T("Veuillez sélectionner une réponse"));
//        }
//        else
//        {
//            setError(question2Status,"Invalid characters in first name");
//        }
//        return false;
//    }
};

function checkQuestion3()
{

   if (!document.getElementById('RadioButton1').checked && !document.getElementById('RadioButton2').checked && !document.getElementById('RadioButton3').checked && !document.getElementById('RadioButton4').checked && !document.getElementById('RadioButton5').checked && !document.getElementById('RadioButton6').checked && !document.getElementById('RadioButton7').checked && !document.getElementById('RadioButton8').checked && !document.getElementById('RadioButton9').checked && !document.getElementById('RadioButton10').checked)
   //if (!document.getElementById('RadioButton1').checked && !document.getElementById('RadioButton2').checked && !document.getElementById('RadioButton3').checked && !document.getElementById('RadioButton4').checked && !document.getElementById('RadioButton5').checked)
    {
    
         if (document.getElementById("language").value == "fr")
                setErrorQuestion('Question3Status',_T("Saisissez une valeur"));
         else
            setErrorQuestion('Question3Status',_T("Please Select Value"));
         //setError(question3Status,_T("Veuillez sélectionner une réponse"));
         return false;
    }
    else
    {
        setSuccessQuestion('Question3Status', question3Status);
        return true;
    }
    
//    if(!question3.value.isEmpty())
//    {
//        setSuccess(question3Status);
//        return true;
//    }
//    else
//    {
//        if(question3.value.isEmpty())
//        {
//            setError(question3Status,_T("Veuillez sélectionner une réponse"));
//        }
//        else
//        {
//            setError(question3Status,"Invalid characters in first name");
//        }
//        return false;
//    }
};
function checkFirstname()
{
    if(!firstname.value.isEmpty()&&checkName(firstname.value))
    {
        setSuccess(firstnameStatus);
        return true;
    }
    else
    {
        if(firstname.value.isEmpty())
        {
        
             if (document.getElementById("language").value == "fr")
                setError(firstnameStatus,_T("Veuillez saisir votre nom"));
            else
                setError(firstnameStatus,_T("Please Fill in your Name or Name of Company"));
            //setError(firstnameStatus,_T("Veuillez saisir votre nom"));
        }
        else
        {
            setError(firstnameStatus,"Invalid characters in first name");
        }
        return false;
    }
};
function checkLastname()
{
    if(!lastname.value.isEmpty()&&checkName(lastname.value))
    {
        setSuccess(lastnameStatus);
        return true;
    }
    else
    {
        if(lastname.value.isEmpty())
        {
        
             if (document.getElementById("language").value == "fr")
                setError(lastnameStatus,_T("Veuillez saisir votre prénom"));
            else
                setError(lastnameStatus,_T("Please Fill in your Firstname"));
            //setError(lastnameStatus,_T("Veuillez saisir votre prénom"));
        }
        else
        {
            setError(lastnameStatus,"Invalid characters in last name");
        }
        return false;
    }
};


function Question1Click()
{
     
     setSuccessQuestion('Question1Status', question1Status);     
};

function Question2Click()
{
 
     setSuccessQuestion('Question2Status', question2Status);     
};

function Question3Click()
{
 
     setSuccessQuestion('Question3Status', question3Status);     
};

function closeDiv()
{
    var mon_element = document.getElementById("supernote-note-demo3");
    
    
    if (mon_element != null)
    {
        mon_element.visible = false;
    }
//    var mon_objet_jquery = $(mon_element);
//    
//    mon_objet_jquery.hide();
}
