// JavaScript Document
function valid_required(field)
{
         if(field=="")          {
         return false;
         }
    return true;
}


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 ID")
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}
	
function valForm()
{var min = 5000;
		
		if(document.myform.biztype.value=="Business Type" || document.myform.bizyears.value=="Years in Business" || document.myform.cc.value=="Monthly CC Sales - $" || document.myform.total.value=="Monthly Total Sales - $")
        {
			var d = document.getElementById('msg');
			jQuery('div#msg').show()
			d.innerHTML = "Please fill out all of the fields";
			/*document.getElementById('bluetext').style.display = 'none';*/
			jQuery('div.blueform').hide()
			setTimeout("jQuery('div.blueform').show()", 3500);
			setTimeout("jQuery('div#msg').hide()", 3500);
			return false;
        }
		 
		
		else if(document.myform.bizyears.value=="less than 6 months")
        {
			var d = document.getElementById('msg');
			jQuery('div#msg').show()
			d.innerHTML = "Unfortunately, AFS requires that you be in business at least 6 months. If you have recently purchased an existing business that was open for over 12 months of started a franchise you may still qualify. Please contact AFS and speak with a funding consultant who can assist you with your unique needs. ";
			/*document.getElementById('bluetext').style.display = 'none';*/
			jQuery('div.blueform').hide()
			setTimeout("jQuery('div.blueform').show()", 3500);	
			setTimeout("jQuery('div#msg').hide()", 3500);
			return false;
        }
		
		
		 else if(!valid_required(document.myform.cc.value) || document.myform.cc.value<min)
        {
			var d = document.getElementById('msg');
			jQuery('div#msg').show()
			d.innerHTML = "Unfortunately, AFS requires that your process at least $5,000 per month in credit card transactions. Please note that we can accept ALL card types including American Express and Discover.";
			/*document.getElementById('bluetext').style.display = 'none';*/
			jQuery('div.blueform').hide()
			setTimeout("jQuery('div.blueform').show()", 3500);
			setTimeout("jQuery('div#msg').hide()", 3500);
			return false;
        }
		
	
	else if(!valid_required(document.myform.cc.value) || document.myform.cc.value>=min)
        {	
		
		var numValue1 = document.myform.cc.value;
	var numValue2 = document.myform.total.value;
	var _loc1;
    var _loc2;
	

var _loc3 = new Date();
    _loc3.setDate(_loc3.getDate() + 7);
    var _loc6 = _loc3.getUTCMonth();
    var _loc7 = _loc3.getUTCDate();
    var _loc5 = _loc3.getUTCFullYear();
    var _loc4 = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
	
	 if (numValue1 > numValue2 / 2)
    {
        _loc1 = numValue1;
    }
    else
    {
        _loc1 = numValue2 / 2;
    } // end else if
	
	if (numValue1 * 1.500000E+000 > numValue2 / 2)
    {
        _loc2 = numValue1 * 1.500000E+000;
    }
    else
    {
        _loc2 = numValue2 / 2;
    } // end else if
    if (_loc1 == _loc2)
    {
        if (_loc1 <= 500000 && _loc2 <= 500000)
        {
            var d = document.getElementById('cong');
			d.innerHTML = "<div style=\"text-align:center;\">Congratulations, you qualify for <br>$" + _loc1 + " in funding!<br><div class=\"duedate\">Apply now and you could have these funds in your account before " + _loc4[_loc6] + "  " + _loc7 + ",  " + _loc5 +"</div></div>";
			return false;
			
        }
        else
        {
            var d = document.getElementById('cong');
			d.innerHTML = "<div style=\"text-align:center;\">Congratulations, you qualify for up to <br>$500000 in funding!<br><div class=\"duedate\">Apply now and you could have these funds in your account before " + _loc4[_loc6] + "  " + _loc7 + ",  " + _loc5 +"</div></div>";
			return false;
        } // end else if
    }
    else if (_loc1 <= 333333 && _loc2 <= 500000)
    {
        var d = document.getElementById('cong');
			d.innerHTML = "<div style=\"text-align:center;\">Congratulations, you qualify for <br>$" + _loc1 + " to $" + Math.round(_loc2) + " in funding!<br><div class=\"duedate\">Apply now and you could have these funds in your account before " + _loc4[_loc6] + "  " + _loc7 + ",  " + _loc5 +"</div></div>";
			return false;
    }
    else if (_loc1 <= 500000 && _loc2 >= 500000)
    {
        var d = document.getElementById('cong');
			d.innerHTML = "<div style=\"text-align:center;\">Congratulations, you qualify for <br>$" + _loc1 + " to $500000 in funding!<br><div class=\"duedate\">Apply now and you could have these funds in your account before " + _loc4[_loc6] + "  " + _loc7 + ",  " + _loc5 +"</div></div>";
			return false;
    }
    else if (_loc1 > 500000 && _loc2 >= 500000)
    {
        var d = document.getElementById('cong');
			d.innerHTML = "<div style=\"text-align:center;\">Congratulations, you qualify for up to <br>$500000 in funding!<br><div class=\"duedate\">Apply now and you could have these funds in your account before " + _loc4[_loc6] + "  " + _loc7 + ",  " + _loc5 +"</div></div>";
			return false;
    } // end else if
		return false;
		}
		
    return true;
}


function valFormsub()
{var min = 5000;
		
		if(document.myform.biztype.value=="Business Type" || document.myform.bizyears.value=="Years in Business" || document.myform.cc.value=="Monthly CC Sales - $" || document.myform.total.value=="Monthly Total Sales - $")
        {
			var d = document.getElementById('msg-sub');
			jQuery('div#msg-sub').show()
			d.innerHTML = "Please fill out all of the fields";
			jQuery('div.blueform').hide()
			setTimeout("jQuery('div.blueform').show()", 3500);
			setTimeout("jQuery('div#msg-sub').hide()", 3500);			
			return false;
        }
		 
		
		else if(document.myform.bizyears.value=="less than 6 months")
        {
			var d = document.getElementById('msg-sub');
			jQuery('div#msg-sub').show()
			d.innerHTML = "Unfortunately, AFS requires that you be in business at least 6 months. If you have recently purchased an existing business that was open for over 12 months of started a franchise you may still qualify. Please contact AFS and speak with a funding consultant who can assist you with your unique needs. ";
			jQuery('div.blueform').hide()
			setTimeout("jQuery('div.blueform').show()", 3500);
			setTimeout("jQuery('div#msg-sub').hide()", 3500);				
			return false;
        }
		
		
		 else if(!valid_required(document.myform.cc.value) || document.myform.cc.value<min)
        {
			var d = document.getElementById('msg-sub');
			jQuery('div#msg-sub').show()
			d.innerHTML = "Unfortunately, AFS requires that your process at least $5,000 per month in credit card transactions. Please note that we can accept ALL card types including American Express and Discover.";
			jQuery('div.blueform').hide()
			setTimeout("jQuery('div.blueform').show()", 3500);
			setTimeout("jQuery('div#msg-sub').hide()", 3500);				
			return false;
        }
		
	
	else if(!valid_required(document.myform.cc.value) || document.myform.cc.value>=min)
        {	
		
		var numValue1 = document.myform.cc.value;
	var numValue2 = document.myform.total.value;
	var _loc1;
    var _loc2;
	
	var _loc3 = new Date();
    _loc3.setDate(_loc3.getDate() + 7);
    var _loc6 = _loc3.getUTCMonth();
    var _loc7 = _loc3.getUTCDate();
    var _loc5 = _loc3.getUTCFullYear();
    var _loc4 = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
	
	
	 if (numValue1 > numValue2 / 2)
    {
        _loc1 = numValue1;
    }
    else
    {
        _loc1 = numValue2 / 2;
    } // end else if
	
	if (numValue1 * 1.500000E+000 > numValue2 / 2)
    {
        _loc2 = numValue1 * 1.500000E+000;
    }
    else
    {
        _loc2 = numValue2 / 2;
    } // end else if
    if (_loc1 == _loc2)
    {
        if (_loc1 <= 500000 && _loc2 <= 500000)
        {
            var d = document.getElementById('cong-sub');
			d.innerHTML = "<div style=\"text-align:center;\">Congratulations, you qualify for <br>$" + _loc1 + " in funding!<br><div class=\"duedate\">Apply now and you could have these funds in your account before " + _loc4[_loc6] + "  " + _loc7 + ",  " + _loc5 +"</div></div>";
			document.getElementById('msg-sub').style.display = 'none';
			return false;
			
        }
        else
        {
            var d = document.getElementById('cong-sub');
			d.innerHTML = "<div style=\"text-align:center;\">Congratulations, you qualify for up to <br>$500000 in funding!<br><div class=\"duedate\">Apply now and you could have these funds in your account before " + _loc4[_loc6] + "  " + _loc7 + ",  " + _loc5 +"</div></div>";
			document.getElementById('msg-sub').style.display = 'none';
			return false;
        } // end else if
    }
    else if (_loc1 <= 333333 && _loc2 <= 500000)
    {
        var d = document.getElementById('cong-sub');
			d.innerHTML = "<div style=\"text-align:center;\">Congratulations, you qualify for <br>$" + _loc1 + " to $" + Math.round(_loc2) + " in funding!<br><div class=\"duedate\">Apply now and you could have these funds in your account before " + _loc4[_loc6] + "  " + _loc7 + ",  " + _loc5 +"</div></div>";
			document.getElementById('msg-sub').style.display = 'none';
			return false;
    }
    else if (_loc1 <= 500000 && _loc2 >= 500000)
    {
        var d = document.getElementById('cong-sub');
			d.innerHTML = "<div style=\"text-align:center;\">Congratulations, you qualify for <br>$" + _loc1 + " to $500000 in funding!<br><div class=\"duedate\">Apply now and you could have these funds in your account before " + _loc4[_loc6] + "  " + _loc7 + ",  " + _loc5 +"</div></div>";
			document.getElementById('msg-sub').style.display = 'none';
			return false;
    }
    else if (_loc1 > 500000 && _loc2 >= 500000)
    {
        var d = document.getElementById('cong-sub');
			d.innerHTML = "<div style=\"text-align:center;\">Congratulations, you qualify for up to <br>$500000 in funding!<br><div class=\"duedate\">Apply now and you could have these funds in your account before " + _loc4[_loc6] + "  " + _loc7 + ",  " + _loc5 +"</div></div>";
			document.getElementById('msg-sub').style.display = 'none';
			return false;
    } // end else if
		return false;
		}
		
    return true;
}


function numbersonly(e, decimal) {
var key;
var keychar;

if (window.event) {
   key = window.event.keyCode;
}
else if (e) {
   key = e.which;
}
else {
   return true;
}
keychar = String.fromCharCode(key);

if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) ) {
   return true;
}
else if ((("0123456789").indexOf(keychar) > -1)) {
   return true;
}
else if (decimal && (keychar == ".")) { 
  return true;
}
else
   return false;
}



function clearText(field){
    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;

}
