// Scripts for AffordableRX.com

// Phone Numbers Etc.  types= phone, fax, address
// <SCRIPT language=javascript>contact_number('fax');</SCRIPT>
function contact_number(type) {
  if (type=="fax"){document.write("1-866-576-7377");}
  if (type=="phone"){document.write("1-866-571-7377");}
  if (type=="address"){document.write("Affordable RX<br>2641 St. Mary's Road<br>Winnipeg, MB R2N 4A2<br>Canada");}
}

// Generates email address "safe" from harvesters
// <SCRIPT language=javascript>generateAntiSpiderEmail('user', 'domain', 'tld', 'display_text');</SCRIPT>
function generateAntiSpiderEmail(Username, DomainName, TLD, Text, ExtraTagStr) {
	Address = Username + "&#64;" + DomainName + "." + TLD;

	if (!(Text)) {DisplayText = Address}
	else {DisplayText = Text};

	document.write("<a href=\"ma" + "il" + "to:" + Address + "\"" + ExtraTagStr + ">" + DisplayText + "</a>");
}

// Form Validation Functions
function isEmpty(str){
    strRE = new RegExp( );
    strRE.compile( '^[\s ]*$', 'gi' );
    return strRE.test( str.value );
}

function notValidEmail(str){
    mailRE = new RegExp( );
    mailRE.compile( '^[\._a-z0-9-]+@[\.a-z0-9-]+[\.]{1}[a-z]{2,4}$', 'gi' );
    return !(mailRE.test( str.value ));
}

function checkForm( form ){
    //check if required fields are empty
	    if( isEmpty( form.Name ) ){
        alert( 'Name is required field!' );
        return false;
    }
    //check if email is correct
    if( notValidEmail( form.Email ) ){
        alert( 'Empty or incorrect email address!' );
        return false;
    }
    return true;
}

function mofCart_checkAuth() {
	if (!document.getElementById('Agree_ID').checked && !document.getElementById('Agree_LegalGuardian_ID').checked) {
		alert('Please review and agree to the patient authorization first');
		return false;
	}
	
	return true;
}
