// JavaScript Document
<!--

function evalSelection(foo) {

	if (foo.name=='selectProduct') { 
		//selectProduct
		if (foo.options[foo.selectedIndex].value=='none selected') { changeDiv('fullReview_questions','none');  changeDiv('FullReviewShippingOption','none'); changeDiv('MBEReview_questions','none');   changeDiv('MBEorStateShippingOption','none'); changeDiv('StateReview_questions','none'); changeDiv('MBEorStateShippingOption','none');}
		if (foo.options[foo.selectedIndex].value=='Full Review') {changeDiv('fullReview_questions','block');  changeDiv('FullReviewShippingOption','block'); changeDiv('MBEReview_questions','none');   changeDiv('MBEorStateShippingOption','none'); changeDiv('StateReview_questions','none'); changeDiv('MBEorStateShippingOption','none');}
		if (foo.options[foo.selectedIndex].value=='MBE Only Review') {changeDiv('MBEReview_questions','block');   changeDiv('MBEorStateShippingOption','block'); changeDiv('fullReview_questions','none');  changeDiv('FullReviewShippingOption','none'); changeDiv('StateReview_questions','none');}
		if (foo.options[foo.selectedIndex].value=='State Only Review') {changeDiv('StateReview_questions','block'); changeDiv('MBEorStateShippingOption','block'); changeDiv('fullReview_questions','none');  changeDiv('FullReviewShippingOption','none'); changeDiv('MBEReview_questions','none');}
	}	
	
	if (foo.name=='selectBarExamDate') { 
		//selectBarExamDate
		if (foo.options[foo.selectedIndex].value=='none selected') { changeDiv('PayLateContract1','none'); changeDiv('PayLateContract2','none'); }
		if (foo.options[foo.selectedIndex].value=='February 2011') { changeDiv('PayLateContract1','block'); changeDiv('PayLateContract2','none'); }
		if (foo.options[foo.selectedIndex].value=='July 2010') { changeDiv('PayLateContract2','block'); changeDiv('PayLateContract1','none'); }
	}
	
	if (foo.name=='selectPaymentOption') { 
		//selectPaymentOption
		if (foo.options[foo.selectedIndex].value=='none selected') { changeDiv('PayLaterContracts','none'); changeDiv('PayLaterCharges','none'); calculateTotal('0'); }
		if (foo.options[foo.selectedIndex].value=='Pay In Full Today') { changeDiv('PayLaterContracts','none'); changeDiv('PayLaterCharges','none'); calculateTotal('0'); }
		if (foo.options[foo.selectedIndex].value=='Study Now, Pay Later') { changeDiv('PayLaterContracts','block'); changeDiv('PayLaterCharges','block'); calculateTotal('1'); }
	}	
				   
}

function calculateTotal(foo) { 

//alert('Product Price: '+productPrice);
//alert('Shipping price: '+shippingPrice);
//alert('Shopping total: '+shoppingTotal);
//alert('Finance charge: '+financeCharge);
//alert('Down payment: '+downPayment);
//alert('Product Price: '+productPrice);
  
	document.getElementById('txtCheckProduct').innerHTML =  "$"+(Math.round(productPrice*100)/100).toFixed(2);
	document.getElementById('productPrice').value = "$"+(Math.round(productPrice*100)/100).toFixed(2);
	document.getElementById('txtCheckShipping').innerHTML = "$"+(Math.round(shippingPrice*100)/100).toFixed(2);
	document.getElementById('shippingPrice').value = "$"+shippingPrice.toFixed(2);
	document.getElementById('txtOrderTotal').innerHTML =    "$"+(Math.round(shoppingTotal*100)/100).toFixed(2);
	document.getElementById('total').value = "$"+(Math.round(shoppingTotal*100)/100).toFixed(2);

	switch(foo)
		{
			case "0":
				document.getElementById('txtFinanceCharge').innerHTML = "";
				document.getElementById('txtDueToday').innerHTML = "";
				document.getElementById('txtRemainingBalance').innerHTML = "";
				document.getElementById('financeCharge').value = "";
				document.getElementById('dueToday').value = "";
				document.getElementById('remainingBalance').value = "";
				
			  break;
			  
			case "1":
				document.getElementById('txtFinanceCharge').innerHTML = "$"+(Math.round(financeCharge*100)/100).toFixed(2);
				document.getElementById('financeCharge').value = "$"+(Math.round(financeCharge*100)/100).toFixed(2);
				document.getElementById('txtDueToday').innerHTML = "$"+(Math.round(downPayment*100)/100).toFixed(2);
				document.getElementById('dueToday').value = "$"+(Math.round(downPayment*100)/100).toFixed(2);
				document.getElementById('txtRemainingBalance').innerHTML = "$"+(shoppingTotal-downPayment+financeCharge).toFixed(2);
				document.getElementById('remainingBalance').value = "$"+(shoppingTotal-downPayment+financeCharge).toFixed(2);
			  break;
		}

}

function resetPaymentOption() { document.getElementById('selectPaymentOption').value = 'none selected';  }

function getStyleObject(objectId) {
    if(document.getElementById && document.getElementById(objectId)) {
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject


function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.display = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	alert("could not find othe div");
	return false;
    }
} // changeObjectVisibility



function switchIfDone(the_form, this_div, next_div, ignoreValidation)
{

  var complete = true;
  for (var loop=0; loop < the_form.elements.length; loop++)
  {
    if (the_form.elements[loop].value == "")
    {
      complete = false;
	 // alert(the_form.elements[loop]);
    }
  }
  if ((complete == true) && (next_div == "finished"))  
  {
  	alert("submitting info");
    submitTheInfo();
  } 
  else if (complete == true || ignoreValidation==true) 
  {	
  	//alert("flipping the switch");
    switchDiv(this_div, next_div);
  } else {
    alert('please complete the form before moving on');
  }
}

function switchDiv(this_div, next_div)
{
  if (getStyleObject(this_div) && getStyleObject(next_div)) {
   // alert("switch 1");
	changeObjectVisibility(this_div, "none");
	//alert("switch 2");
    changeObjectVisibility(next_div, "block");
	//alert("vsibility changed");
  }
}

function changeDiv(the_div,the_change)
{ 
  var the_style = getStyleObject(the_div);
  if (the_style != false) { the_style.display = the_change; }
}


function hideAll()
{
  changeDiv("fullReveiw_questions","none");
  changeDiv("MBEReveiw_questions","none");
  changeDiv("StateReveiw_questions","none"); 
  changeDiv("FullReviewShippingOption","none");
  changeDiv("MBEorStateShippingOption","none");
  changeDiv("PayLateContract1","none");
  changeDiv("PayLateContract2","none");  
}

function setBillingAddress(checked) {
        if (checked) {
                document.getElementById('txtBillingAddress1').value = document.getElementById('txtShippingAddress1').value;
				document.getElementById('txtBillingAddress2').value = document.getElementById('txtShippingAddress2').value;
				document.getElementById('txtBillingTownCity').value = document.getElementById('txtShippingTownCity').value;
				document.getElementById('selectBillingState').value = document.getElementById('selectShippingState').value;
				document.getElementById('txtBillingPostalCode').value = document.getElementById('txtShippingPostalCode').value;
				document.getElementById('selectBillingCountry').value = document.getElementById('selectShippingCountry').value;
        } else {
                document.getElementById('txtBillingAddress1').value = '';
				document.getElementById('txtBillingAddress2').value = '';
				document.getElementById('txtBillingTownCity').value = '';
				document.getElementById('selectBillingState').value = '';
				document.getElementById('txtBillingPostalCode').value = '';
				document.getElementById('selectBillingCountry').value = 'none selected'; //selectShippingCountry		
        }
}


var productPrice;
var shippingPrice;
var shoppingTotal;
var financeCharge;
var downPayment;

function initProcessing(foo) {
	switch(foo)
		{
			case "products":
					var xmlhttp;
					if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
					try{
						xmlhttp.onreadystatechange=function() {
								if(xmlhttp.readyState==4) {
									if (xmlhttp.status==200){ 
											eval(xmlhttp.responseText); 
										}
								  }
							}
						xmlhttp.open("GET","includes/orderProcessing.php?x=001",true);
						xmlhttp.send(null);
					}
					catch(e){
					//suppress error
				   }	
			  break;
			  
			case "shipping":
					var xmlhttp;
					if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
					try{
						xmlhttp.onreadystatechange=function() {
								if(xmlhttp.readyState==4) {
									if (xmlhttp.status==200){ 
											eval(xmlhttp.responseText); 
										}
								  }
							}
						var url="includes/orderProcessing.php?x=002&y="+ document.getElementById('selectProduct').options[document.getElementById('selectProduct').selectedIndex].value;
						xmlhttp.open("GET",url,true);
						xmlhttp.send(null);
						
					}
					catch(e){
					//suppress error
				   }				
			  break;
			  
			case "checkShipping":
					if(document.getElementById('selectShippingCountry').options[document.getElementById('selectShippingCountry').selectedIndex].value!="United States") {
						document.getElementById("selectFullReviewShippingOption").selectedIndex=3;
						document.getElementById("selectFullReviewShippingOption").disabled="disabled";
						document.getElementById("selectMBEorStateShippingOption").selectedIndex=3;
						document.getElementById("selectMBEorStateShippingOption").disabled="disabled";
					} else {
						document.getElementById("selectFullReviewShippingOption").selectedIndex=0;
						document.getElementById("selectFullReviewShippingOption").disabled="";
						document.getElementById("selectMBEorStateShippingOption").selectedIndex=0;
						document.getElementById("selectMBEorStateShippingOption").disabled="";	
					
					}				
			  break;
			  
			case "reviewOrder":
			
					var y=document.getElementById('selectProduct').options[document.getElementById('selectProduct').selectedIndex].value;
					var w=document.getElementById('selectPaymentOption').options[document.getElementById('selectPaymentOption').selectedIndex].value;
					
					if(document.getElementById('selectFullReviewShippingOption').options[document.getElementById('selectFullReviewShippingOption').selectedIndex].value!='none selected') {
						var z= document.getElementById('selectFullReviewShippingOption').options[document.getElementById('selectFullReviewShippingOption').selectedIndex].value;
					} 
					
					if(document.getElementById('selectMBEorStateShippingOption').options[document.getElementById('selectMBEorStateShippingOption').selectedIndex].value!='none selected') {
						var z= document.getElementById('selectMBEorStateShippingOption').options[document.getElementById('selectMBEorStateShippingOption').selectedIndex].value;
					}	
			
					var xmlhttp;
					if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
					try{
						xmlhttp.onreadystatechange=function() {
								if(xmlhttp.readyState==4) {
									if (xmlhttp.status==200){ 
											eval(xmlhttp.responseText);
												document.getElementById('txtCheckProduct').innerHTML = "$"+(Math.round(productPrice*100)/100).toFixed(2);
												document.getElementById('productPrice').value = "$"+(Math.round(productPrice*100)/100).toFixed(2);
												document.getElementById('txtCheckShipping').innerHTML = "$"+shippingPrice.toFixed(2);
												document.getElementById('shippingPrice').value = "$"+shippingPrice.toFixed(2);
												document.getElementById('txtOrderTotal').innerHTML = "$"+(Math.round(shoppingTotal*100)/100).toFixed(2);
												document.getElementById('total').value = "$"+(Math.round(shoppingTotal*100)/100).toFixed(2);
										}
								  }
							}
						var url="includes/orderProcessing.php?x=003&y="+y+"&w="+w+"&z="+z;
						//alert(url);
						xmlhttp.open("GET",url,true);
						xmlhttp.send(null);
					}
					catch(e){
					//suppress error
				   }
			  break;
			  
			case "submitForProcessings":
					changeDiv('formerrors','none');
					var errorCount=0;
					var arrErrors = new Array();
					
					if (!document.getElementById('txtFirstName').value) {
						arrErrors.push('First Name: Please provide your first name.');
					}
					
					if (!document.getElementById('txtLastName').value) {
						arrErrors.push('Last Name: Please provide your last name.');
					}

					//selectProduct
					//selectFullReviewState
					//selectBarExamDate
					//selectOS

					if (!document.getElementById('txtEmail').value) {
						arrErrors.push('E-Mail: Please provide your e-mail address.');
					}
                    
                    if (!document.getElementById('txtConfirmEmail').value) {
						arrErrors.push('Confirm E-Mail: Please confirm your e-mail address.');
					}
                    
                    if (!document.getElementById('txtPhone').value) {
						arrErrors.push('Phone: Please provide your phone number.');
					}                   

					//txtLawSchool
					//txtGraduationDate

                    if (!document.getElementById('txtUsername').value) {
						arrErrors.push('Username: Please choose a username.');
					}
                    
                    if (!document.getElementById('txtPassword').value) {
						arrErrors.push('Password: Please choose a password. Must be at least 6 character and must include letters and numbers.');
					}     
                     
                    if (!document.getElementById('txtPassword2').value) {
						arrErrors.push('Password: Please confirm your password.');
					}  

					//selectSecurityQuestion

                    if (!document.getElementById('txtSecurityQuestionAnswer').value) {
						arrErrors.push('Security question: Please enter the answer to your security question.');
					}
                    
					//txtHowDidYouHear

                    if (!document.getElementById('txtShippingAddress1').value) {
						arrErrors.push('Shipping address 1: Please enter your shipping address.');
					}
                    
					//txtShippingAddress2

                    if (!document.getElementById('txtShippingTownCity').value) {
						arrErrors.push('Shipping town/city: Please enter your shipping town/city.');
					}

					//selectShippingState

                    if (!document.getElementById('txtShippingPostalCode').value) {
						arrErrors.push('Shipping postal code: Please enter your shipping postal code.');
					}
                    
					//selectShippingCountry
					//eula
					//selectPaymentOption
					
					var errorCount=arrErrors.length;
					//alert(errorCount);
					if (errorCount > 0) {
						strError = '<div class="formerror"><h3>Please check the following and try again:</h3><ul>';
						for (i=0;i<errorCount;i++) { if(arrErrors[i]) strError+= '<li>'+arrErrors[i]+'</li>';}
						strError += '</ul></div>';

						changeDiv('formerrors','block');
						changeDiv('next1','none'); changeDiv('next2','none'); changeDiv('next3','none'); changeDiv('next4','none'); changeDiv('next5','none');
						changeDiv('previous1','none'); changeDiv('previous2','none'); changeDiv('previous3','none'); changeDiv('previous4','none');
						changeDiv('part1','block'); changeDiv('part2','block'); changeDiv('part3','block'); changeDiv('part4','block'); changeDiv('part5','block'); changeDiv('part6','block');
						
						document.getElementById('formerrors').innerHTML = strError;
						window.location = "#topForm";
					} 
					else { document.getElementById('frmOrder').submit(); }
			  break;			  
			 
		}
}

// -->