// JavaScript Document

/**
 * 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 = 5;

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 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){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValidateForm(){
    var Phone=document.sysfrm.phone1;
    
    /*if ((Phone.value==null)||(Phone.value=="")){
        alert("Please Enter your Phone Number")
        Phone.focus()
        return false
    }*/


    if (checkInternationalPhone(Phone.value)==false){
        alert("Please enter a Valid Phone Number of minimum 5 digits")
        Phone.value=""
        Phone.focus()
        return 0
    }
    return 1
 }
 function ValidateForm1(){
    var Phone=document.sysfrm.phone2;
    
    
    if (checkInternationalPhone(Phone.value)==false){
        alert("Please enter a Valid Phone Number of minimum 5 digits")
        Phone.value=""
        Phone.focus()
        return 0
    }
    return 1
 }

function return_false(obj_nam,rtrn_msg){
      alert(rtrn_msg);      
      document.getElementById(obj_nam).select();
      document.getElementById(obj_nam).focus();
      return false;
}
function checktext(eventtype)
{
	var x=document.getElementById('comments').value;    
	if(eventtype=='blur')
	{
	 if(x=="")
	   document.getElementById('comments').value = "Please type here...";
	}
   if(eventtype=='focus')
	{
	 if(x=="Please type here...")
	   document.getElementById('comments').value = "";
	}

	 
}
function Chk_Empty(obj_nam,rtrn_msg)
{           
  var x=document.getElementById(obj_nam).value;    
    if(x == "" || x == "Please type here...")
      return_false(obj_nam,rtrn_msg);   
    else
      return true;
}
function Chk_AlphaNumeric(obj_nam,rtrn_msg,stat){
    
    var x = document.getElementById(obj_nam).value;
    var invalids = "";
    /*if(document.getElementById(obj_nam).value == "")
    return true;
    
    else*/ if(stat==0)
      invalids = "`~@#$%^&*()_-+=\|{}[]:;'\"<>,.?/1234567890";
    else
      invalids = "`~@#$%^&*()_-+=\|{}[]:;'\"<>,.?/";
      
    for(i=0; i<invalids.length; i++) {
       
        if(x.indexOf(invalids.charAt(i)) >= 0 || x==false) {
               return_false(obj_nam,rtrn_msg);
               return false;
        }
    }
    return true;
}
//Email validation
function  Chk_EmailValid(obj_nam,msg){
var str = document.getElementById(obj_nam).value;

var filter=/^.+@.+\..{2,3}$/;
 if (filter.test(str))
    return true;
 else {
    return_false(obj_nam,msg);
        
  }
}

function checkquote()
{
if(!Chk_Empty("fname","Please enter your First Name") || !Chk_AlphaNumeric("fname","First Name should contain alphabets only",0)|| !Chk_Empty("lname","Please enter your Last Name") || !Chk_AlphaNumeric("lname","Last Name should contain alphabets only",0) || !Chk_Empty("phone1","Please enter your Phone Number",0) ||!Chk_Empty("email","Please enter your Email Address") || !Chk_EmailValid("email","Please enter a Valid Email Address(ex:yourname@example.com)") ||!Chk_Empty("comments","Please enter your Description"))
{

			return false;
         }
 

if(document.sysfrm.phone1.value!="")
{
if(ValidateForm()==0)
return false;   
 }
if(document.sysfrm.phone2.value!="")
{
if(ValidateForm1()==0)
return false;
     }

if(requestform)
{

 with(window.document.sysfrm)
    {   totalCheck = 0; 
        totalElement = elements.length;

        for(i = 0; i < totalElement; i++)
        {   
           
			if (elements[i].type == 'checkbox' && elements[i].name == 'service[]')
            {   if (elements[i].checked) 
                {   totalCheck++;
                    break;
                }
            }
        }       

        if (totalCheck == 0)
        {   
            alert("Please check at least one option which you are Interested!");
            
            return false;
        }
	}
	if(window.document.sysfrm.photo1.value!="")
	  {
		   var img=window.document.sysfrm.photo1.value;
        var proimage=img.split('.');
        if(proimage[proimage.length-1].toLowerCase()!='gif' && proimage[proimage.length-1].toLowerCase()!='GIF' && proimage[proimage.length-1].toLowerCase()!='jpg' && proimage[proimage.length-1].toLowerCase()!='png' && proimage[proimage.length-1].toLowerCase()!='JPEG')
            {
            alert("Please Enter The Images Of the Type Of gif or jpg or png");
            window.document.sysfrm.photo1.focus();
            return false;
            }
          document.getElementById("showmsg").style.visibility = "visible";
         }
	  
	 if(window.document.sysfrm.photo2.value!="")
	  {
		   var img=window.document.sysfrm.photo2.value;
        var proimage=img.split('.');
        if(proimage[proimage.length-1].toLowerCase()!='gif' && proimage[proimage.length-1].toLowerCase()!='GIF' && proimage[proimage.length-1].toLowerCase()!='jpg' && proimage[proimage.length-1].toLowerCase()!='png' && proimage[proimage.length-1].toLowerCase()!='JPEG')
            {
            alert("Please Enter The Images Of the Type Of gif or jpg or png");
            window.document.sysfrm.photo2.focus();
            return false;
            }
       document.getElementById("showmsg").style.visibility = "visible";
       }
		 if(window.document.sysfrm.photo3.value!="")
	  {
		   var img=window.document.sysfrm.photo3.value;
        var proimage=img.split('.');
        if(proimage[proimage.length-1].toLowerCase()!='gif' && proimage[proimage.length-1].toLowerCase()!='GIF' && proimage[proimage.length-1].toLowerCase()!='jpg' && proimage[proimage.length-1].toLowerCase()!='png' && proimage[proimage.length-1].toLowerCase()!='JPEG')
            {
            alert("Please Enter The Images Of the Type Of gif or jpg or png");
            window.document.sysfrm.photo3.focus();
            return false;
            }
        document.getElementById("showmsg").style.visibility = "visible";
         }
		 
		 
}

if(requestform)
{

 document.sysfrm.action="free-estimates.php?submit=yes";
}
else
 document.sysfrm.action="contactus.php?submit=yes";

            document.sysfrm.submit();

}
