﻿
    
    function getRegistrationForm()
{
	return document.registerForm;
}

	
function checkFormWithMarketing()
{
	var currForm = getRegistrationForm();
	if(!someSoftwareTypeIsSelected() && !document.getElementById("m1").checked && !document.getElementById("m2").checked)
	{
		alert("Please select a software type or 'Whitepaper'");
		document.getElementById("m1").focus();
		return false;
	}
	
	return checkForm(currForm);
}

function checkFormWithoutMarketing()
{
	var currForm = document.registerForm;
	
	if(!someSoftwareTypeIsSelected())
	{
		alert("Please select a software type");
		currForm.r1[0].focus();
		return false;
	}
	
	return checkForm(currForm);
}


function someSoftwareTypeIsSelected()
{
	return getSelectedRadio(document.registerForm.r1) != -1;
}

function checkForm(currForm)
{
	if(currForm.first_name.value=="")
	{
		alert("Please fill in First Name");
		currForm.first_name.focus();
		return false;
	}
	if(currForm.last_name.value=="")
	{
		alert("Please fill in Last Name");
		currForm.last_name.focus();
		return false;
	}
	if(currForm.company.value=="")
	{
		alert("Please fill in Company Name");
		currForm.company.focus();
		return false;
	}
	if(currForm.industry.selectedIndex==0)
	{
		alert("Please select Industry");
		currForm.industry.focus();
		return false;
	}
	if(document.getElementById('00N200000013FlU').selectedIndex==0)
	{
		alert("Please select Country");
		document.getElementById('00N200000013FlU').focus();
		return false;
	}
	// User selected "USA" bud didn't select a state
	if(document.getElementById('00N200000013FlU').selectedIndex == 1 && document.getElementById('00N200000013FlZ').selectedIndex == 0)
	{
		alert("Please select State");
		document.getElementById('00N200000013FlZ').focus();
		return false;
	}
	
	//User selected "Canada" bud didn't select a region
	if(document.getElementById('00N200000013FlU').selectedIndex == 36 && document.getElementById('00N200000013Flo').selectedIndex == 0)
	{
		alert("Please select province");
		document.getElementById('00N200000013Flo').focus();
		return false;
	}
	
	if(currForm.email.value=="")
	{
		alert("Please fill in email address");
		currForm.email.focus();
		return false;
	}
	if (!isValidEmail(currForm.email.value))
	{
		alert("Please fill in correct email address");
		currForm.email.focus();
		return false;
	}
	if(currForm.phone.value=="")
	{
		alert("Please fill in Phone number");
		currForm.phone.focus();
		return false;
	}
	
	
	return true;
}

function checkCountry(slctFild)
{
	if(slctFild.selectedIndex==1)
	{
		showStateLine();
		hideProvinceLine();
	}
	else
	{
		if(slctFild.selectedIndex==36)
		{
			hideStateLine();
			showProvinceLine();
		}
		else
		{
			document.getElementById("00N200000013FlZ").selectedIndex = 0;
			document.getElementById("00N200000013Flo").selectedIndex = 0;
			hideStateLine();
			hideProvinceLine();
		}
	}
}

function showStateLine()
{
	showElement("state_field");
	showElement("state_label");
}

function hideStateLine()
{
	hideElement("state_field");
	hideElement("state_label");
}


function showProvinceLine()
{
	showElement("province_field");
	showElement("province_label");
}

function hideProvinceLine()
{
	hideElement("province_field");
	hideElement("province_label");
}


function showElement(id)
{
	document.getElementById(id).style.display = "block";
}

function hideElement(id)
{
	document.getElementById(id).style.display = "none";
}

function isValidEmail(email)
	{
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(email))
			return true;
		else{
			return false
		}

	}
	
	function getfile(filename,filetype)
	{
		if(filetype != 3 && document.getElementById("btn_next"))
		{
			document.getElementById("btn_next").disabled = false;
		} 
		switch (filetype)
		{
			case 1:
				window.open('download/getfile.php?f=' + escape(filename) +'&t='+filetype + getDbsStr(),'_blank');
				break;
			case 2:
				window.open('download/getfile.php?f=' + escape(filename) +'&t='+filetype + getDbsStr(),'_blank');
				break;
			case 3:
				window.open('download/getfile.php?f=' + escape(filename) +'&t='+filetype + getDbsStr(),'_self');
				break;
			case 4:
				window.open('download/getfile.php?f=' + escape(filename) +'&t='+filetype + getDbsStr(),'_self');
				break;
			default:
				
		}
	}
	
	function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function


    