/*
 *   Browser safe method to get an element by it's id
 */
function getElement(id) {
     return document.getElementById ? document.getElementById(id) :
     document.all ? document.all(id) : null;
}

function validateEmail(entered) {
     apos=entered.indexOf("@");
     dotpos=entered.lastIndexOf(".");
     lastpos=entered.length-1;
     if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) {
          return false;
     } else {
          return true;
     }
}

function validateNumber(x) {
     var anum=/(^\d+$)|(^\d+\.\d+$)/;
     if (anum.test(x)){
          return true;
     } else {
          return false;
     }
}

// 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 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);
}

/*
 * Credits to Simon Willison for this function
 * http://simon.incutio.com/archive/2004/05/26/addLoadEvent
 */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function addBehavior(){

    /*
        Get targetBlank links and attribute the right target.
    */
    elements = document.getElementsByTagName("a");
    for( var i=0; i < elements.length; i++ ){
        var s = elements[i].rel;
        if( s == "external" ) elements[i].target = "_blank";
    }

    var viewportheight;
    if (typeof window.innerWidth != 'undefined') {
        viewportheight = window.innerHeight
    } else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
        viewportheight = document.documentElement.clientHeight
    } else {
        viewportheight = document.getElementsByTagName('body')[0].clientHeight
    }
    // bottom = 500;
    // top = 207
    if( viewportheight > 705 ){
        // for large screens
        document.body.style.backgroundPosition = "bottom left";
    }
}
addLoadEvent(addBehavior);

function openwin(url){
     day = new Date();
     id = day.getTime();
     eval("page"+id+" = window.open('"+url+"' , '"+ id +"', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=500,left=150,top=150');");
}

(function(){ /*Use Object Detection to detect IE6*/ var m = document.uniqueID /*IE*/ && document.compatMode /*>=IE6*/ && !window.XMLHttpRequest /*<=IE6*/ && document.execCommand ; try{ if(!!m){ m("BackgroundImageCache", false, true) /* = IE6 only */ } }catch(oh){}; })();

