﻿String.prototype.trim = function(){return this.replace(/(^\s*)|(\s*$)/g, "");}
//return false if email is not valid ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function checkEmail(checkThisEmail){
var myEMailIsValid = true;
var myAtSymbolAt = checkThisEmail.indexOf('@');
var myLastDotAt = checkThisEmail.lastIndexOf('.');
var mySpaceAt = checkThisEmail.indexOf(' ');
var myLength = checkThisEmail.length;
if (myAtSymbolAt < 1 ){myEMailIsValid = false}
if (myLastDotAt < myAtSymbolAt){myEMailIsValid = false}
if (myLength - myLastDotAt <= 2){myEMailIsValid = false}
if (mySpaceAt != -1){myEMailIsValid = false}return myEMailIsValid;}

function addbookmark(){
var url="http://www.galilcol.ac.il/";
var title="Galillee College";
if (window.sidebar) { // firefox
   //alert('firefox');
   window.sidebar.addPanel(title, url,"");
}else if(window.opera && window.print){ // opera
   var elem = document.createElement('a');
   elem.setAttribute('href',url);
   elem.setAttribute('title',title);
   elem.setAttribute('rel','sidebar');
   elem.click();
}else if(document.all)// ie
   window.external.AddFavorite(url, title);
}

String.prototype.trim = function(){return this.replace(/(^\s*)|(\s*$)/g, "");}
function MM_openBrWindow(theURL,winName,features){window.open(theURL,winName,features);}
function emptyField(textObj){if (textObj.value.length == 0) return true;for (var i=0; i<textObj.value.length; i++){var ch = textObj.value.charAt(i);if (ch != ' ' && ch != '\t') return false;}return true;}
function LoadIMG(siteUrl){document.getElementById('captcha_numchar').src=siteUrl+'global/captcha.asp?'+Date();}

function checkSearch(obj){
   if(obj.keySearch.value.trim() == ""){
   alert('Please fill in the " Search Keywords "');
   obj.keySearch.focus();return false;}
}

function check_contactForm(formObj) {		
	if (emptyField(formObj.name)) {window.alert('Please fill in the "Name"');formObj.name.focus();return false;}
	if (emptyField(formObj.Organisation)) {window.alert('Please fill in the "Organisation"');formObj.Organisation.focus();return false;}
	if (emptyField(formObj.phone)) {window.alert('Please fill in the "Phone"');formObj.phone.focus();return false;}	
	if (emptyField(formObj.email)) {window.alert('Please fill in the "Email"');formObj.email.focus();return false;}	
	if (formObj.email.value!='' && !checkEmail(formObj.email.value)) {alert('The "email" address is not in the correct format');formObj.email.select();return false;}	
	if (formObj.captchacode.value==''){alert('Please fill in the "Code"');formObj.captchacode.focus();return false;}
}

function check_registrationForm(formObj) {		
    if (emptyField(formObj.courseName)) {window.alert('Please fill in the "Course"');formObj.courseName.focus();return false;}
	if (emptyField(formObj.gender)) {window.alert('Please fill in the "Gender"');formObj.gender.focus();return false;}
	if (emptyField(formObj.firstName)) {window.alert('Please fill in the "First Name"');formObj.firstName.focus();return false;}	
	if (emptyField(formObj.surname)) {window.alert('Please fill in the "Surname"');formObj.surname.focus();return false;}	
	if (emptyField(formObj.birthDate)) {window.alert('Please fill in the "Date of Birth"');formObj.birthDate.focus();return false;}	
	if (emptyField(formObj.companyName)) {window.alert('Please fill in the "Name of Organisation"');formObj.companyName.focus();return false;}	
	if (emptyField(formObj.address)) {window.alert('Please fill in the "Address"');formObj.address.focus();return false;}	
	if (emptyField(formObj.country)) {window.alert('Please fill in the "Country"');formObj.country.focus();return false;}	
	if (emptyField(formObj.email)) {window.alert('Please fill in the "Email"');formObj.email.focus();return false;}	
	if (formObj.email.value!='' && !checkEmail(formObj.email.value)) {alert('The "email" address is not in the correct format');formObj.email.select();return false;}	
	if (formObj.captchacode.value==''){alert('Please fill in the "Code"');formObj.captchacode.focus();return false;}
}

function onsubmi_form_alumni(formObj){
  var programID="",courseID="",countryID="",str_action="";
  countryID=new String(document.getElementById('countryID').value);
  var str_courses=new String(document.getElementById('search_courseID').value);
  if (str_courses!=''){arrCourses=str_courses.split("_");programID = arrCourses[0];courseID = arrCourses[1];}
  if (programID!='' && !isNaN(programID) && (courseID=='' || courseID=='0')){
     str_action=site_url+"alumni/?programID="+programID
  }else if( programID!='' && !isNaN(programID) && (courseID!='' && courseID!='0') ){
     str_action=site_url+"alumni/?courseID="+courseID;
  }else if( (programID=='' || isNaN(programID)) && (courseID!='' && courseID!='0') ){
     str_action=site_url+"alumni/?courseID="+courseID;
  }
  if (str_action!="" && countryID!=""){
     str_action=str_action+"&countryID="+countryID;
  }else if (str_action=="" && countryID!=""){
     str_action=site_url+"alumni/?countryID="+countryID;
  }
  if (str_action=="" ){site_url+"alumni/";}
  formObj.action=str_action;
  return true;
}

function check_loginForm() {
var pr = {};
pr['pr_memberEmail'] = $F('memberEmail');
pr['pr_memberPassword'] = $F('memberPassword');
if(pr['pr_memberEmail']=='' && pr['pr_memberPassword']==''){alert('Please fill in the "Email" and "Password" ');document.getElementById('memberEmail').focus();return false;}
if(pr['pr_memberEmail']==''){alert('Please fill in the "Email"');document.getElementById('memberEmail').focus();return false;}
if (pr['pr_memberEmail']!=''  && !checkEmail(pr['pr_memberEmail'])){alert('The "email" address is not in the correct format');document.getElementById('memberEmail').select();return false;}
if(pr['pr_memberPassword']==''){alert('Please fill in the "Password"');document.getElementById('memberPassword').focus();return false;}
$('login_error').style.display='none';
$('login_indicator').style.display='block';
var rq = new Ajax.Request(
site_url+'login/get_login.asp', {method:'post',postBody: $H(pr).toQueryString(),
onComplete: function(req) {
//alert(req.responseText);
if (req.status == '200' && req.responseText == '') {
   $('login_indicator').style.display='none';
   on_login();
   //$('login_error').update(req.responseText);
} else{
   $('login_indicator').style.display='none';
   $('login_error').update(req.responseText);
   $('login_error').style.display='block';
}
}});
}

function on_login(){
   closeMessage();
   displayMessage(site_url+'login/login.asp',660,400);
}

function check_forgotPassword(formObj) {		
  if (emptyField(formObj.forgotEmail)) {window.alert("Please fill in the 'Email'");formObj.forgotEmail.focus();return false;}	
  if ( formObj.forgotEmail.value!='' && !checkEmail(formObj.forgotEmail.value)){alert("The email address is not in the correct format");formObj.forgotEmail.focus();return false;}	
  var pr = {};
  pr['forgotEmail'] = $F('forgotEmail');
  $('login_error').style.display='none';
  $('login_indicator').style.display='block';
  var rq = new Ajax.Request(
    site_url+'login/get_forgotPassword.asp', {method:'post',postBody: $H(pr).toQueryString(),
    onComplete: function(req) {
    // alert(req.responseText);
    $('login_indicator').style.display='none';
    $('login_error').update(req.responseText);
    $('login_error').style.display='block';
    }});
}

function addText(id) {
	var container = document.getElementById(id);
	var para = container.getElementsByTagName('p')[0];
	container.insertBefore(para.cloneNode(true), container.firstChild);
}

/* projects */
function onsubmi_form_projects(formObj){
  var projectCatID="",countryID="",str_action="";
  countryID=new String(document.getElementById('countryID').value);
  projectCatID=new String(document.getElementById('projectCatID').value);
  if( (countryID!='') ){
      str_action=site_url+"projects/country.asp?countryID="+countryID;
      if(projectCatID!='' && !isNaN(projectCatID)){
         str_action+="&projectCatID="+projectCatID;
      }
  }else if( projectCatID!='' && !isNaN(projectCatID) && (countryID!='') ){
     str_action=site_url+"projects/search.asp?projectCatID="+projectCatID+"&countryID="+countryID;
  }else if (projectCatID!='' && !isNaN(projectCatID)){
     str_action=site_url+"projects/search.asp?projectCatID="+projectCatID;
  }
  if (str_action=="" ){site_url+"projects/search.asp";}
  formObj.action=str_action;
  return true;
}

function projects_categories(){
  var countryID=new String(document.getElementById('countryID').value);
  var projectCatID=new String(document.getElementById('hidden_projectCatID').value);
  var url=new String();
  var url = site_url+"projects/get_projects_categories.asp?countryID="+countryID+"&projectCatID="+projectCatID;  
  var div_update="projectCatID";
  new Ajax.Request(url,{method: 'get', onComplete: function(req) {if (req.status == '200' && req.responseText != '') {$(div_update).update(req.responseText);} } } )
}

function projects_countries(){
  var projectCatID=new String(document.getElementById('projectCatID').value);
  var countryID=new String(document.getElementById('hidden_countryID').value);
  var url=new String();
  var url = site_url+"projects/get_projects_countries.asp?projectCatID="+projectCatID+"&countryID="+countryID;  
  var div_update="countryID";
  new Ajax.Request(url,{method: 'get', onComplete: function(req) {if (req.status == '200' && req.responseText != '') {$(div_update).update(req.responseText);} } } )
}
