// JavaScript Document
<!-- hide JavaScript from non-JavaScript browsers

function VerifyMe(form){
	var errormsg = "";
	if(form.UserName.value==''){
		errormsg += 'You need to enter a Name.\n';
		form.UserName.focus();	
	}
	if(form.UserEmail.value==''){
		errormsg += 'You need to enter an E Mail Address.\n';
		form.UserEmail.focus();
	}
	else if(form.UserEmail.value.indexOf("@") == -1){
		errormsg += 'You need to enter a valid E Mail Address.\n';
		form.UserEmail.focus();
	}
	else if(form.UserEmail.value.indexOf(".") == -1){
		errormsg += 'You need to enter a valid E Mail Address.\n';
		form.UserEmail.focus();
	}
	if(form.PhoneNumber.value==''){
		errormsg += 'You need to enter a Phone Number.\n';
		form.PhoneNumber.focus();
	}

	if(form.Address1.value==''&&form.Address2.value==''&&form.Address3.value==''){
		errormsg+='You need to enter a Shipping Address.\n';
		form.Address1.focus();
	}
	b_itemEntered = false;
	for(x=1;x<11;x++)
	{
		if(form["Item"+x].value!=''&&form["Quantity"+x].value!=''&&form["Price"+x].value!=''){
			b_itemEntered = true;
		}
		if(form["Total"+x].value!='' && form["Item"+x].value==''){
			errormsg+='You have entered an Item Price and Quantity without entering the Item!\n';
			break;
		}else if(form["Item"+x].value!=''&&(form["Quantity"+x].value=='' || form["Price"+x].value=='')){
			errormsg+='You have entered an Item, without entering the Price and/or Quantity!\n';
			break;
		}
	}
	if(!(b_itemEntered)){
		errormsg += 'You haven\'t entered any Items to Order!';
		form.Item1.focus();
	}
	if (errormsg) {
		alert('The following error(s) occurred:\n'+errormsg);
		return false;
	}else {
		return true;
	}
}		

function UpdateMe(){
	
	var theChange = 0;
	var GrandTotal = 0;
	var total = 0;
	var errMessage = '';
	var theForm = window.document.frm_Email;
	for(i=0;i<theForm.elements.length; i++){
		if(theForm.elements[i].type == 'text'){
			theForm.elements[i].value=stripSpaces(theForm.elements[i].value);
		}
	}
	for(x=1;x<11;x++){
		if(isNaN(theForm["Price"+x].value)||isNaN(theForm["Quantity"+x].value)){
			errMessage += 'The price and quantity entries must only contain numbers.\n';
			//theForm["Price"+x].value = "";
			break;
		}else if(theForm["Price"+x].value == '' || theForm["Quantity"+x].value == ''){
			theForm["Total"+x].value  = "";
		}else{
			total = Math.round(((theForm["Price"+x].value)*(theForm["Quantity"+x].value))*100);
			if(total==0){
				theForm["Total"+x].value  = "00.00";
			}else{
				GrandTotal += total;
				total = total.toString();
				theChange = total.substr((total.length - 2), 2);
				theForm["Total"+x].value = total.substr(0, (total.length -2)) + '.' + theChange;
			}
		}
		if(errMessage){
			alert('The following error(s) occured:\n');
			//break;
			return false;
		}
		
	}
	//now format the grand total
	if(GrandTotal == 0){
		theForm.GrandTotal.value = "00.00";
	}else{
		GrandTotal = GrandTotal.toString();
		theChange = GrandTotal.substr((GrandTotal.length - 2), 2);
		theForm.GrandTotal.value = GrandTotal.substr(0, (GrandTotal.length -2)) + '.' + theChange;
	}
	return;
}



function checkCharacters(myWord){
	theString = new String(myWord);
	var b_illegal = false;
	var char_num = 0;
	var x = 0;
	for(x=0; x<theString.length; x++){
		char_num = theString.charCodeAt(x);
		if(!(((char_num>64) & (char_num<91)) | ((char_num>96) & (char_num<123)) | (char_num == 32))){
			b_illegal = true;
		}
	}
	if(b_illegal){
		return true;
	}else{
		return false;
	}
}

function stripSpaces(entry){
	theString = new String(entry);
	if(theString.charCodeAt(0) == 32){
		do{
			theString = theString.substring(1,theString.length);
		}while (theString.charCodeAt(0) == 32);
	}
	if(theString.charCodeAt(theString.length-1) == 32){
		do{
			theString = theString.substring(0,theString.length-1);
		}while (theString.charCodeAt(theString.length-1) == 32);
	}
	return theString;
}

function myCapitilizer(entry) {
	var phrase = entry.value;
	phrase = phrase.toUpperCase();
	entry.value = phrase;
	return entry;
}

//script added by satish
document.body.onkeydown=onKeyDown;
function onKeyDown(e)
{
var elt;
if(e)
elt=e.target;
else
elt=event.srcElement;
if(elt.name=="Comments")
return;
if(document.all)
{
if (event.keyCode==13) {
if(event.srcElement.type=='submit')
return true;
event.keyCode=9; return event.keyCode }
}
else
{
if (e.which==13) {e.which=9; return e.which; }
}
}

function ForceNumbersOnly(myfield, e, dec)
{
    var key;
    var keychar;

    if (window.event)
    {
        key = window.event.keyCode;
    }
    else if (e)
    {
        key = e.which;
    }
    else
    {
        return true;
    }
    if(key != 46 && key != 45 && key > 31 && (key < 48 || key > 57))
    {
        return false;
    }
    else
    {
        return true;
    }
}
function GotoNextControl(input)
{
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function getIndex(input) 
{
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
    {
        if (input.form[i] == input)
            index = i;
        else 
            i++;
     }
return index;
}
// end hide JavaScript -->
