var ajax_list_objects = new Array();
var thevalues = ''
function ajax_fillOptions(sectionid,typeid,e) { 
var ajaxIndex = ajax_list_objects.length;
ajax_list_objects[ajaxIndex] = new sack();
var url = '/community/autofillfategorykeyword?typeid=' + typeid + '&sectionid=' + sectionid;   	  
ajax_list_objects[ajaxIndex].requestFile = url;	// Specifying which file to get
ajax_list_objects[ajaxIndex].onCompletion = function()
{
    ajax_option_list_showContent(ajaxIndex); 
};	
// Specify function that will be executed after file has been found
ajax_list_objects[ajaxIndex].runAJAX();		// Execute AJAX function
  } 	
  
 function sack(file) {
 this.xmlhttp = null;
 this.resetData = function() {
 this.method = "POST";
 this.queryStringSeparator = "?";
 this.argumentSeparator = "&";
 this.URLString = "";
 this.encodeURIString = true;
 this.execute = false;
 this.element = null;
 this.elementObj = null;
 this.requestFile = file;
 this.vars = new Object();
 this.responseStatus = new Array(2);
 };
 this.resetFunctions = function() {
  this.onLoading = function() { };//document.getElementById("loading").style.display='block'; };
  this.onLoaded = function() { };
  this.onInteractive = function() { };// document.getElementById("loading").style.display='none'; };
  this.onCompletion = function() { };
  this.onError = function() { };
  this.onFail = function() { };
 };
 this.reset = function() {
  this.resetFunctions();
  this.resetData();
 };
 this.createAJAX = function() {
  try {
   this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e1) {
  try {
   this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
   this.xmlhttp = null;
  } }
  if(! this.xmlhttp) {
   if(typeof XMLHttpRequest != "undefined") {
    this.xmlhttp = new XMLHttpRequest();
   } else {
    this.failed = true;
 } } };
 this.setVar = function(name, value){
  this.vars[name] = Array(value, false);
 };
 this.encVar = function(name, value, returnvars) {
  if (true == returnvars) {
   return Array(encodeURIComponent(name), encodeURIComponent(value));
  } else {
   this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
 } }
 this.processURLString = function(string, encode) {
  encoded = encodeURIComponent(this.argumentSeparator);
  regexp = new RegExp(this.argumentSeparator + "|" + encoded);
  varArray = string.split(regexp);
  for (i = 0; i < varArray.length; i++){
   urlVars = varArray[i].split("=");
   if (true == encode){
    this.encVar(urlVars[0], urlVars[1]);
   } else {
    this.setVar(urlVars[0], urlVars[1]);
 } } }
 this.createURLString = function(urlstring) {
  if (this.encodeURIString && this.URLString.length) {
   this.processURLString(this.URLString, true);
  }
  if (urlstring) {
   if (this.URLString.length) {
    this.URLString += this.argumentSeparator + urlstring;
   } else {
    this.URLString = urlstring;
  } }
  // prevents caching of URLString
  this.setVar("rndval", new Date().getTime());
  urlstringtemp = new Array();
  for (key in this.vars) {
   if (false == this.vars[key][1] && true == this.encodeURIString) {
    encoded = this.encVar(key, this.vars[key][0], true);
    delete this.vars[key];
    this.vars[encoded[0]] = Array(encoded[1], true);
    key = encoded[0];
   }
   urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
  }
  if (urlstring){
   this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
  } else {
   this.URLString += urlstringtemp.join(this.argumentSeparator);
  } }
  this.runResponse = function() {
   eval(this.response);
  }
  this.runAJAX = function(urlstring) {
   if (this.failed) {   
   this.onFail();
   } else {		
    this.createURLString(urlstring);
    if (this.element) {
      this.elementObj = document.getElementById(this.element);
    } if (this.xmlhttp) {    
      var self = this;
      if (this.method == "GET") {					
        totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;      
        this.xmlhttp.open(this.method, totalurlstring, true);
      } else {					
        this.xmlhttp.open(this.method, this.requestFile, true);
        try {
         this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
        } catch (e) { alert("error"); }
     }
     this.xmlhttp.onreadystatechange = function() {
      switch (self.xmlhttp.readyState) {
      case 1:
      self.onLoading();
      break;
      case 2:
      self.onLoaded();
      break;
      case 3:
      self.onInteractive();
      break;
      case 4:
      self.response = self.xmlhttp.responseText;
      self.responseXML = self.xmlhttp.responseXML;
      self.responseStatus[0] = self.xmlhttp.status;
      self.responseStatus[1] = self.xmlhttp.statusText;
      if(self.execute) {
        self.runResponse();
      }
      if(self.elementObj) {
        elemNodeName = self.elementObj.nodeName;
        elemNodeName.toLowerCase();
        if (elemNodeName == "input"
        || elemNodeName == "select"
        || elemNodeName == "option"
        || elemNodeName == "textarea") {
         self.elementObj.value = self.response;
        } else {
          self.elementObj.innerHTML = self.response;
      } }
      if (self.responseStatus[0] == "200") {
       self.onCompletion();
      } else {
       self.onError();
      }
      self.URLString = "";
      break;
   } };   
   this.xmlhttp.send(this.URLString);
  } } };
  this.reset();
  this.createAJAX();
}

function ajax_option_list_showContent(ajaxIndex)	{  
   var content = ajax_list_objects[ajaxIndex].response;   
   document.getElementById('p_section_text').value = content; 
  }	

function hideWhenApplyedvalue(){	
for (x=1; x<=20 ;x++ )
{if(document.getElementById('p_buttonflag'+x).value=='Y')
{document.getElementById('linkapply'+x).style.display='none';}
}}
// Hide script from old browsers
// General form validation 


function isInCharacterLimit(string, limit) {
	if (string.length<=limit) 
	return true; 
	else return false;
}
function isFilledIn(string) {
	if (string.length>0) return true;
	else return false;
}
function isEmail(string) {
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)  return true;
	else return false; 	
}
function isValueSelected(selectBox) {
	if (selectBox.options[selectBox.selectedIndex].value!="") return true;
	else return false;
}
function isValueThis(selectBox, value) {
	if (selectBox.options[selectBox.selectedIndex].value==value) return true; 
	else return false; 
}

// this is a temporary fix
function valueSelected(selectBox) {
	if (selectBox.options[selectBox.selectedIndex].value!="") return true;
	else return false;
}
function isRadioSelected(radioGroup) {
  radioPass = false
  for(var i = 0; i < radioGroup.length; i++) {
    if (radioGroup[i].checked == true) {
	  radioPass = true
	}
  }
  if (radioPass==true) return true;
    else return false;
} 
function isDate(string) {
	datecomps=string.split("/");
	isDate=((datecomps.length==3)&&(datecomps[2].length==2)&&(parseInt(datecomps[1])<=12)&&parseInt(datecomps[0])<=31);	
	return isDate;
}
function isSame(string1,string2) {
	if (string1 == string2) return true;
	else return false;
}
function isNumber(string) {
	num=parseFloat(string);
	if (isNaN(num)) return false;
	else return true;
}
function isNumeric(string) {
	if (string.match(/[^0-9\.\,\,\=\+\-\*\|\[\]\{\}\<\>\(\)\%\$\£\#\&]/))  return false;
	else return true;	
}

/* Functions that validate the field value on the run */
function checkDate(object) {
	if (object.value != '') {
	  string=(object.value)
	  if (!string.match(/^(3[01]|0[1-9]|[12]\d)\/(0[1-9]|1[012])\/(\d{2})$/)) {
	    alert("Date field is not in the correct format (DD/MM/YY)");
	    object.focus();
	  }
	}
}
function checkNumber(object) {
	if (object.value != '') {
	  num = object.value
	  if (isNaN(num)) {
	    alert("Number field is not in the correct format");
	    object.focus();
	  }
	}
}
function checkNumeric(object) {
	if (object.value != '') {
	  string = object.value
	  if (string.match(/[^0-9\.\,\,\=\+\-\*\|\[\]\{\}\<\>\(\)\%\$\£\#\&]/) != null) {
	    alert("Numeric field is not in the correct format");
	    object.focus();
	  }
	}	
}
function checkEmail(object) {
	if (object.value != '') {
	  string = object.value
	  if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1) {
	    alert("Email field is not in the correct format");
	    object.focus();
	  }
	}
}
function checkMandatory(form) {
var pass=true;
for (i=0;i<form.length;i++) {
   var tempobj=form.elements[i];
   if (tempobj.name.substring(0,3)=="pm_") {
     if (((tempobj.type=="text" || tempobj.type=="textarea" || 
tempobj.type=="password") && trimString(tempobj.value)=='') || 
(tempobj.type.toString().charAt(0)=="s" && 
tempobj.options[tempobj.selectedIndex].value=='')) {
     pass=false;
     break;
     }
   }
}

if (!pass) { 
  alert("Please ensure that all the required fields are properly completed.");
  tempobj.focus();
  return false;
}
  else return true;
}

function no_enter() {
  return !(window.event && window.event.keyCode == 13); }
  
var done = 0;
function confirmButton (msg) {
   if ( done == 1 ) {
     alert ("This form is busy processing, please wait");
     return false;
   }

   if (confirm (msg)) {
     done = 1;
     return true;
   }
   else {
     return false;
   }
}

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 countOccurances(str, chr){
   var count = 0;
   for (i = 0;  i < str.length;  i++)
   {
      if (chr == str.charAt(i)) count++;
   }
   return count;
}

function isEmailAddressValid(str)
{
  var c, count, domain;
  validEmailChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_@.-`";
     s = stripCharsInBag(str,validEmailChars);

     if (s != "") {
     alert ("Your email address can only include numbers, letters, or _, @, ., ` and -");
     return (false); //email can only include numbers, letters, or _, @, .,` and  -.
     }

     if (str.length < 5) {
     alert ("Your email address needs to be at least 5 characters long");
     return (false); //email has to be at least 5 characters long
     }

     if (countOccurances(str, "@") == 0 || countOccurances(str, "@") > 1) {
     alert ("Your email address can have 1 and only 1 @");
     return (false); //email can have 1 and only 1 @.
     }

     if (countOccurances(str, ".") == 0) {
     alert ("Your email address needs to have at least one dot");
     return (false); //email has to have at least one dot.
     }
	if(!(countdot(str,".")))
	{
	    alert ("Your email address can have only one dot(.)");
		 return (false); //email has to have at least one dot.
	}
     if (((str.length - str.lastIndexOf(".")) > 7) || ((str.length - str.lastIndexOf(".")) < 3)) {
     alert ("Your email address has an incorrect number of characters after the last dot");
     return (false); //After the last dot, there cannot be more than 6 or less than 2 characters
     }

     if (str.charAt(str.indexOf("@") + 1) == "_") {
     alert ("Your email address cannot have an underscore right after the @");
     return (false); //Cannot have an underscore right after the @.
     }

     if (str.charAt(str.indexOf("@") + 1) == ".") {
     alert ("Your email address cannot have a dot right after the @");
     return (false); //Cannot have a dot right after the @.
     }
     
    var emailRegEx =/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;  
    if(str.match(emailRegEx)){   
      return true;
    }else{
      alert('Please enter a valid email address.');
      return false;
     }

     return (true);
}
 
/* checking that the keyword is filled in on the searches */
function checkmand(which) {
	if (document.searchForm.phrase_search.value == "")
		{
			alert("You must enter a subject keyword.");
			document.searchForm.phrase_search.focus();
			return (false);
		}
	else if (document.searchForm.phrase_search.value == "Enter subject keyword")
		{
			alert("You must enter a subject keyword.");
			document.searchForm.phrase_search.focus();
			return (false);
		}
	else
	return true;
}


function eea06(){
window.open("/html/bc_alpha/eeacountries06.html", "pop_up", "resizable=0,scrollbars=1,toolbar=0,location=0,menubar=0,status=0,width=400,height=400,left=400,top=400");}

// End hiding script from old browsers 

// Schoolsnet registration validation 

function checkschoolMandatory(form) 
  {
    var pass=true;
    for (i=0;i<form.length;i++) 
    {
      var tempobj=form.elements[i];
      if (tempobj.name.substring(0,3)=="pm_") 
      {
        if (((tempobj.type=="text" || tempobj.type=="textarea" || 
        tempobj.type=="password") && tempobj.value=='') || 
        (tempobj.type.toString().charAt(0)=="s" && 
        tempobj.options[tempobj.selectedIndex].value=='')) 
        {               	 
            pass=false;
            break;
        }
      }
    }
    if (document.regForm.p_1437.checked == false)
      {
        if (document.regForm.p_1439.checked == false && document.regForm.p_1440.checked == false && 
        document.regForm.p_1441.checked == false && document.regForm.p_1442.checked == false && 
        document.regForm.p_1443.checked == false && document.regForm.p_1444.checked == false) 
        {
          pass=false;
        }
      }
    if (!pass) 
    { 
      alert("Please ensure that all the required fields are properly completed.");
      tempobj.focus();
      return false;
    }
    else return true;
  }


function trimString (str) {
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function countdot(str,chr)
{
   var count = 0;
   retval=true;
   for (i = 0;  i < str.length;  i++)
   {
      if (chr == str.charAt(i)) 
	  {
		 if (chr == str.charAt(i+1))
		 {
			retval=false;
		 }
	  }
   }
  return retval;
}

//Added by Santhosh for validating the age
function checkAge()
{
	if(document.getElementById("pm_1455").value=="09")
		document.getElementById("pm_1455").value="9";	
	else if(document.getElementById("pm_1455").value=="08")
		document.getElementById("pm_1455").value="8";

	var str=document.getElementById("pm_1455").value;
	var age=parseInt(str);
	var flag=false;
	if(str!="" && isNaN(age))
	{
		alert("Age should be a number");
		flag=true;
	}
	else if(str!="" && age==0)
	{
		alert("Age should not be 0");
		flag=true;
	}
	else if(str!="" && age<0)
	{
		alert("Age should not be a negative");
		flag=true;
	}
	if(flag)
	{
		document.getElementById("pm_1455").value="";
		document.getElementById("pm_1455").focus();
	}
	else
	{
		if(str!="")
			document.getElementById("pm_1455").value=age;
	}
}
// End 

//Magazine manager freezing header/column function
var mainscroll;
var mtopright;
var mbottomright;
var mbottomleft;
var IE = (document.all) ? true : false;
var last_x = 0;
var last_y = 0;
function synchronizeScroll() {
	document.getElementById("mbottomleft").scrollTop=0;
	document.getElementById("mbottomright").scrollTop=0;
	document.getElementById("mbottomright").scrollLeft=0;
	document.getElementById("mtopright").scrollLeft=0;
		if (document.getElementById("mainscroll").scrollLeft) {
			document.getElementById("mbottomright").scrollLeft = document.getElementById("mainscroll").scrollLeft;
			document.getElementById("mtopright").scrollLeft = document.getElementById("mainscroll").scrollLeft;
		}
		if (document.getElementById("mainscroll").scrollTop) {
			document.getElementById("mbottomleft").scrollTop = document.getElementById("mainscroll").scrollTop;
			document.getElementById("mbottomright").scrollTop = document.getElementById("mainscroll").scrollTop;
		}
}
function scrolllevel() {
	document.getElementById("scrollablevalue").style.height=document.getElementById("mbottomleft").scrollHeight+50+"px";
	document.getElementById("scrollablevalue").style.width=document.getElementById("mbottomright").scrollWidth+275+"px";
}



// Script for backoffice
// Added by Meikandan on 03-11-2008

function doSubmit(thisform)
{
  var str = trimString(thisform.p_search_text.value);
  if (str.length==0)
  {
    alert ("Please enter keyword to search");
    return false;
  }
  else
  { 
    return true;                 
  }
}

function applythelinktext(text,link,buttonnumber)
{	
var linktext= document.getElementById('linktext'+buttonnumber).value;
var pointinglink =document.getElementById('pointlink'+buttonnumber).value;
if(linktext.lenght==0|| linktext =="" || pointinglink.lenght == 0 || pointinglink == "")
{
alert("Please enter both text and link values")
}
else
{
document.getElementById('p_buttonflag'+buttonnumber).value = "Y";
document.getElementById('p_linktextflag'+buttonnumber).value = "Y";
document.getElementById('linkapply'+buttonnumber).style.display='none';
document.getElementById('linkrevert'+buttonnumber).style.display='block';	
}
}

function revertthelinktext(text,link,buttonnumber)
{
document.getElementById('p_buttonflag'+buttonnumber).value = "N";
document.getElementById('p_linktextflag'+buttonnumber).value = "N";
document.getElementById('linkrevert'+buttonnumber).style.display='none'
document.getElementById('linkapply'+buttonnumber).style.display='block'
}

 function trimString (str) {
     str = this != window? this : str;
     return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
 }

function hideWhenApplyedvalue()
{
for (var x=1;x<=20 ; x++ )
{
	if (document.getElementById('p_buttonflag'+x).value=='Y')
	{	document.getElementById('linkapply'+x).style.display='none';	}
}
}

