//------------------Script Written By Luke Pruen------------------

//------------------No Promo Pop-up------------------

function popup_promo(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=750,height=520,scrollbars=yes');
return false;
}

//------------------Detect Valid Email Address------------------
function rows(){
	
	if (navigator.appName == "Netscape") {
		document.getElementById("address").rows=2
	}else{
		document.getElementById("address").rows=3
	}
}

function validate_email(field,alerttxt)
{
  with (field)
  {
    apos=value.indexOf("@");
    dotpos=value.lastIndexOf(".");
    if (apos<1||dotpos-apos<2) 
    {
	  alert(alerttxt);return false;
	}
    else
	{
	  return true;
	}
  }
}

function validate_form_HA(){
	// Make quick references to our fields
	var company = document.getElementById('company');
	var name = document.getElementById('name');
	var role = document.getElementById('role');
	var hear = document.getElementById('hear');
	var tel = document.getElementById('tel');
	var address = document.getElementById('address');
	var country = document.getElementById('country');
	var email = document.getElementById('email');
	var promo = document.getElementById('promo');
	
	// Check each input in the order that it appears in the form!
	if(isEmpty(company, "Please enter a Company name")){
		if(isAlphabet(name, "Please enter a valid Name")){
			if(isSelected(role, "Please select a Role")){
				if(isSelected(hear, "Where did you Hear about us?")){
					if(isNumeric(tel, "Telephone may only contain numbers")){
				//if(madeSelection(state, "Please Choose a State")){
						if(isEmpty(address, "Numbers and Letters Only for Address")){
								if(isSelected(country, "Please Select a Country")){
									if(emailValidator(email, "Please enter a valid Email address")){
										if(isAlphanumeric(promo, "Please enter a valid Promo Key")){
												document.theform.btSubmit.value = "Submitted";
												document.theform.btSubmit.disabled =true;
											//window.open("http://www.stormagic-kb.com/SvSAN/svsan_buy.php");
											return true;
										}
									}
								}
						}
					}
				}
				//}
			}
		}
	}
		
	return false;
	
}

function validate_form_license(){
	// Make quick references to our fields
	var company = document.getElementById('company');
	var name = document.getElementById('name');
	var role = document.getElementById('role');
	var hear = document.getElementById('hear');
	var tel = document.getElementById('tel');
	var address = document.getElementById('address');
	var country = document.getElementById('country');
	var email = document.getElementById('email');
	var promo = document.getElementById('promo');
	var license_type = document.getElementById('license_type');

	if(isAlphanumeric(company, "Please enter a valid Company name")){
			if(isAlphabet(name, "Please enter a valid Name")){
				if(isSelected(role, "Please select a Role")){
					if(isSelected(hear, "Where did you Hear about us?")){
						if(isNumeric(tel, "Telephone may only contain numbers")){
						//if(madeSelection(state, "Please Choose a State")){
							if(isEmpty(address, "Numbers and Letters Only for Address")){
								if(isAlphabet(country, "Please enter a valid Country")){
									if(emailValidator(email, "Please enter a valid Email address")){
												//document.theform.btSubmit.value = "Submitted";
												//document.theform.btSubmit.disabled =true;
											//window.open("http://www.stormagic-kb.com/SvSAN/svsan_buy.php");
											return true;
									}
								}
							}
						}
					}
				}
			}
		}
		
	return false;
	
}


function submitEnable(){
	
	document.theform.btSubmit.disabled =false;
	document.theform.btSubmit.value = "Submit";
}

function isSelected(elem, helperMsg){
	if(elem.value == "Select"){
		alert(helperMsg);
		return false;
	}
	return true;
}

function isEmpty(elem, helperMsg){
	if(elem.value.length == ""){
		alert(helperMsg);
		return false;
	}
	return true;
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z ]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z ]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isNumeric(elem, helperMsg){
	var numericExpression = /[^a-z]+$/;
	//var numericExpression = /^[0-9 ]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}


//------------------Privacy Statement Pop-up------------------

function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=600,height=520,scrollbars=yes');
return false;
}

//------------------Buy HA & Maintenance---------------------

function BuyPopup() {
window.open( "http://www.stormagic.com/index.php", "myWindow", 
"status = 1, height = 300, width = 300, resizable = 0" )
}


