﻿function doSearchGlobal()
	{
		
			val = document.getElementById("txtSearch").value ;
			if ((val !== "") && (val.toLowerCase() !== "search"))
			{
				
				window.location.href = "/search.aspx?zoom_query=" + val + "&zoom_cat=5";
				
			}
			else
			{
				//document.getElementById("txtSearch").style.backgroundColor = "#FFFFCC";
			}
	
	}
	function checkEnterPageGlobal(e)
		{
						
			if (!e) var e = window.event
			if (e.keyCode) code = e.keyCode;
			else if (e.which) code = e.which;
		
			
			if (code == 13) {
				
				doSearchGlobal();
				return false;
				
				}
				
		}
		
function switchtabs(t)
{
    // 4 is 1 + the number of tabs
    // each tab content area is named tab1, tab2 etc..
    // each tab head is named thead1, thead2 etc...

    for (i=1;i < 7;i++)
    {
        
        
        if (document.getElementById ("tab" + i))
        {
                 el = document.getElementById ("tab" + i);
                
                
                 elhead = document.getElementById ("thead" + i);
                if (i==t)
                {
                    el.style.display = "";
                    elhead.className = "current";
                }
                else
                {
                    el.style.display = "none";
                    elhead.className = "";
                }    
        }
    }
}

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    
    if (pair[0] == variable) {
      return pair[1];
    }
    else {
     
    }
  
  } 
  return "";
}

function findControl(controlid)
{

	for (y=0; y < document.forms.length;y++)
	{
	f = document.forms[y] ;
	
	
	for (r=0;r < f.length ; r++)
	{
	
		if (f.elements[r].id.indexOf(controlid) > -1 )
		{
			return f.elements[r].id ;
		}
	
	}
	}


}

function isValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
	return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}
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++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}


// 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 checkInternationalPhone(strPhone)
{
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length == minDigitsInIPhoneNumber);
}
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;
}
