
var passwordField = '<input type="password" name="ac_password" class="styledInput" value="" id="signinPassword" onblur="passwordBlur($(this));" />';
var passwordFieldReplacment = '<input type="text" name="ac_password" class="styledInput" value="your password" id="signinPassword" onfocus="passwordFocus($(this));" />';

function formFieldFocus(idx, f_name) {
	field = fields_ids[idx];
	txt   = fields_txt[idx];
		obj   = eval("document.getElementById(\"" + f_name + "\")." + field);
	
	if(obj.value == txt) {
		obj.value = "";
	}
	return true;
}

function formFieldBlur(idx, f_name) {
	field = fields_ids[idx];
	txt   = fields_txt[idx];
		obj   = eval("document.getElementById(\"" + f_name + "\")." + field);
		if(obj.value == "") {
		obj.value = txt;
	}
	return true;
}

function submitForm(f_name) {
	for(i = 0; i < fields_ids.length; ++i) {
		obj = eval("document.getElementById(\"" + fields_ids[i] + "\")");
		if(obj.value == fields_txt[i]) {
			obj.value = "";
		}
	}
	eval("document.getElementById(\"" + f_name + "\").submit();");
	return false;
}

function setContextForForm(field_name, field_value) {
	eval("document.getElementById(\"" + field_name + "\").value = '" + field_value + "';");
	return false;
}

function detailedFields(field_id) {
	obj = eval("document.getElementById(\"" + field_id + "\")");
	if(!obj.style.display || obj.style.display == "none") {
		obj.style.display = "block";
	} else if(obj.style.display == "block") {
		obj.style.display = "none";
		obj.value = "Please specify";
	}
}

function openPopup(popupLocation, popupName, popupWidth, popupHeight) {
	var screenWidth = 760;
	var screenHeight = 420;
	if (self.screen.width) {
		screenWidth = self.screen.width;
		screenHeight = self.screen.height;
	}
	var popupTop = (screenHeight-popupHeight)/2;
	var popupLeft = (screenWidth-popupWidth)/2;
	newPopupName=window.open(popupLocation, 'newname', 'height=' + popupHeight + ', width=' + popupWidth + ', left=' + popupLeft + ', top=' + popupTop + ', resizable=0');
	if (newPopupName.focus) {
		newPopupName.focus();
	}
	return false;
}

function openInNewWindow() {
	var newWindow = window.open(this.getAttribute('href'), '_blank');
	if(newWindow) {
	newWindow.focus();
	}
	return false;
}

function getNewWindowLinks() {
	if (document.getElementById && document.createElement && document.appendChild) {
		var objWarningText;
		var strWarningText;
		var link;
		var links = document.getElementsByTagName('a');
		for (var i = 0; i < links.length; i++) {
			link = links[i];
			if (link.getAttribute && link.getAttribute) {
				if (link.getAttribute("href") && link.getAttribute("rel") == "external") {
					link.onclick = openInNewWindow;
				}
			}
		}
		objWarningText = null;
	}
	if ($('input[type=password]')) {
		$('input[type=password]').replaceWith(passwordFieldReplacment); 
	}
}

function printPage() {
	if (window.print) {
		window.print() ;  
	}
	return false;
}

function addBookMark(title,url) {
	if (window.sidebar) { 
		// firefox
		window.sidebar.addPanel(title, url,"");
	} else if(window.opera && window.print){
		// opera
		var anchorElem = document.createElement('a');
		anchorElem.setAttribute('href',url);
		anchorElem.setAttribute('title',title);
		anchorElem.setAttribute('rel','sidebar');
		anchorElem.click();
	} else if( document.all ) {
		// IE
		window.external.AddFavorite(url,title);
	} 
}

function sfHover() {
	if (document.getElementById) {
		var sfEls = document.getElementById("globalNav").getElementsByTagName("LI");
		if (sfEls) {
			for (var i=0; i<sfEls.length; i++) {
				sfEls[i].onmouseover=function() {
					this.className+=" sfhover";
				}
				sfEls[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
				}
			}
		}
	}
}

function showHide(theid){
    if (document.getElementById) {
    var switch_id = document.getElementById(theid);
        if(switch_id.className == 'hide') {
           switch_id.className = 'styledTable';
        }else{
           switch_id.className = 'hide';
        }
	}
}

function showHideBlock(theid, desiredClass){
	if (document.getElementById) {
		var switch_id = document.getElementById(theid);
		if (switch_id.className != desiredClass) {
			if (switch_id.className == 'hide') {
				switch_id.className = 'dontHide';
			} else {
				switch_id.className = 'hide';
			}
		}
	}
}

function passwordFocus(me) {
	me.replaceWith(passwordField); 
	$('input[type=password]').focus();
}

function passwordBlur(me) {
	if (me.val() == '') {
		me.replaceWith(passwordFieldReplacment);
	}
}

if (window.attachEvent) {
	window.attachEvent("onload", sfHover)
};