/*
* bottom contact info 
*/
var contact=("<div align='center'>| <a href='contact.html'>zoli@mymortgagepros.com</a> | Tel: 403-253-2022 | Fax: 403-253-2064 | Licensed under <a href='http://www.mymortgagepros.com'>MortgagePro Ltd. Alberta</a> |</div>")
/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

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 Address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail Address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail Address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

 		 return true					
	}


/* validate contact.htm form */
function ValidateForm(){
	var emailID=document.contact.youremail
	var emailMsg=document.contact.yourcontent
	
	
	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
	}
	
	if ((emailMsg.value==null)||(emailMsg.value=="")){
		alert("Please Enter your Email Message")
		emailMsg.focus()
		return false
	}
	return true
 }
 
 
/* phone number validation */ 
/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        /* Check that current character isn't whitespace.*/
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}


 
 /* validate investors-form-lenders*/ 
  function ValidateForm2(){
  
  var firstname=document.investors.first_name
  var lastname=document.investors.last_name
  var phoneno=document.investors.phone
  var emailID=document.investors.email
  var address_street_name=document.investors.address_street_name
  var address_city=document.investors.address_city
  var address_postal_code=document.investors.address_postal_code
  var address_province=document.investors.address_province
  var comments=document.investors.comments
  
	if ((firstname.value==null)||(firstname.value=="")){
		alert("Please Enter your First Name")
		firstname.focus()
		return false
	}
	if ((lastname.value==null)||(lastname.value=="")){
		alert("Please Enter your Last Name")
		lastname.focus()
		return false
	}
	
	if ((phoneno.value==null)||(phoneno.value=="")){
		alert("Please Enter your 10 Digits Phone Number")
		phoneno.focus()
		return false
	}
	if (checkInternationalPhone(phoneno.value)==false){
		alert("Please Enter a 10 digits Valid Phone Number")
		phoneno.value=""
		phoneno.focus()
		return false
	}
	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
	}
	if ((address_street_name.value==null)||(address_street_name.value=="")){
		alert("Please Enter your Address, no, street..")
		address_street_name.focus()
		return false
	}
	if ((address_city.value==null)||(address_city.value=="")){
		alert("Please Enter your City")
		address_city.focus()
		return false
	}
	if ((address_postal_code.value==null)||(address_postal_code.value=="")){
		alert("Please Enter your Postal Code")
		address_postal_code.focus()
		return false
	}
	if ((address_province.value==null)||(address_province.value=="")||(address_province.value=="no")){
		alert("Please Select your Province")
		address_province.focus()
		return false
	}
	/*location check boxes*/
	boxes = document.investors.investlocation.length
	txt = ""
	for (i = 0; i < boxes; i++) {
	if (document.investors.investlocation[i].checked) {
	txt = txt + document.investors.investlocation[i].value + " "
	}
	}
	if (txt == "") {
	alert("No investment location checked, minimum one province should be checked")
	comments.focus()
	return false
	}
	
	
	return true
 }
 
/***********************************************
* Textarea Maxlength script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}
/*********************************************/	
