
function stripUser(){
	var string = document.implogin.imapuser.value;
	a = string.split('@');
	if (a.length > 1){
		document.implogin.imapuser.value = a[0];
	}
}

function billingToggle(billing_method) {
	if (billing_method == 1) {
		if (document.order.billing_method[0].checked == true) {
			document.order.paperbilling_term.disabled = false;
			document.order.ccbilling_term.disabled = true;
			document.order.billing_ccNumber.disabled = true;
			document.order.billing_ccType.disabled = true;
			document.order.billing_ccExpMonth.disabled = true;
			document.order.billing_ccExpYear.disabled = true;
			document.order.billing_ccName.disabled = true;
			document.order.billing_ccAddress.disabled = true;
			document.order.billing_ccCity.disabled = true;
			document.order.billing_ccState.disabled = true;
			document.order.billing_ccZip.disabled = true;
		} 
	}
	if (billing_method == 2) {
		if (document.order.billing_method[1].checked == true) {
			document.order.ccbilling_term.disabled = false;
			document.order.paperbilling_term.disabled = true;
			document.order.billing_ccNumber.disabled = false;
			document.order.billing_ccType.disabled = false;
			document.order.billing_ccExpMonth.disabled = false;
			document.order.billing_ccExpYear.disabled = false;
			document.order.billing_ccName.disabled = false;
			document.order.billing_ccAddress.disabled = false;
			document.order.billing_ccCity.disabled = false;
			document.order.billing_ccState.disabled = false;
			document.order.billing_ccZip.disabled = false;
		} 
	}
}

function toggle(billingSame) {
	var selectgroup=document.order.state;
	  
	for (var b = 0; b < selectgroup.length; b++) {
	  if (selectgroup[b].selected) {
	     var state=selectgroup[b].value; 
	  }
	}
	
	if (billingSame == 1) {
		if (document.order.billingSame.checked == true) {
			document.order.billing_companyName.value = document.order.companyName.value;
			document.order.billing_contact.value = document.order.contact.value;
			document.order.billing_address1.value = document.order.address1.value;
			document.order.billing_city.value = document.order.city.value;
			document.order.billing_state.value = state;
			document.order.billing_zip.value = document.order.zip.value;
			}else {
			document.order.billing_companyName.value = '';
			document.order.billing_contact.value = '';
			document.order.billing_address1.value = '';
			document.order.billing_city.value = '';
			document.order.billing_state.value = 'CO';
			document.order.billing_zip.value = '';
		}
	} 
	if (billingSame == 2) {
		if (document.order.modemBillingSame.checked == true) {
			document.order.modem_contact.value = document.order.contact.value;
			document.order.modem_address1.value = document.order.address1.value;
			document.order.modem_city.value = document.order.city.value;
			document.order.modem_state.value = state;
			document.order.modem_zip.value = document.order.zip.value;
			}else {
			document.order.modem_contact.value = '';
			document.order.modem_address1.value = '';
			document.order.modem_city.value = '';
			document.order.modem_state.value = 'CO';
			document.order.modem_zip.value = '';
		}
	}
}

// email validation
function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail")
		    return false
		 }

 		 return true					
	}
			
function ValidateForm(){
	var emailID=document.order.emailAddress
	var radiogroup=document.order.billing_method;
	  
	for (var b = 0; b < radiogroup.length; b++) {
	  if (radiogroup[b].checked) {
	     var billingMethod=radiogroup[b].value; 
	  }
	}
	
	// company/customer name	
	if (document.order.companyName.value=="") {
			document.order.companyName.focus();
    		alert('You must provide a customer or company name.');
       		return false; 
	}
	// contact name	
	if (document.order.contact.value=="") {
			document.order.contact.focus();
    		alert('You must provide a contact name.');
       		return false; 
	}
	// email address	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your email address.")
		emailID.focus()
		return false;
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false;
	}
	// address	
	if (document.order.address1.value=="") {
			document.order.address1.focus();
    		alert('You must provide your address.');
       		return false; 
	}
	// city	
	if (document.order.city.value=="") {
			document.order.city.focus();
    		alert('You must provide your city.');
       		return false; 
	}
	// state	
	if (document.order.state.value=="") {
			document.order.state.focus();
    		alert('You must provide your state.');
       		return false; 
	}
	// zip	
	if (document.order.zip.value=="") {
			document.order.zip.focus();
    		alert('You must provide your zip code.');
       		return false;
 	}
 	// home number	
	if (document.order.homeNumber.value=="") {
			document.order.homeNumber.focus();
	    alert('You must provide your home phone number.');
	    return false;
	}
	// billing contact name	
	if (document.order.billing_contact.value=="") {
			document.order.billing_contact.focus();
    		alert('You must provide a billing contact name.');
       		return false; 
	}
	// billing address	
	if (document.order.billing_address1.value=="") {
			document.order.billing_address1.focus();
    		alert('You must provide your billing address.');
       		return false; 
	}
	// billing city	
	if (document.order.billing_city.value=="") {
			document.order.billing_city.focus();
    		alert('You must provide your billing city.');
       		return false; 
	}
	// billing state	
	if (document.order.billing_state.value=="") {
			document.order.billing_state.focus();
    		alert('You must provide your billing state.');
       		return false; 
	}
	// billing zip	
	if (document.order.billing_zip.value=="") {
			document.order.billing_zip.focus();
    		alert('You must provide your billing zip code.');
       		return false;
 	}
	// Validation for Credit Card Values
	if (billingMethod == 'Credit Card') {
		// Credit Card Name	
		if (document.order.billing_ccName.value=="") {
				document.order.billing_ccName.focus();
	    		alert('You must provide your name as it appears on your credit card statement.');
	       		return false;
		}
		// Credit Card Address	
		if (document.order.billing_ccAddress.value=="") {
				document.order.billing_ccAddress.focus();
	    		alert('You must provide your billing address as it appears on your credit card statement.');
	       		return false;
		}
		// Credit Card City	
		if (document.order.billing_ccCity.value=="") {
				document.order.billing_ccCity.focus();
	    		alert('You must provide your billing address as it appears on your credit card statement.');
	       		return false;
		}
		// Credit Card City	
		if (document.order.billing_ccZip.value=="") {
				document.order.billing_ccZip.focus();
	    		alert('You must provide your billing address as it appears on your credit card statement.');
	       		return false;
		}
	}
	// format cc number and date
	if (document.order.billing_method[1].checked == true) {
		tmpNum = document.order.billing_ccNumber.value;
		rExp = / /gi;
		ccNum = tmpNum.replace(rExp,'');
		ccType = document.order.billing_ccType.value;
			
		// validate cc specified
		if (validateCCNum(ccType, ccNum)==false){
			alert('We cannot validate the credit card information you have provided. Please check your information and try again. You can also contact the sales office at (970) 963-7873.')
			return false;
		}
	}
	
	return true;
}

// credit card validation
function validateCCNum(billing_ccType, billing_ccNumber){	
	var result = false;
	cardType = billing_ccType.toUpperCase();
	
	var cardLen = billing_ccNumber.length;
	var firstdig = billing_ccNumber.substring(0,1);
	var seconddig = billing_ccNumber.substring(1,2);
	var first4digs = billing_ccNumber.substring(0,4);

	switch (cardType)
	{
		case "VISA":
			result = ((cardLen == 16) || (cardLen == 13)) && (firstdig == "4");
			break;
		case "AMEX":
			var validNums = "47";
			result = (cardLen == 15) && (firstdig == "3") && (validNums.indexOf(seconddig)>=0);
			break;
		case "MASTERCARD":
			var validNums = "12345";
			result = (cardLen == 16) && (firstdig == "5") && (validNums.indexOf(seconddig)>=0);
			break;
		case "DISCOVER":
			result = (cardLen == 16) && (first4digs == "6011");
			break;
		case "DINERS":
			var validNums = "068";
			result = (cardLen == 14) && (firstdig == "3") && (validNums.indexOf(seconddig)>=0);
			break;
	}	
	return result;
}
 
// hosting window popup windows
function hostingDetail(plan){
 	iWin = window.open('services/hostingPlanDetail.cfm?planID=' + plan, 'blah', 'resizable,scrollbars,width=650,height=320,left=25,top=25');
	iWin.focus();
}	