// JavaScript Document



//to Show and Hide the request form
function ShowHide(chkbox, tbl) {

	var Chkbox = document.getElementById(chkbox);
	var tbl = document.getElementById(tbl);
	
	if (Chkbox.checked) {
		tbl.style.display = 'block';
	}
	else {
		tbl.style.display = 'none';
	}
}//end of the ShowHide function

//to validate one email address
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){
		   return false
		}

		if (str.charAt(lstr - 1)== dot || str.charAt(lstr - 1)== at){
		   return false
		}
		
		if (str.indexOf("..") != -1 || str.indexOf(",") != -1 || str.indexOf(":") != -1 || str.indexOf(";") != -1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==(lstr - 1)){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==(lstr - 1)){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

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

 		 return true					
	}// end of the echeck function

function isEmpty(s)
{   return ((s == null) || (s.length == 0));
}

// Returns true if string s is empty or 
// whitespace characters only.

function isWhitespace (s)

{   var i;
	var whitespace = " \t\n\r";

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
	// Check that current character isn't whitespace.
	var c = s.charAt(i);

	if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

// Checks to see if a required field is blank.  If it is, a warning
// message is displayed...
function ForceEntry(objField, FieldName)
{
	if (objField != null){
	var strField = new String(objField.value);
	if (isWhitespace(strField)) {
		alert("Please, information required: " + FieldName);
		objField.focus();
		objField.select();
		return false;
	}
	}
	return true;
}//end of the ForceEntry function

function ForceComboEntry(objField, FieldName)
{
	if (objField != null){
	var strField = new String(objField.value);
	if (strField == '0') {
		alert("Please, information required: " + FieldName);
		objField.focus();
		return false;
	}
	}
	return true;
}//end of the ForceComboEntry function


function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}//end of the IsNumeric function

//function si es entero el valor
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;
}


/*To validate phone number*/
//variables needed
//check phone number

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 = 4;

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 checkPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}




