function getCookie(Name) {
   var search = Name + "="
   if (document.cookie.length > 0) { // if there are any cookies
      offset = document.cookie.indexOf(search) 
      if (offset != -1) { // if cookie exists 
         offset += search.length 
         // set index of beginning of value
         end = document.cookie.indexOf(";", offset) 
         // set index of end of cookie value
         if (end == -1) 
            end = document.cookie.length
         return unescape(document.cookie.substring(offset, end))
      } 
   }
   return ""
}

function popupPage(file)
{
  winAtts = "toolbar=0,scrollbars=1,width=425,height=400";
  winAtts = "resizable=1',toolbar=0,scrollbars=1,width=700,height=300,left=50,top=150";

  popupWindow = window.open( file, 'Mohandes', winAtts );
  
  //if (navigator.appName.indexOf("Netscape") != -1)
  //{
  //  popupWindow.focus();
  //}

}

function openWindow(url, name, rs, w, h) {

          var resize = "";
          //if (rs) {
            resize = "resizable,";
          //}
          popupWin = window.open(url, name, 'scrollbars,menubar,' + resize + 'width=' + w + ',height=' + h);
  
	//if (navigator.appName.indexOf("Netscape") != -1)
  	//{
    	//	popupWin.focus();
  	//}
}

function confirmDelete(){
    if (confirm("Are you sure you want to delete this record?")) {
        return true;
    } else {
        return false;
    }
}

function isEmpty (el) {
  return ((el==null) || (el.length==0));
}

function isNotEmpty (el) {
  if (isEmpty(el.value)) {
    alert (el.name + " field can not be empty.");
    //el.focus();
    return false;
  }
  return true;
}

function isNumber (el) {
  if (isNaN(el.value)) {
    alert (el.name + " field must contain a valid number.");
    el.focus();
    return false;
  }
  return true;
}
  
function isPhone (el) {
  var phone="";
  for (i=0; i<el.value.length; i++) { 
    c = el.value.substr(i,1);
    if (!isNaN(c) && c != " ") {
      phone = phone + c;
    }
  }
  if (phone.length>0 && phone.length<6) {
    alert(el.name + " must contain a valid phone number (too short!).");
    el.focus();
    return false;
  } else if (phone.length>10) {
    alert(el.name + " must contain a valid phone number (too long!).");
    el.focus();
    return false;
  } else if (phone.length==10) {
    phone = "(" + phone.substr(0,3) + ") " + phone.substr(3,3) + "-" + phone.substr(6,4);
  } else if (phone.length==7) {
    phone = "(416) " + phone.substr(0,3) + "-" + phone.substr(3,4);
  } else if (phone.length<10) {
    phone = phone.substr(0, phone.length-4) + "-" + phone.substr(phone.length-4,4);
  }
  if (phone.length>=6) el.value = phone;
  return true;
}

function saveNewMember () {
  //verify business rules before save

  var el = document.form;
  //1-UserId can not be empty.
  if (isEmpty(el.UserId.value)) {
    alert ("UserId must be specified.");
    el.UserId.focus();
    return false;
  }
  
  //2-Password can not be empty.
  //if (isEmpty(el.Password.value)) {
  //  alert ("Password must be specified.");
  //  el.Password.focus();
  //  return false;
  //}

  //3-PasswordVerify can not be empty.
  //if (isEmpty(el.PasswordVerify.value)) {
  //  alert ("Password verification must be specified.");
  //  el.PasswordVerify.focus();
  //  return false;
  //} else if (el.Password.value != el.PasswordVerify.value) {
  //  alert ("Password does not match Password verification\nPlease enter Password again.");
  //  el.Password.value = ""
  //  el.PasswordVerify.value = ""
  //  el.Password.focus();
  //  return false;
  //} 

  //4-FirstName can not be empty.
  if (isEmpty(el.FirstName.value)) {
    alert ("First Name must be specified.");
    el.FirstName.focus();
    return false;
  }

  //5-LastName can not be empty.
  if (isEmpty(el.LastName.value)) {
    alert ("Last Name must be specified.");
    el.LastName.focus();
    return false;
  }

  //6-EmailAddress can not be empty.
  //if (isEmpty(el.EmailAddress.value)) {
  //  alert ("Email Address must be specified.");
  //  el.EmailAddress.focus();
  //  return false;
  //}

  //7-Address1 can not be empty.
  if (isEmpty(el.Address1.value)) {
    alert ("Address must be specified.");
    el.Address1.focus();
    return false;
  }

  //8-City can not be empty.
  if (isEmpty(el.City.value)) {
    alert ("City must be specified.");
    el.City.focus();
    return false;
  }

  //9-State can not be empty.
  if (isEmpty(el.State.value)) {
    alert ("State must be specified.");
    el.State.focus();
    return false;
  }

  //10-Zip can not be empty.
  if (isEmpty(el.Zip.value)) {
    alert ("Zip / Posta code must be specified.");
    el.Zip.focus();
    return false;
  }

  //11-Country can not be empty.
  if (isEmpty(el.Country.value)) {
    alert ("Country must be specified.");
    el.Country.focus();
    return false;
  }

  return true;

}

function UpdateEvents () {
  //verify business rules before save

  var el = document.form;
  //1-Title can not be empty.
  if (isEmpty(el.Title.value)) {
    alert ("Title must be specified.");
    el.Title.focus();
    return false;
  }

  //2-Date can not be empty.
  if (isEmpty(el.EDYear.value)) {
    alert ("Date must be specified.");
    el.EDYear.focus();
    return false;
  }
}

function updateProfile () {
  //verify business rules before save

  var el = document.form;
  //1-UserId can not be empty.
  if (isEmpty(el.UserId.value)) {
    alert ("UserId must be specified.");
    el.UserId.focus();
    return false;
  }
  
  //2-Password can not be empty.
  if (isEmpty(el.Password.value)) {
    alert ("Password must be specified.");
    el.Password.focus();
    return false;
  }

  //3-PasswordVerify can not be empty.
  if (isEmpty(el.PasswordVerify.value)) {
    alert ("Password verification must be specified.");
    el.PasswordVerify.focus();
    return false;
  } else if (el.Password.value != el.PasswordVerify.value) {
    alert ("Password does not match Password verification\nPlease enter Password again.");
    el.Password.value = ""
    el.PasswordVerify.value = ""
    el.Password.focus();
    return false;
  } 

  //4-FirstName can not be empty.
  if (isEmpty(el.FirstName.value)) {
    alert ("First Name must be specified.");
    el.FirstName.focus();
    return false;
  }

  //5-LastName can not be empty.
  if (isEmpty(el.LastName.value)) {
    alert ("Last Name must be specified.");
    el.LastName.focus();
    return false;
  }

  //6-EmailAddress can not be empty.
  //if (isEmpty(el.EmailAddress.value)) {
  //  alert ("Email Address must be specified.");
  //  el.EmailAddress.focus();
  //  return false;
  //}

  //7-Address1 can not be empty.
  if (isEmpty(el.Address1.value)) {
    alert ("Address must be specified.");
    el.Address1.focus();
    return false;
  }

  //8-City can not be empty.
  if (isEmpty(el.City.value)) {
    alert ("City must be specified.");
    el.City.focus();
    return false;
  }

  //9-State can not be empty.
  if (isEmpty(el.State.value)) {
    alert ("State must be specified.");
    el.State.focus();
    return false;
  }

  //10-Zip can not be empty.
  if (isEmpty(el.Zip.value)) {
    alert ("Zip / Posta code must be specified.");
    el.Zip.focus();
    return false;
  }

  //11-Country can not be empty.
  if (isEmpty(el.Country.value)) {
    alert ("Country must be specified.");
    el.Country.focus();
    return false;
  }

  return true;

}


