All pastes #737980 Raw Edit

Someone

public text v1 · immutable
·published 2007-10-15 22:07 UTC
rendered paste body
function validateField(objForm, fields, i)
{	
	var ajax = new Ajax.Request(
        '/order/validation/validate_field.php',
        {
          method:'post',
          parameters: objForm.serialize(objForm),
          onComplete: 
          	function (oReq)
          	{          		
          		if(oReq.responseText != "1")
          		{
          			document.order_step1.has_errors.value = "1";
          			$('error_'+fields[i]).innerHTML = '<font color="red"><b>(!)</b></font>';
          			
          			if(fields[i] == "confirm_email") 
          			{ 
          			}
          			else
          			{
          				$('stringErrorList').innerHTML = $('stringErrorList').innerHTML + '<li>' + oReq.responseText + '</li>';
          			}
          			
          			$('errorlist').style.display = 'block';
					document.order_step1.has_errors.value = "1";
					return false;
          		}
          		else
          		{
          			$('error_'+fields[i]).innerHTML = '';
          			return true;
          		}
           	}
        }
    );
}

function validateNewAccount(objForm)
{
	/* Check fields */
	var errorList = new Array();
	
	/* Loop */
	$('errorlist').style.display = 'none';
	fields = new Array('password', 'confirm_password', 'first_name','last_name','address_1','phone','city','state','zip','email','confirm_email');
	for(i=0; i<fields.length; i++)
	{
		objForm.validate_field.value = fields[i];
		validateField(objForm, fields, i);
	}
	
	/* Validate Payment Information */
	var chosenService = objForm.serviceChoice.options[objForm.serviceChoice.selectedIndex].value;
	if(chosenService == "ts" || chosenService == "vent" || chosenService == "gs" || chosenService == "reseller")
	{
		var paymentOptionChosen = objForm.paymentOption.options[objForm.paymentOption.selectedIndex].value;
		if(paymentOptionChosen == "cc")
			validateCreditCard(objForm);
	}
}

function validateCreditCard(objForm)
{
	$('error_card_number').innerHTML = '';
	$('stringErrorList').innerHTML = '';
	$('error_card_cvv2').innerHTML = '';
	$('errorlist').style.display = 'none';
		
	if(objForm.card_number.value == "" || objForm.card_number.length < 5)
	{
		$('error_card_number').innerHTML = '<b><font color="red">(!)</b></font>';
       	$('stringErrorList').innerHTML = $('stringErrorList').innerHTML + '<li>Invalid Credit Card Number!</li>';
       	$('errorlist').style.display = 'block';
       	objForm.has_errors.value = 1;
	}
	
	if(objForm.card_cvv2.value == "" || objForm.card_cvv2.length < 2)
	{
		$('error_card_cvv2').innerHTML = '<b><font color="red">(!)</b></font>';
       	$('stringErrorList').innerHTML = $('stringErrorList').innerHTML + '<li>Invalid CVV2 Code!</li>';
       	$('errorlist').style.display = 'block';
       	objForm.has_errors.value = 1;
	}
}

function handleSubmitOrder()
{
	document.order_step1.has_errors.value = 0;
	objForm = $('orderwiz');
	$('stringErrorList').innerHTML = '<ol>';
	
	/* We're using a new account. */
	if(objForm.use_account.value == 0)
	{
		validateNewAccount(objForm);
	}
	else
	{
		validateCurrentAccount(objForm);
	}
		
	if(document.order_step1.has_errors.value == 0)
	{
		alert("errors -> " + document.order_step1.has_errors.value);
//		var ajax = new Ajax.Request(
//    	    '/order/process-order.php',
//    	    {
//    	      method:'post',
//    	      parameters: objForm.serialize(objForm),
//    	      onComplete: handleCompletedOrder
//    	    }
//    	);
	}
}