// MODLOG001 23 JANUARY 2006 In line 42 FUNCTION openFavourites()the height 
// is been changed to min-height=495px
// MODLOG002  06-Jun-2007 Infosys       BPPLUS-2030: To allow apostrophe in email address
// MODLOG003  21-Apr-2008 Infosys		BPPLUS-2959: To allow a '.' before '@' in email address.
// MODLOG004  16-Sep-2008 Infosys       BPPLUS-3025: email addresses containing .- are rejected in user admin
// MODLOG005  15-Jun-2009 Infosys		BPPLUS-3748:  To allow '-' before '@' in email address.

// *****************************************************************************
// Preload Images for Footer
// *****************************************************************************
function preloadImages() {
	if (document.images) {
		image5on = new Image(); image5on.src = "/images/footer/ft_pos1_on.gif";
		image6on = new Image(); image6on.src = "/images/footer/ft_pos2_on.gif";
		image7on = new Image(); image7on.src = "/images/footer/ft_pos3_on.gif";
		image8on = new Image(); image8on.src = "/images/footer/ft_pos4_on.gif";
		image9on = new Image(); image9on.src = "/images/footer/ft_pos5_on.gif";
		
		image5off = new Image(); image5off.src = "/images/footer/ft_pos1_off.gif";
		image6off = new Image(); image6off.src = "/images/footer/ft_pos2_off.gif";
		image7off = new Image(); image7off.src = "/images/footer/ft_pos3_off.gif";
		image8off = new Image(); image8off.src = "/images/footer/ft_pos4_off.gif";
		image9off = new Image(); image9off.src = "/images/footer/ft_pos5_off.gif";
	}
}

// *****************************************************************************
// Specific/Special Custom functions
// *****************************************************************************
function changeImages() {
	if (document.images) {
		for (var i=0; i<changeImages.arguments.length; i+=2){
			document[changeImages.arguments[i]].src = eval(changeImages.arguments[i+1] + ".src");
	  }
	}
}
// *****************************************************************************
// Open a modal dialog window for the favourites screen.!
// *****************************************************************************
function openFavourites()
{
	var leftVal,topval;
	leftVal = (screen.width-423) / 2;
	topVal = (screen.height-498) / 2;
    // MODLOG001 STARTS
	window.open("/pages/am/Favourites.asp","_blank","Height=495px,Width=417px,left=" + leftVal + "px, top=" + topVal +"px, location=no, menubar=no, scrollbars=no, center=Yes, help=No,resizable=No, status=No, ","");
    // MODLOG001 ENDS
}


// *****************************************************************************
// Open a window!
// *****************************************************************************
function newwin(location) {
	window.open (location);
}

function isEmailAddress (string) {
// *****************************************************************************
// Validate an email address
// *****************************************************************************
  //MODLOG002 Starts
  //MODLOG003 Starts
	//var addressPattern = /^\w+((-\w+)|(\.\w+)|(\'\w+))*\@[A-Za-z0-9\']+((\.|-)[A-Za-z0-9\']+)*\.[A-Za-z0-9\']+$/;  
    //MODLOG004 Starts
    //var addressPattern = /^\w+((-\w+)|(\.\w+)|(\'\w+))*([.]{0,1})\@[A-Za-z0-9\']+((\.|-)[A-Za-z0-9\']+)*\.[A-Za-z0-9\']+$/;  
    	//MODLOG005  Starts
	//var addressPattern = /^\w+((-\w+)|(\.\w+)|(\.\-\w+)|(\'\w+))*([.]{0,1})\@[A-Za-z0-9\']+((\.|\-|\.\-)[A-Za-z0-9\']+)*\.[A-Za-z0-9\']+$/; 
	  var addressPattern = /^\w+((-\w+)|(\.\w+)|(([\.\-]{0,2})\w+)|(\'\w+))*([\.\-]{0,2})\@[A-Za-z0-9\']+(([\.\-]{0,2})[A-Za-z0-9\']+)*([\.\-]{0,2})[A-Za-z0-9\']+$/; 
	//MODLOG005 Ends  
    //MODLOG004 Ends
  //MODLOG003 Ends
  //MODLOG002 Ends
  return addressPattern.test(string);
}

// *****************************************************************************
// Validate the search form. User must enter a query
// *****************************************************************************
function validateStdFooterSearchForm() {
  if ((document.forms["stdfootersearch"].keyword.value) == SearchValidationContentArray[0]) {
    alert(SearchValidationContentArray[1])
    return false;
  }    
  if ((document.forms["stdfootersearch"].keyword.value) == "") {
    alert(SearchValidationContentArray[1])
    return false;
  }    
  return true;
}

// *****************************************************************************
// Validate the registration form. User must enter a query
// *****************************************************************************
function validateRegistrationForm() {
  if (!isEmailAddress(document.forms["registration"].email.value)) {
    alert("Please enter a valid email address (e.g. someone@company.com)")
    document.forms["registration"].email.focus()
    return false;
  }    
  if ((document.forms["registration"].password.value) == "") {
    alert("Please enter a password")
    document.forms["registration"].password.focus()
    return false;
  }    
  if (document.forms["registration"].password.value.length < 8) {
    alert("Please enter a password of 8 or more characters")
    document.forms["registration"].password.focus()
    return false;
  }    
  if ((document.forms["registration"].passwordconfirmation.value) == "") {
    alert("Please enter a password confirmation")
    document.forms["registration"].passwordconfirmation.focus()
    return false;
  }    
  if (document.forms["registration"].password.value != document.forms["registration"].passwordconfirmation.value) {
    alert("Your password and your password confirmation do not match")
    document.forms["registration"].password.focus()
    return false;
  }    
  if ((document.forms["registration"].fname.value) == "") {
    alert("Please enter your first name")
    document.forms["registration"].fname.focus()
    return false;
  }    
  if ((document.forms["registration"].lname.value) == "") {
    alert("Please enter your last name")
    document.forms["registration"].lname.focus()
    return false;
  }    
  return true;
}

function IsNumeric(strString) {
  //  check for valid numeric integer strings  
  var strValidChars = "0123456789";
  var strChar;
  var blnResult = true;

  //  test strString consists of valid characters listed above
  for (i = 0; i < strString.length && blnResult == true; i++)
    {
    strChar = strString.charAt(i);
    if (strValidChars.indexOf(strChar) == -1)
       {
       blnResult = false;
       }
    }
  return blnResult;
}

// *****************************************************************************
//  function for the aral template to ensure the page resizes when the window does.
// *****************************************************************************
function calcdivsize(){
	if (document.body.clientHeight >= 115){
		document.getElementById("maincontentdiv").style.height=document.body.clientHeight - 115;
	}
	if (document.body.clientWidth >= 165){
		document.getElementById("maincontentdiv").style.width=document.body.clientWidth - 165;
	}
}


// *****************************************************************************
//  function for swapping images over
// *****************************************************************************
function swapImage(imgname,newsrc) { 
  document.getElementById(imgname).src = newsrc;
}

// *****************************************************************************
//  function for opening window
// *****************************************************************************
function openBrWindow(theURL,winName,features) { 
  window.open(theURL,winName,features);
}

// *****************************************************************************
//  function for Loadpage from menu
// *****************************************************************************
function Loadpage(surl,targ){
if (targ == "_blank"){
	openBrWindow(surl,"",""); 
}else{
	window.location = surl;
}
}

// *****************************************************************************
//  function for trimming a string
// *****************************************************************************
function fnTrim (str) {
  //str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
