/*
 * SimpleModal Basic Modal Dialog
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2010 Eric Martin - http://ericmmartin.com
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Revision: $Id: basic.js 254 2010-07-23 05:14:44Z emartin24 $
 */

function validateFormOne() {
    var reqFields = new Array();
    var errstr    = "";

    reqFields["inputPhone1"]     = "Phone";
    reqFields["inputPhone2"]     = "Phone";
    reqFields["inputPhone3"]     = "Phone";


	var phone1 = document.getElementById('inputPhone1').value 
	var phone2 = document.getElementById('inputPhone2').value 
	var phone3 = document.getElementById('inputPhone3').value 

	if (isNaN(phone1)) {
	errstr = errstr + "Phone Number has to contain digits only.\n";
	}
	
		if (isNaN(phone2)) {
	errstr = errstr + "Phone Number has to contain digits only.\n";
	}
	
		if (isNaN(phone3)) {
	errstr = errstr + "Phone Number has to contain digits only.\n";
	}
	
	if (phone1.length != 3) {
	errstr = errstr + "Phone Number has to be 10 digits only.\n";
	}
		
	if (phone2.length != 3) {
	errstr = errstr + "Phone Number has to be 10 digits only.\n";
	}
	if (phone3.length != 4) {
	errstr = errstr + "Phone Number has to be 10 digits only.\n";
	}
    for ( var i in reqFields )
    {
        if ( ! document.getElementById(i).value )
            errstr = errstr + reqFields[i] + " is Required.\n";
    }

    if ( errstr ) {
        alert( errstr );
        return false;
    } else {
  	  document.forms['signUp'].submit();
    	//$('#basic-modal-content').modal();
		return true;
    }
}

function validateFormTwo() {
    var reqFields = new Array();
    var errstr    = "";
    var encrpytedActivation = document.getElementById('encrpytedActivation').value 
	var codeCode = (encrpytedActivation- 626)/2;
	
    reqFields["inputCode"]     = "Activation Code";

    var agreement = document.getElementById('agreementConfirmation').checked 
	var inputCode = document.getElementById('inputCode').value

	if (agreement == false) {
	errstr = errstr + "Terms are Required.\n";
	}
	
	if (codeCode != inputCode) {
	errstr = errstr + "Activation Code is incorrect.\n";
	}

    for ( var i in reqFields )
    {
        if ( ! document.getElementById(i).value )
            errstr = errstr + reqFields[i] + " is Required.\n";
    }

    if ( errstr ) {
        alert( errstr );
        return false;
    } else {
 		//  document.forms['homeMain'].submit();
 		$("#modalPref").slideDown();
		$('#simplemodal-container').css('height','auto');
		$("#modalMaster").slideUp();
		return true;
    }
}

function validateFormThree() {
    var reqFields = new Array();
    var errstr    = "";
	
    reqFields["dealcity"]     = "Deal City";

    for ( var i in reqFields )
    {
        if ( ! document.getElementById(i).value )
            errstr = errstr + reqFields[i] + " is Required.\n";
    }

    if ( errstr ) {
        alert( errstr );
        return false;
    } else {
 		document.forms['homeMain'].submit();
		return true;
    }
}

jQuery(function ($) {
	// Load dialog on page load
	//$('#basic-modal-content').modal();

	// Load dialog on click
    $('#basic-modal .basic').click(function (e) {
		validateFormOne();
	});
	
	// Load dialog on click
	$('#modalConfirm .basic').click(function (e) {
		validateFormTwo();
	});
	
});
