function df_xmlhttpPost(strURL) 
{
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) 
    {
            self.xmlHttpReq = new XMLHttpRequest();
        }
    // IE
        else 
    if (window.ActiveXObject) 
    {
            self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
        self.xmlHttpReq.open('POST', strURL, true);
        self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        self.xmlHttpReq.onreadystatechange = function() 
    {
            if (self.xmlHttpReq.readyState == 4) 
        {
                    df_updatepage(self.xmlHttpReq.responseText);
            
            }
        }
        self.xmlHttpReq.send(df_getdatastring(document.getElementById("dfform"))+df_getdatastring(document.getElementById("dfform2")) );
}


function df_xmlhttpget(obj,strURL) 
{
    this.obj = obj;
    this.strURL = strURL;
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari

    if (window.XMLHttpRequest) 
    {
            self.xmlHttpReq = new XMLHttpRequest();
        }
    // IE
        else 
    if (window.ActiveXObject) 
    {
            self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
      }


    self.xmlHttpReq.open("GET",strURL, true); 

    self.xmlHttpReq.onreadystatechange = function() 
    {
            if (self.xmlHttpReq.readyState == 4) 
            {
                    obj.innerHTML = self.xmlHttpReq.responseText;
            }
     }
     self.xmlHttpReq.send("");
}

function df_buildpage(dfdiv,str)
{
   dfdiv.innerHTML = str;
}

function df_loadpage()
{
    
    
    document.getElementById('register_member_step_1').style.visibility = "visible";
    document.getElementById('register_member_step_2').style.visibility = "hidden";
    document.getElementById('register_member_step_3a').style.visibility = "hidden";
    document.getElementById('register_member_step_3b').style.visibility = "hidden";

    document.getElementById('register_member_step_1').style.display = "block";
    document.getElementById('register_member_step_2').style.display = "none";   
    document.getElementById('register_member_step_3a').style.display = "none";
    document.getElementById('register_member_step_3b').style.display = "none";
              
    document.getElementById('requiredfield').style.visibility = "hidden";
    document.getElementById('requiredfield').style.display = "none";


    document.getElementById('hidden_form').style.visibility = "hidden";
    document.getElementById('hidden_form').style.display = "none";

    var t1 = new df_xmlhttpget(document.getElementById('countrylist'),'/country.html'); 
    var t2 = new df_xmlhttpget(document.getElementById('hidden_form'),'/hiddenform.html'); 



}

function df_gotocreditcard(id,time,country)
{
    var str;
    var form3=document.getElementById("hidden_form");
 //   form3.elements["CHAMP009"].value=id;
    form3.elements["CHAMP200"].value=time;
    form3.elements["CHAMP110"].value = country;
    str ="https://ecom.cimetz.com/telepaie/cgishell.exe/epaie01.exe?"+df_getdatastring(document.dfform3);
	window.location.href = str;   

}

function df_registerstep1() 
{
    if(validateFormOnSubmit(document.dfform))
    {
        document.getElementById('register_member_step_1').style.visibility = "hidden";
        document.getElementById('register_member_step_2').style.visibility = "visible";
	    document.getElementById('register_member').style.visibility = "hidden";
		document.getElementById('register_member').style.display = "none";
        document.getElementById('register_member_step_1').style.display = "none";
        document.getElementById('register_member_step_2').style.display = "block";
        window.scroll(0,0); 
//      df_xmlhttpPost(strURL);
    }
}


function df_registerstep2(id,time) 
{
   var form3=document.getElementById("hidden_form");
  //  form3.elements["CHAMP009"].value = id;
    form3.elements["CHAMP200"].value = time;
    if(validateFormOnSubmit(document.dfform))
    {
    //  df_getdatastring();
        df_xmlhttpPost('/test/register_member_step2a.php');
    }
}

function validateDateBirth(fld,id)
{
    var error = "";
    var str ="";
 //   alert(form.elements["year"].value);
 //      alert(form.elements["month"].value);
 //           alert(form.elements["day"].value);
  
    var Filter = /[0-9]{2}-[0-9]{2}-[0-9]{4}/ ;
    if (!Filter.test(fld.value)) 
    {
 //   alert("filter");
            error = "The required field has formt dd-mm-yyyy.\1n";

    }  
    if (fld.value.length == 0) 
    {
     //   alert("length");
        error = "The required field has not been filled in.\1n";
    }
    if(error!="")
    {

      //  document.getElementById(id).innerHTML = document.getElementById(id).innerHTML.replace('color=#000000>&nbsp;*','color=#ff0000>&nbsp;!!');
     

      
    } else {
        //document.getElementById(id).innerHTML = document.getElementById(id).innerHTML.replace('color=#ff0000>&nbsp;!!','color=#000000>&nbsp;*');
   
 
    }
    return error;
}

function validatecheck(fld,id)
{
    var error = "";
    var str ="";
    if (fld.checked== false) 
    {
   // document.getElementById(id).innerHTML = document.getElementById(id).innerHTML.replace('color=#000000>&nbsp;*','color=#ff0000>&nbsp;!!');
      fld.style.background="#ffffff";

     error = "The required field has not been filled in.\1n";
    } 
    else {
   //     document.getElementById(id).innerHTML = document.getElementById(id).innerHTML.replace('color=#ff0000>&nbsp;!!','color=#000000>&nbsp;*');
           fld.style.background="#ffcccc";
    }
    return error;   
}

function validateEmpty(fld,id) 
{
    var error = "";
    var str ="";
    if (fld.value.length == 0) {
    //document.getElementById(id).innerHTML = document.getElementById(id).innerHTML.replace('color=#000000>&nbsp;*','color=#ff0000>&nbsp;!!');
          fld.style.background="#ffcccc";
     error = "The required field has not been filled in.\1n";
    } else {
       // document.getElementById(id).innerHTML = document.getElementById(id).innerHTML.replace('color=#ff0000>&nbsp;!!','color=#000000>&nbsp;*');
   fld.style.background="#ffffff";
    }
    return error;   
}

function validatePassword(value,id) {
    var error = "";
    if (value == "") {
        error = "You didn't enter a password.\n";
    } else if ((value.length < 8) || (value.length > 150)) {
        error = "The password is the wrong length. \n";

    }
   return error;
}   

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
} 

function validateEmail(fld,id) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    
    if (fld.value == "") {
          error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
          error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
                error = "The email address contains illegal characters.\n";
    } 
    else 
    {
       
    }
    if (fld.value.length == 0) {
   // document.getElementById(id).innerHTML = document.getElementById(id).innerHTML.replace('color=#000000>&nbsp;*','color=#ff0000>&nbsp;!!');
     fld.style.background="#ffcccc";
     error = "The required field has not been filled in.\1n";
    } else {
   //     document.getElementById(id).innerHTML = document.getElementById(id).innerHTML.replace('color=#ff0000>&nbsp;!!','color=#000000>&nbsp;*');
       fld.style.background="#ffffff";
    }
    return error;
}



function validateFormOnSubmit(theForm) 
{
    var reason = "";
 //     reason += validatePassword(theForm.password);
 //     reason += validateEmail(theForm.email);
     //   alert(theForm.elements["name"].value);
    reason += validateEmpty(theForm.elements["name"],'name_id');
    if (reason != "") 
    {
        alert(document.getElementById('requiredfield').innerHTML);
        theForm.elements["name"].focus();
            return false;
    }
    reason += validateEmpty(theForm.elements["surename"],'surename_id');
    if (reason != "") 
    {
        alert(document.getElementById('requiredfield').innerHTML);
        theForm.elements["surename"].focus();
            return false;
    }
    reason += validateEmpty(theForm.elements["nationality"],'nationality_id');
    if (reason != "") 
    {
        alert(document.getElementById('requiredfield').innerHTML);
        theForm.elements["nationality"].focus();
            return false;
    }
    reason += validateEmpty(theForm.elements["street"],'street_id');
    if (reason != "") 
    {
        alert(document.getElementById('requiredfield').innerHTML);
        theForm.elements["street"].focus();
            return false;
    }
    reason += validateEmpty(theForm.elements["number"],'street_id');
    if (reason != "") 
    {
        alert(document.getElementById('requiredfield').innerHTML);
        theForm.elements["number"].focus();
            return false;
    }
    reason += validateEmpty(theForm.elements["postalcode"],'postalcode_id');
    if (reason != "") 
    {
        alert(document.getElementById('requiredfield').innerHTML);
        theForm.elements["postalcode"].focus();
            return false;
    }
    reason += validateEmpty(theForm.elements["city"],'city_id');
    if (reason != "") 
    {
        alert(document.getElementById('requiredfield').innerHTML);
        theForm.elements["city"].focus();
            return false;
    }
    reason += validateEmpty(theForm.elements["country"],'countrylist');
    if (reason != "") 
    {
        alert(document.getElementById('requiredfield').innerHTML);
        theForm.elements["country"].focus();
            return false;
    }   
    reason += validateEmail(theForm.elements["email"],'email_id')
    if (reason != "") 
    {
        alert(document.getElementById('requiredfield').innerHTML);
        theForm.elements["email"].focus();
            return false;
    }
    reason += validatePassword(theForm.elements["password1"].value,'password1_id');
    theForm.elements["password1"].style.background="#ffffff";
    if (reason != "") 
    {
        alert(document.getElementById('requiredfield').innerHTML);
        theForm.elements["password1"].style.background="#ffcccc";
        theForm.elements["password1"].focus();
            return false;
    }

    if(theForm.password1.value!=theForm.elements["password_confirm"].value||reason != "")
    {
//document.getElementById('password2a_id').innerHTML = document.getElementById('password2a_id').innerHTML.replace('color=#000000>&nbsp;*','color=#ff0000>&nbsp;!!');
       theForm.elements["password_confirm"].style.background="#ffcccc";
        alert(document.getElementById('requiredfield').innerHTML);
        theForm.elements["password_confirm"].focus();
        return false;
    }
    else
    {
         theForm.elements["password_confirm"].style.background="#ffffff";
     //   document.getElementById('password2a_id').innerHTML = document.getElementById('password2a_id').innerHTML.replace('color=#ff0000>&nbsp;!!','color=#000000>&nbsp;*');
    }
        theForm.elements["day"].style.background="#ffffff";
        theForm.elements["month"].style.background="#ffffff";
        theForm.elements["year"].style.background="#ffffff";
        
 
  theForm.elements["date_of_birth"].value=theForm.elements["day"].value+"-"+theForm.elements["month"].value+"-"+theForm.elements["year"].value;
 // alert(theForm.elements["date_of_birth"].value);
    reason += validateDateBirth(theForm.elements["date_of_birth"],'date_of_birth_id');
    
    if (reason != "") 
    {
               theForm.elements["day"].style.background="#ffcccc";
        theForm.elements["month"].style.background="#ffcccc";
        theForm.elements["year"].style.background="#ffcccc";    
        theForm.elements["year"].focus();
    
    
    
        alert(document.getElementById('requiredfield').innerHTML);
   
            return false;
    }
    reason += validateEmpty(theForm.orig_country,'orig_country_id');
    if (reason != "") 
    {
        alert(document.getElementById('requiredfield').innerHTML);
        theForm.elements["orig_country"].focus();
            return false;
    }

    reason += validateEmpty(theForm.elements["mothertongue"],'mothertongue_id');
    if (reason != "") 
    {
        alert(document.getElementById('requiredfield').innerHTML);
        theForm.elements["mothertongue"].focus();
            return false;
    }
    reason += validatecheck(theForm.elements["lecturecharter"],'lecturecharter_id');
    if (reason != "") 
    {
        alert(document.getElementById('requiredfield').innerHTML);
        theForm.elements["lecturecharter"].focus();
            return false;
    }
    reason += validatecheck(theForm.elements["principles"],'principles_id');
    if (reason != "") 
    {
        alert(document.getElementById('requiredfield').innerHTML);
        theForm.elements["principles"].focus();
            return false;
    }
    reason += validatecheck(theForm.elements["certification"],'certification_id');
    if (reason != "") 
    {
        alert(document.getElementById('requiredfield').innerHTML);
        theForm.elements["certification"].focus();
            return false;
    }
    showPrice(theForm);
    var form3=document.getElementById("hidden_form");
    form3.elements["CHAMP100"].value = theForm.elements["name"].value;
    form3.elements["CHAMP101"].value = theForm.elements["surename"].value;
    form3.elements["CHAMP104"].value = theForm.elements["email"].value;
    form3.elements["CHAMP005"].value="http://www.members-newropeans.eu/register_member_step2.php?action=pay";
    form3.elements["CHAMP107"].value = theForm.elements["street"].value+" "+theForm.elements["number"].value;
    form3.elements["CHAMP108"].value = theForm.elements["city"].value;
    form3.elements["CHAMP109"].value = theForm.elements["postalcode"].value;
//  document.dfform3.CHAMP110.value = theForm.country.value;
        document.getElementById('warning').style.visibility = "hidden";
    



    return true;
}




function df_getdatastring(theForm) 
{
//alert('hallo');
    var qstr="";
    for ( var i=0;i<theForm.elements.length;i++ )
    {
        var t ="hallo";
        if(theForm.elements[i].type=="checkbox"||theForm.elements[i].type=="radio")
        {
            if(theForm.elements[i].checked==true)
            {
                qstr = qstr+escape(theForm.elements[i].name)+"="+escape(theForm.elements[i].value)+"&";
            }
        }
        else
        {
            qstr = qstr+escape(theForm.elements[i].name)+"="+escape(theForm.elements[i].value)+"&";
        }
    }
    return qstr;
}


function df_updatepage(str)
{
    var id="";
    var time;
    document.getElementById('register_member_step_1').style.visibility = "hidden";
    document.getElementById('register_member_step_2').style.visibility = "hidden";
    document.getElementById('register_member').style.visibility = "hidden";
   
    document.getElementById('register_member').style.display = "none";
    document.getElementById('register_member_step_1').style.display = "none";
    document.getElementById('register_member_step_2').style.display = "none";   
    if(str.indexOf('bank')==0)
    {
        document.getElementById('register_member_step_3a').style.visibility = "visible";
        document.getElementById('register_member_step_3a').style.display = "block";
    }
    if(str.indexOf('paypal')==0)
    {
        document.getElementById('register_member_step_3b').style.visibility = "visible";
        document.getElementById('register_member_step_3b').style.display = "block";
    }
    if(str.indexOf('creditcard')==0)
    {
        id = str.substring(str.indexOf('<id>')+4,str.indexOf('</id>'));
        time = str.substring(str.indexOf('<time>')+6,str.indexOf('</time>'));
        country = str.substring(str.indexOf('<country>')+9,str.indexOf('</country>'));
        df_gotocreditcard(id,time,country);
    }

//alert(str);
//  window.navigate(str);
//   document.getElementById("register_member").innerHTML = str;
}

function showPrice(form)
{
    var vareur;
    var today = new Date( );          
    var birthday = new Date( );      
    var day = form.elements["date_of_birth"].value.substring(0,2);
    var month = form.elements["date_of_birth"].value.substring(3,5);
    var year = form.elements["date_of_birth"].value.substring(6);



    birthday.setMonth(parseInt(day));
    birthday.setDate(parseInt(month));
    birthday.setYear(parseInt(year));


    if (today.getFullYear( ) > birthday.getFullYear( ))
    {  
        yeari=today.getFullYear( ) - birthday.getFullYear( );
    }
    if(yeari<30)
    {
        vareur ="25";
    }
    else
    {
        vareur ="100";
    }

    document.getElementById("dfform3a").elements["amount"].value=vareur;
    document.getElementById("euro1").innerHTML = vareur;
    document.getElementById("euro2").innerHTML = vareur;
    document.getElementById("europart2").innerHTML = vareur;
    document.getElementById("hidden_form").elements["CHAMP201"].value = vareur;


//  var obj = document.getElementById('prices');

//      var datum = document.getElementById('date_of_birth').value;
//        while(obj.hasChildNodes()) 
//        {
//            obj.removeChild(obj.lastChild);
//        }
//        var script = document.createElement('SCRIPT');
//        script.type = 'text/javascript';
//        script.src = '/test/js/js.php?date=' + datum + '&country=' + country;
//        obj.appendChild(script);
}