function set_focus(d, el)
{
	if (!el)	// if form element not set - do nothing
		return;

	if ((x = findObj(e, d)) != null) {
		if (x.focus)
			x.focus();
		if (x.select)
			x.select();
	}
}

function openSpellChecker(thistextarea) {

//	var textarea1 = document.vacancyForm.vacancyDescription;
	// get the textarea we're going to check
	// give the spellChecker object a reference to our textarea
	// pass any number of text objects as arguments to the constructor:
	var speller = new spellChecker( thistextarea );
	speller.openChecker();

}

function syn(s)
{
	if (!s || !s.options || !s.options.length)
		return false;

	if (s.options[s.options.length - 1].selected)
		s.options[s.options.length - 1].selected = false;
}

function plesk_scroll(w)
{
	var nav = navigator.appName;
	var ver = parseInt(navigator.appVersion);
	if ((nav.indexOf('Netscape') != -1) && (ver == 4) && w.document.location.hash) {
		var aname = w.document.location.hash.substr(1);
		var an = w.document.anchors[aname];
		if (an)
			w.scrollTo(an.x, an.y);
	}
}

function MM_reloadPage(init)	// reloads the window if Nav4 resized
{
	if (init == true)
		with (navigator) {
			if ((appName == 'Netscape') && (parseInt(appVersion) == 4)) {
				document.MM_pgW = innerWidth;
				document.MM_pgH = innerHeight;
				onresize = MM_reloadPage;
			}
		}
	else
		if ((innerWidth != document.MM_pgW) || (innerHeight != document.MM_pgH))
			location.reload();
}

function getButtonName(name)
{
    re = /^bname_([A-Za-z0-9-]+)$/;
    return name.replace(re,"$1");
}


function isFramed()
{
	return !opt_no_frames && top.workFrame && top.leftFrame && top.topFrame;
}

function setActiveButtonByName(name)
{
	try {
		return top.leftFrame.setActiveNode(name);
	} catch (e) {
		return false;
	}
}

function setActiveButton(o)
{
	try {
		return top.leftFrame.setActiveNode(o.id);
	} catch (e) {
		return false;
	}
}

function setScrollInIE()
{
	try {
		var navL = top.leftFrame.document.getElementById ('pageLayout');
		top.leftFrame.document.body.scroll = (navL.clientHeight > top.leftFrame.document.documentElement.clientHeight || navL.clientWidth > top.leftFrame.document.documentElement.clientWidth) ? 'yes' : 'no';
	} catch (e) {
		return false;
	}
}

//---------------------------------- redirect

function get_workframe()
{
	try {
		if (top.workFrame.visibilityContent && !top.workFrame.removeMe)
			return top.workFrame.visibilityContent;
	} catch (e) {}
	if (top.workFrame)
		return top.workFrame;
	else
		return this;
}

function go_to(href)
{
	return go_to_workframe(href);
}

function go_to_workframe(href)
{
	_go_to(isFramed() ? get_workframe() : this, href);
}

function refresh_leftframe()
{
	_refresh(top.leftFrame);
}

function go_to_leftframe(href)
{
	_go_to(top.leftFrame, href);
}

function refresh_topframe()
{
	_refresh(top.topFrame);
}

function go_to_topframe(href)
{
	_go_to(top.topFrame, href);
}

function go_to_top(href)
{
	_go_to(top, href);
}

function _refresh(target)
{
	try {
		target.location.reload();
	} catch (e) {
		alert (e);
	}
}

function _go_to(target, href)
{
	try {
		target.location = href;
	} catch (e) {
	}
}

//---------------------------------- conhelp & help

function SetConHelp(conhelp_name, direct)
{
	try {
		return top.leftFrame._SetConHelp(conhelp_name, direct);
	} catch (e) {
		return false;
	}
}

function SetContext(context)
{
	SetHelpModule('');

	if (opt_integrated_mode && !opt_no_frames)
		return top.SetContext(context)

	try {
		if (context)
			top._context = context;
	} catch (e) {
		return false;
	}

	return SetConHelp();
}

function InitTips(path,key)
{
	try {
		return top._InitTips(path,key)
	} catch (e) {
		return false;
	}
}

function SetHelpModule(module)
{
	if (opt_integrated_mode && !opt_no_frames && top.SetHelpModule)
		return top.SetHelpModule(module)

	try {
		top._help_module = module;
	} catch (e) {
		return false;
	}

	return true;
}

function GetContext()
{
	try {
		return top._context;
	} catch (e) {
		return false;
	}
}

function GetHelpPrefix()
{
	try {
		return top._help_prefix;
	} catch (e) {
		return false;
	}
}

function GetHelpModule()
{
	try {
		return top._help_module;
	} catch (e) {
		return false;
	}
}

function mouse_move(context, direct)
{
	if (!opt_integrated_mode || opt_no_frames) {
		return SetConHelp(context, direct);
	} else {
		try {
			return top.mouse_move(context);
		} catch (e) {
			return false;
		}
	}
}

function lsetup_handler(e)
{
	lsetup(this);
	return true;
}

function lsetup(target)
{
	try {
		if (!target)
			target = this;

		var o_set = target.document.getElementById('loaderContainerWH');
		var o_getH = target.document.getElementsByTagName('BODY')[0];

		o_set.style.height = o_getH.scrollHeight;
	} catch (e) {
	}
}

function lon(target)
{
	try {
		if (parent.visibilityToolbar)
			parent.visibilityToolbar.set_display("standbyDisplayNoControls");
	} catch (e) {}

	try {
		if (!target)
			target = this;

		lsetup(target);

		if (!target._lon_disabled_arr)
			target._lon_disabled_arr = new Array();
		else if (target._lon_disabled_arr.length > 0)
			return true;

		target.document.getElementById("loaderContainer").style.display = "";
		var select_arr = target.document.getElementsByTagName("select");

		for (var i = 0; i < select_arr.length; i++) {
			if (select_arr[i].disabled)
				continue;

			select_arr[i].disabled = true;
			_lon_disabled_arr.pop(select_arr[i]);
			var clone = target.document.createElement("input");
			clone.type = "hidden";
			clone.name = select_arr[i].name;
			var values = new Array();
			for (var n = 0; n < select_arr[i].length; n++) {
				if (select_arr[i][n].selected) {
					values[values.length] = select_arr[i][n].value;
				}
			}
			clone.value = values.join(",");
			select_arr[i].parentNode.insertBefore(clone, select_arr[i]);
		}
	} catch (e) {
		return false;
	}
	return true;
}

function loff(target)
{
	try {
		if (parent.visibilityToolbar) {
			parent.visibilityToolbar.set_display(visibilityCount
												 ? "standbyDisplay"
												 : "standbyDisplayNoControls");
		}
	} catch (e) {}

	try {
		if (!target)
			target = this;

		target.document.getElementById("loaderContainer").style.display = "none";

		if (target._lon_disabled_arr) {
			while(_lon_disabled_arr.legth > 0) {
				var select = _lon_disabled_arr.push();
				select.disabled = false;

				var clones_arr = target.document.getElementsByName(select.name);
				for (var n = 0; n < clones_arr.length; n++) {
					if ("hidden" == clones_arr[n].type)
						clones_arr[n].parent.removeChild(clones_arr[n]);
				}
			}
		}
	} catch (e) {
		return false;
	}
	return true;
}

function lsubmit(f)
{
	try {
		if (f.lock.value == "true")
			return false;
		f.lock.value = "true";
	} catch (e) {
	}

	lon();

	try {
		f.submit(f);
	} catch (e) {
		return false;
	}
	return true;
}

function getParentNodeByName(o, name)
{
	var parent = o.parentNode;
	if (!parent)
		return false;
	if (parent.nodeName != name)
		return getParentNodeByName(parent, name);
	return parent;
}

function errorfield(o, status)
{
	var tr = getParentNodeByName(o, 'TR');
	if (!tr)
		return false;
	tr.className = status ? 'error' : '';
	return true;
}

function hasClass(element, className)
{
    var classes = element.className.split(' ');
	for (var i in classes) {
		if (classes[i] == className)
			return true;
	}
	return false;
}

function addClass(element, className)
{
	if (!hasClass(element, className))
		element.className = (element.className == '' ? className : element.className + ' ' + className);
}

function removeClass(element, className)
{
	var newValue = '';
    var classes = element.className.split(' ');
	for (var i in classes) {
		if (classes[i] != className)
			newValue += newValue.length ? ' ' + classes[i] : classes[i];
	}
	element.className = newValue;
}

function OpenThis(thisURL,thisW,thisH, thisName, thisScroll)
  {
      window.open(thisURL,thisName,'left=100,top=100,toolbar=0,location=0,directories=0,status=0, menubar=0,scrollbars='+thisScroll+',resizable=0,width='+thisW+',height='+thisH);
  }
  
function disableForm(theform) {
if (document.all || document.getElementById) {
//for (i = 0; i < theform.length; i++) {
//var tempobj = theform.elements[i];
//if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset")
//tempobj.disabled = true;
//}
theform.Submit.disabled = true;
//setTimeout('alert("Your form has been submitted. Notice how the submit and reset buttons were disabled upon submission.")', 2000);
return true;
} else {
//alert("The form has been submitted. But, since you're not using IE 4+ or NS 6, the submit button was not disabled on form submission.");
return false;
}
}

function confirmSubmit()
{
var agree=confirm("Are you sure you wish to continue?");
if (agree)
	return true;
else
	return false;

}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
if (confirmSubmit() == true){
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
  }
}

function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}


function checkAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = true ;
}
function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = false ;
}

   function confirmAction(thisForm, msg)
   {
        var status = confirm(msg);

        if (status)
        {
            thisForm.submit();
            return true;

        } else {
            return false;
        }

   }


   // TO BE REMOVED FROM HERE (ASIF)
   function showVac(thisForm)
   {

       thisForm.step.value="2";
       thisForm.submit();

   }
   
   function showMore(arr)
   {
   foo = arr.join('|');
   alert(foo);
   }

   function confirmAndSwitchSubmit(formIndex, newAction, msg, cmdVal)
   {

        var ok = confirm(msg);

        if (ok)
        {
           switchSubmit(formIndex, newAction, cmdVal);

        } else {
            return false;
        }

   }

   function switchSubmit(formIndex, newAction, cmdVal)
   {
        document.forms[formIndex].action = newAction;

        document.forms[formIndex].cmd.value=cmdVal;
        document.forms[formIndex].submit();

   }
   
   
   function swapPhoto(photoSRC,theCaption) {

if (document.getElementById("caption")) {

	var theImage = document.getElementById("mainPhoto");
	var displayedCaption = document.getElementById("caption");
	var displayedCredit = document.getElementById("credit");
	displayedCaption.innerHTML = theCaption;
	theImage.setAttribute("src", photoSRC);

    }
  }

