CLEI_es = {

necessary_input:null,
necessary_txt:null,
app_form:null,
sbt_btn: null,
cf_ol:null,
nav_box_el: null,
nav_box: 'cf-sb',
labels: [],
fields: [],
lab_fields: [],
stop: null,
page: null,
fieldsets: null,

setOnClick:function(page){
this.stop = Number(page);
this.app_form = document.getElementById('cforms2form');
this.sbt_btn = document.getElementById('sendbutton2');
this.page = 1;
this.app_form.onsubmit = function (){
return CLEI_es.sub_app();
}
this.layout_nav();

},

//Class elements
classElements: function(classSearch){
var classElements = [];
var els = this.app_form.getElementsByTagName('*');
var elsLen = els.length;
var pattern = new RegExp('(^|\\\\s)'+classSearch+'(\\\\s|$)');
for (i = 0, j = 0; i < elsLen; i++) {
if ( pattern.test(els[i].className) ) {
classElements[j] = els[i];
j++;
}
}
return classElements;
},

//The onsubmit function
sub_app: function(){
this.check_page();

},


//Checks the first page for proper information
check_page:function(){

this.necessary_input = this.getElementsByClassName('fldrequired', this.app_form);
this.necessary_txt = this.getElementsByClassName('reqtxt', this.app_form);
var forloop = this.necessary_input.length;
var stop = false;


for(var i = 0; i < forloop; i++){
if(!this.necessary_input[i].value){ 
this.necessary_input[i].style.borderStyle = 'solid';
this.necessary_input[i].style.borderWidth = 'thin';
this.necessary_input[i].style.color = 'red';
this.necessary_txt[i].style.color = 'red';
stop = true; 

}
else{

this.necessary_input[i].style.borderStyle = 'none';
this.necessary_txt[i].style.color = "#888";
}
}

if(stop){ return false;}
else {return true;}

},

// Add the Menu Items

addMenuItem: function(val) {

var numi = this.nav_box_el[0];
var newdiv = document.createElement('div');
var divIdName = 'layout_nav';
var id = 'sendbutton' + val;
var innerHTML = '<input type="buttom" value="'+ val +'" class="sendbutton" id="'+ id +'" name="sendbutton2" onClick="CLEI_es.switch_page(this);"/>';
newdiv.setAttribute('id',divIdName);
newdiv.innerHTML = innerHTML;
this.sbt_btn = numi.childNodes[0];
this.sbt_btn.style.display = 'none';
numi.appendChild(newdiv);
},

switch_page: function(elem){

switch(elem.id){

case 'sendbutton1':
if(this.page == 2){
this.show_page(elem);
this.classElements('sendbutton')[1].value = '2';
}
break;

case 'sendbutton2':
if(this.page == 1)
if(this.check_page())
this.show_page(elem);
if(this.page == 2 && elem.value == 'Submit'){
this.app_form.submit();
}else if(this.page == 2)
elem.value = 'Submit';


break;

}



},


//show the correct page
show_page: function(btn){

switch(this.page){

case 1:
this.page = 2;
for(i=this.stop; i < this.labels.length; i++){
this.labels[i].style.display = 'block';

}
for(i=0; i < this.stop; i++){
this.labels[i].style.display = 'none';
if(i < 3){this.fieldsets[i].style.display = 'none';}
}


break;

case 2:
this.page = 1;
for(i=this.stop; i < this.labels.length; i++){
this.labels[i].style.display = 'none';
}
for(i=0; i < this.stop; i++){
this.labels[i].style.display = 'block';
if(i < 3){this.fieldsets[i].style.display = 'block';}
}


break;



}

},

//SetNavBoxEl
setNavBoxEl: function(classSearch) {
var classElements = [];

var els = this.app_form.getElementsByTagName('*');
var elsLen = els.length;
var pattern = new RegExp('(^|\\\\s)'+classSearch+'(\\\\s|$)');
for (i = 0, j = 0; i < elsLen; i++) {
if ( pattern.test(els[i].className) ) {
classElements[j] = els[i];
j++;
}
}
this.nav_box_el = classElements;
},


//Sets the layout for the entire form, and
//loads up the css styles
layout_nav: function(){
this.setNavBoxEl(this.nav_box);
this.labels = this.app_form.getElementsByTagName('li');
this.fieldsets = this.app_form.getElementsByTagName('fieldset');


for(i=2; i > 0; i--){
this.addMenuItem(i);

}

for(i=this.stop; i < this.labels.length; i++){
this.labels[i].style.display = 'none';
}

},

//A function used to the find all the necessary class Elements
//class name.
getElementsByClassName: function(classname, node)  {
    if(!node){ node = document.getElementsByTagName("body")[0];}
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++){
        if(re.test(els[i].className)){a.push(els[i]);}}
    return a;
}

};