var TimeOutID;
TimeOutID = 0;
var skillWin, jtWin;

//DEV
var gstrBaseURL = "http://pfj.hotlizard-hosting.co.uk/default.asp";
var gstrGRCURL = "http://pfj1.hotlizard-hosting.co.uk/default.asp";
//LIVE
//var gstrBaseURL = "http://pfj.hotlizard-hosting.co.uk/default.asp";
//var gstrGRCURL = "http://pfj1.hotlizard-hosting.co.uk/default.asp";

function SetMenuTimeout() {
   ResetTimeout();
   TimeOutID = setTimeout('ClearDownMenu();',5000);
}

function ClearDownMenu() {
   MM_showHideLayers('Layer1','','hide','Layer2','','hide');
}

function ResetTimeout() {
   clearTimeout(TimeOutID);
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function CheckEmail(formname,fieldname) {

	// If the email entry box has something in it carry out the email
	// address validation, otherwise just return true
	if (formname.value.length > 0) {

		// split the entered string at the @ sign, if
		// there aren't at least 2 array elements created
		// no @ sign was entered so therefore it is an
		// invalid email address so return false.
		string = formname.value;
		check_for_at = string.split("@");

		if ( ! check_for_at[0] || ! check_for_at[1] ) {
			alert(fieldname + ' must be a valid email address');
			return false;
		} else {

			// If there is a valid @ sign, split the second
			// half of the string by the first dot.  If
			// there aren't at least 2 array elements created
			// no . was entered so therefore it is an
			// invalid email address so return false.
			check_for_dot = check_for_at[1].split(".");
			if ( ! check_for_dot[0] || ! check_for_dot[1] ) {
				alert(fieldname + ' must be a valid email address');
				return false;
			}
		}
	}
	return true;
}

function CheckEmail2(astrEmailAddress) {
	var reEMail = /^\S+@\S+\.\S+$/;
	return reEMail.test(astrEmailAddress);
}


function CheckEmail(formname,fieldname) {

	// If the email entry box has something in it carry out the email
	// address validation, otherwise just return true
	if (formname.value.length > 0) {

		// split the entered string at the @ sign, if
		// there aren't at least 2 array elements created
		// no @ sign was entered so therefore it is an
		// invalid email address so return false.
		string = formname.value;
		check_for_at = string.split("@");

		if ( ! check_for_at[0] || ! check_for_at[1] ) {
			alert(fieldname + ' must be a valid email address');
			return false;
		} else {

			// If there is a valid @ sign, split the second
			// half of the string by the first dot.  If
			// there aren't at least 2 array elements created
			// no . was entered so therefore it is an
			// invalid email address so return false.
			check_for_dot = check_for_at[1].split(".");
			if ( ! check_for_dot[0] || ! check_for_dot[1] ) {
				alert(fieldname + ' must be a valid email address');
				return false;
			}
		}

		var re = / |;/;
		if ((/[ ;]/).exec(formname.value) != null) {
			alert(fieldname + ' must be a valid email address');
			return false;
		}
	}

	return true;
}

function CheckBlank(formname,fieldname)
{
	// If nothing has been entered return false

	var strTemp = formname.value;
	strTemp=strTemp.replace(/ /g,"");

	if (strTemp.length < 1) {
		alert('Please complete the "' + fieldname + '" field.');
		return false;
	} else {
		return true;
	}
}

function CheckTelephone(sText,fieldname)
{
	// If not a valid telephone number return false

	var ValidChars = " ()0123456789";
	var IsValid = true;
	var Char;

	for (i = 0; i < sText.value.length && IsValid == true; i++)
	{
	   Char = sText.value.charAt(i);
	   if (ValidChars.indexOf(Char) == -1)
	   {
	      IsValid = false;
	   }
	}

	if (IsValid == false)
	{
		alert('Please enter a valid "' + fieldname + '" number.');
		return false;
	}
	else
	{
		return true;
	}

}


function IsNumeric(sText)
{
	var ValidChars = "0123456789";
	var IsNumber = true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++)
		   {
	   Char = sText.charAt(i);
	   if (ValidChars.indexOf(Char) == -1)
	      {
	      IsNumber = false;
	      }
	   }
	return IsNumber;
}




function CheckExpiredDate(field, message)
{
    var checkstr = "0123456789";
    var DateTemp = "";

    var DateField = field;
    DateValue = DateField.value;

    /* Delete all chars except 0..9 */
    for (i = 0; i < DateValue.length; i++)
    {
        if (checkstr.indexOf(DateValue.substr(i,1)) >= 0)
        {
     		DateTemp = DateTemp + DateValue.substr(i,1);
    	}
    }

    DateValue = DateTemp;

    /* Always change date to 8 digits - string*/
    /* if year is entered as 2-digit / always assume 20xx */
    if (DateValue.length == 6)
    {
    	DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2);
    }


    var year = DateValue.substr(4,4);
    var month = DateValue.substr(2,2);
    var day = DateValue.substr(0,2);

    var now = new Date();
    now = now.getTime(); //NN3

    var dateToCheck = new Date();
    dateToCheck.setYear(year);
    dateToCheck.setMonth(month-1);
    dateToCheck.setDate(day);
    var checkDate = dateToCheck.getTime();

    if (now < checkDate)
    {
        return true;
    }
    else
    {
        alert('Please enter ' + message + ' in the future');
        return false;
    }
}


function CheckSelect(formname,fieldname,bMulti,Maxnoitems,bNoItems) {

	// If this is NOT a multi select
	if ( ! bMulti ) {

		// If the user is NOT allowed to select nothing (sounds a bit
		// strange but bear with me...)
		if ( ! bNoItems ) {

			// Check they haven't just selected the default option
			// or even just not selected anything at all.  If this is
			// the case return false.
			mySelectedIndex = formname.selectedIndex;
			if ( formname.options[mySelectedIndex].value<1 || formname.options[mySelectedIndex].value=="" ) {
				alert('Please select ' + fieldname);
				return false;
			}
		}
		return true;

	// If this IS a multi select list
	} else {

		// If the user is NOT allowed to select nothing (sounds a bit
		// strange but bear with me...)
		if ( ! bNoItems ) {

			// If selectedIndex is a negative value nothing
			// has been selected so print error and return false
			mySelectedIndex = formname.selectedIndex;
			if ( mySelectedIndex < 0 ) {
				alert('Please select ' + fieldname);
				return false;
			}

			// If a maximum number of items has been set check
			// that the user hasn't selected more.  If they have
			// print the error and return false.
			if ( Maxnoitems > 0 ) {
				numSelected = 0;
				for ( i=0; i<formname.options.length ; i++ ) {
					if ( formname.options[i].selected ) {
						numSelected++;
					}
				}
				if ( numSelected > Maxnoitems ) {
					alert('Only ' + Maxnoitems + ' options can be selected from the ' + fieldname + ' list');
					return false;
				}
			}
			return true;
		} else {
			// If the user IS allowed to select nothing, just check that
			// they haven't selected more than the maximum allowed (if
			// it is set)
			if ( Maxnoitems > 0 ) {
				numSelected = 0;
				for ( i=0; i<formname.options.length ; i++ ) {
					if ( formname.options[i].selected ) {
						numSelected++;
					}
				}
				if ( numSelected > Maxnoitems ) {
					alert('Only ' + Maxnoitems + ' options can be selected from the ' + fieldname + ' list');
					return false;
				}
			}
			return true;
		}

	}

}




function contains(smstring,lrgstring) {
        //returns true if lrgstring contains smstring.
        strlen1 = smstring.length
        strlen2 = lrgstring.length
        istrue = false
        for (i=0;i<=strlen2;i++) {
                comp=lrgstring.substring(i-1,strlen2)
                comp = comp.substring(0,strlen1)
                if (comp == smstring) {
                        istrue = true
                        break
                }
        }
        return istrue
}

function lcase(str) {
        //returns str in all lowercase letters.
        return str.toLowerCase()
}


function left(str,n) {
        //returns the left n characters from str.
        return str.substring(0,n)
}

function leftOf(smstring,lrgstring) {
        //returns leftmost characters of lrgstring up to smstring.
        //If user passes an empty string, change that to a space.
        if (smstring == ""){smstring = " "}
        strlen1 = smstring.length
        strlen2 = lrgstring.length
        foundat = 0
        for (i=0;i<=strlen2;i++) {
                comp=lrgstring.substring(i-1,strlen2)
                comp = comp.substring(0,strlen1)
                if (comp == smstring) {
                        foundat = i
                        break
                }
        }
        return lrgstring.substring(0,(foundat-1))
}

function mid(str,start,n) {
        //returns a substring of str starting at 'start' that's n characters long.
        strlen = str.length
        var jj = str.substring(start-1,strlen)
        jj = jj.substring(0,n)
        return jj
}

function pcase(str) {
        //returns str in proper-noun case (first letter uppercase)
        strlen = str.length
        jj = str.substring(0,1).toUpperCase()
        jj = jj + str.substring(1,strlen).toLowerCase()
        for (i = 2; i <= strlen; i++) {
                if (jj.charAt(i)==" ") {
                        lefthalf = jj.substring(0,i+1)
                        righthalf = jj.substring(i+1,strlen)
                        righthalf = righthalf.substring(0,1).toUpperCase()+righthalf.substring(1,strlen)
                        jj=lefthalf+righthalf
                }
        }
        return jj
}

function right(str,n) {
        //returns the right n characters of str
        strlen = str.length
        return str.substring(strlen-n,strlen)
}

function rightOf(smstring,lrgstring) {
        //returns the rightmost characters of lrgstring back to smstring.
        //If user passes an empty string, change that to a space.
        if (smstring == ""){smstring = " "}
        strlen1 = smstring.length
        strlen2 = lrgstring.length
        foundat = 0
        for (i=strlen2;i>=0;i--) {
                comp=lrgstring.substring(i-1,strlen2)
                comp = comp.substring(0,strlen1)
                if (comp == smstring) {
                        foundat = i
                        break
                }
        }
        return lrgstring.substring(foundat,255)
}

function spot(smstring,lrgstring) {
        //returns a number indicating the spot where smstring appears in lrgstring.
        strlen1 = smstring.length
        strlen2 = lrgstring.length
        foundat = 0
        for (i=0;i<=strlen2;i++) {
                comp=lrgstring.substring(i-1,strlen2)
                comp = comp.substring(0,strlen1)
                if (comp == smstring) {
                        foundat = i
                        break
                }
        }
        return foundat
}



function ucase(str) {
        //returns str in all uppercase letters.
        return str.toUpperCase()
}

// Create and display the progress dialog.
// end: The number of steps to completion
function ProgressCreate(end) {
	// Initialize state variables
	_progressEnd = end;
	_progressAt = 0;

	// Move layer to center of window to show
	if (document.all) {	// Internet Explorer
		progress.className = 'show';
		progress.style.left = (document.body.clientWidth/2) - (progress.offsetWidth/2);
		progress.style.top = (document.body.clientHeight/2) - (progress.offsetHeight/2);
	} else if (document.layers) {	// Netscape
		document.progress.visibility = true;
		document.progress.left = (window.innerWidth/2) - 100;
		document.progress.top = (window.innerHeight/2) - 40;
	}

	ProgressUpdate();	// Initialize bar
}

function MessageDisplay(id, str) {
  if (! document.all) {
    with (document[id].document) {
      open();
      write(str);
      close();
    }
  } else {
    document.all[id].innerHTML = str;
  }
}


function cleanNumber(inputNum)
     {
     var i;
     var ch;
      var outputNum = "";
     // walk through the string character by character to build a new string with numbers only
     i = 0;
     while (i < inputNum.length)
          {
          // get the current character
         ch = inputNum.substring(i, i+1);
          if ((ch >= "0") && (ch <= "9"))
           {
              // if the current character is a digit then add it to the numbers-only string we're building
           outputNum += ch;
           }
          else
           {
           // not a digit, so check if its a dash or a space
           if ((ch != " ") && (ch != "-")) {
                 // not a dash or a space so fail
                 // return "";
              }
            }
        i++;
     }
     // we got here if we didn't fail, so return what we built
      return outputNum;
}

// Submit a form (rather than using a submit image) and set the command value
function submitForm(formname,strCommand) {

   var thisObj = eval("document." + formname);
   thisObj.command.value = strCommand;
   thisObj.submit();

}

function setCookie(name, value, expires, path, domain, secure) {
// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments

  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) {
// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist

  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds

  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function fixDate(date) {
// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"

  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function check_date(field,fieldname){
   var checkstr = "0123456789";
   var DateField = field;
   var Datevalue = "";
   var DateTemp = "";
   var seperator = "/";
   var day;
   var month;
   var year;
   var leap = 0;
   var err = 0;
   var i;
   err = 0;
   DateValue = DateField.value;

   /* Delete all chars except 0..9 */
   for (i = 0; i < DateValue.length; i++) {
	  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
	     DateTemp = DateTemp + DateValue.substr(i,1);
	  }
   }
   DateValue = DateTemp;
   /* Always change date to 8 digits - string*/
   /* if year is entered as 2-digit / always assume 20xx */
   if (DateValue.length == 6) {
      DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
   if (DateValue.length != 8) {
      err = 19;}
   /* year is wrong if year = 0000 */
   year = DateValue.substr(4,4);
   if (year == 0) {
      err = 20;
   }
   /* Validation of month*/
   month = DateValue.substr(2,2);
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/
   day = DateValue.substr(0,2);
   if (day < 1) {
     err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      DateField.value = day + seperator + month + seperator + year;
   }
   /* Error-message if err != 0 */
   else {
     alert("Please enter a valid date (dd/mm/yyyy) in the " + fieldname + "field");
     DateField.select();
     DateField.focus();
   }
}

function CheckLength (formname,fieldname,minlength,maxlength) {
	if (minlength != 0) {
		if (formname.value.length < minlength) {
			alert(fieldname + ' must be greater than ' + minlength + ' characters.');
			return false;
		}
	}
	if (maxlength != 0) {
		if (formname.value.length > maxlength) {
			alert(fieldname + ' must be less than ' + maxlength + ' characters.');
			return false;
		}
	}

	return true;
}

function addBookmark() {
  if (window.external)
    external.AddFavorite('http://www.discjobs.com','Discjobs.com')
  else
    alert("Your browser doesn't support this feature.");
}

function openImageSelect (section) {
	var url='/admin/imagelibrary/imageSelect.asp?section=' + section;

//	var newWin = window.open(url);
	var newWin = window.open(url,'newWin','location=no,scrollbars=0,toolbar=no,width=400,height=250');

}

function OpenPopup (url, winname, width, height, options) {
	var w = 480, h = 340;

	if (document.all || document.layers) {
	  w = screen.availWidth;
	  h = screen.availHeight;
	}

	var leftPos = (w-width)/2, topPos = (h-height)/2;

	window.open(url,winname,'width=' + width + ',height=' + height + ',top=' + topPos + ',left=' + leftPos + ',' + options);
}

function openLogoView(url) {
	var newWin = window.open(url,'logoWin','location=no,scrollbars=1,toolbar=no,width=400,height=250');
}

//Submit dropdownform on LeftNav
function viewSectorContent (aintSectorID)	{
    //document.formSectorContent.action = "/MarketContent.asp";

//    if (aintSectorID == 2) { //GRC
//
//	if (document.formSectorContent.intSectorID.value != 0) {
//	    if (document.formSectorContent.intSectorID.value == 2) {
//		document.formSectorContent.action = "/Default.asp";
//	    } else {
//		document.formSectorContent.action = "/MarketContent.asp";
//	    }
//	    document.formSectorContent.submit();
//	}
//
//    } else {
//
	if (document.formSectorContent.intSectorID.value != 0) {
		switch(document.formSectorContent.intSectorID.value)
		{
		case "2":
			location.href = "http://www.grc.uk.net";
			break

		case "3":
			location.href = "http://www.pfj.co.uk/media_jobs.asp";
			break

		case "5":
			location.href = "http://www.pfj.co.uk/new_media_jobs.asp";
			break

		case "6":
			location.href = "http://www.pfj.co.uk/conferences_events_and_exhibition_jobs.asp";
			break

		case "7":
			location.href = "http://www.pfj.co.uk/editorial_jobs.asp";
			break

		case "9":
			location.href = "http://www.pfj.co.uk/information_research_and_knowledge_management_jobs.asp";
			break

		case "10":
			location.href = "http://www.pfj.co.uk/intellectual_property_jobs.asp";
			break

		case "11":
			location.href = "http://www.pfj.co.uk/recruitment_jobs.asp";
			break

		case "12":
			location.href = "http://www.pfj.co.uk/temporary_contract_and_interim_jobs.asp";
			break

		case "13":
			location.href = "http://www.pfj.co.uk/training_jobs.asp";
			break
		}
	}
}

//Submit Market Sector home pages
function MarketSectorHomePage (aintSectorID)	{
    document.formMarketSectorHomePage.action = "/Default.asp?intSectorID=" + aintSectorID;
    document.formMarketSectorHomePage.intSectorID.value = aintSectorID;
    document.formMarketSectorHomePage.submit();
}

//Submit View Microsite from front page
function frontpageViewMicrosite (aintMicrositeID)	{
    document.formFrontPageViewMicrosite.action = "/FeaturedClientView.asp";
    document.formFrontPageViewMicrosite.intMicrositeID.value = aintMicrositeID;
    document.formFrontPageViewMicrosite.submit();
}


//Submit VacancySearh
function vacancySearch (aintSectorID)	{
    document.formMarketSectorHomePage.action = "/vacancy_search.asp?intSectorID=" + aintSectorID;
    document.formMarketSectorHomePage.intSectorID.value = aintSectorID;
    document.formMarketSectorHomePage.submit();
}


// Show and hide divs

function ShowHide(id, display) {
    obj = document.getElementsByTagName("div");
    obj[id].style.display = display;
}

