// Function to return a list of elements with a specific class attribute
document.getElementsByClassName = function($class) {
	var $results = Array();
	var $elements = document.getElementsByTagName("*");
	for (var $i=0; $i<$elements.length; $i++) {
		var $classes = $elements[$i].className.split(" ");
		for (var $j=0; $j<$classes.length; $j++) {
			if ($classes[$j] == $class) {
				$results[$results.length] = $elements[$i];
			}
		}
	}
	return $results;
}

var browser=navigator.vendor;
if (browser == undefined){browser="internet explorer";}

var pos=browser.indexOf("Apple");
if (pos>=0)
{

	
} else {
	
	// In order to pass the safety checks this section must appear AFTER the getElementsByClassName function (above)
	if (document.getElementsByTagName && document.getElementsByClassName) {
		// Create a link to the Javascript-only stylesheet, which will primarily hide the hidden text
		var $link_element = document.createElement('link');
		$link_element.setAttribute("rel","stylesheet");
		$link_element.setAttribute("href","../styles/javascript_only.css");
		$link_element.setAttribute("media","screen");
		
		// Append this stylesheet link to the document
		var $head_element = document.getElementsByTagName('head')[0];
		$head_element.appendChild($link_element);
	}	
}




function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


// popupWindow function
// This is where you set your specific height & width etc... for your popups.
function openPopup(url,popType) {
	if (popType==1)
		window.open(url, 'popupwindow', 'width=735,height=800,scrollbars,resizable'); 
	else
		window.open(url);
	return false;
	}

function setFocus(formName, field) {
	eval('document.'+formName+'.'+field+'.focus()');
	}


function disabledFields() {
	if (document.getElementById("sel-User_IsCompany").value==1) {
		document.getElementById("txt-User_FSA").disabled=false;
		document.getElementById("txt-User_NetAsset").disabled=false;
		}
	else {
		document.getElementById("txt-User_FSA").disabled=true;
		document.getElementById("txt-User_NetAsset").disabled=true;
		}
	}

/*function selectOther() {
	
	var myField = document.getElementsByName("User_AccessReason");
	
	if (getCheckedValue(myField)=='Other') {
		//alert('Other selected');
		var myOther = document.getElementsByName("User_AccessReason_other");
		
		myOther.focus();
		}
	}*/



$(document).load(function(){
	
	fileCntVar = 1;
	grpCntVar = 1;
	
	if (pos>=0)
	{
		$("form#dir").hide();
		$("form#fil").hide();
	
	}
	
	// Live user search
	$("input#search").keyup(function(){
		showHint(this.value);
		});
	
	
	$("a#switch-fil").click(function(){
		/* if button is clicked when "up" */
		if (fileCntVar == 1){

			/* button toggle value */
			fileCntVar = 0;
			$("#hs-file-group").hide();
			$("form#fil").show();
			
 			$(this).addClass("on");
			$("a#switch-grp").removeClass("on");
		
		/* if button is clicked when "down" */
		} else if (fileCntVar == 0) {
			fileCntVar = 1;
			$("form#dir").hide();
			$("form#fil").hide();
			
 			$(this).removeClass("on");
		}
		/*reset the other button to "up" state*/
		grpCntVar = 1;
		
		return false;
	});
	
		
	$("a#switch-grp").click(function(){
	
		/* if button is clicked when "up" */
		if (grpCntVar == 1){
		
			/* button toggle value */
			grpCntVar = 0;
			$("form#fil").hide();
			$("#hs-file-group").show();
			
 			$(this).addClass("on");
			$("a#switch-fil").removeClass("on");
			//$("input#grp-title").focus();
			
		/* if button is clicked when "down" */
		} else if (grpCntVar == 0){
			grpCntVar = 1;
			$("form#fil").hide();
			$("#hs-file-group").hide();
			
 			$(this).removeClass("on");
		}
		/*reset the other button to "up" state*/
		fileCntVar = 1;
		
		//$("#txt-name").focus();
		return false;
	});	
		
	
	
	// Popups and external links.
	$("a.popup").click(function(){
		var url = this.href;
		openPopup(url,1);
		return false;
		})
	
	$("a.external").click(function(){
		var url = this.href;
		openPopup(url,2);
		return false;
		})
	
	
	//document.getElementById("txt-User_FSA").disabled=true;
	//document.getElementById("txt-User_NetAsset").disabled=true;
	disabledFields(); 

	$("#sel-User_IsCompany").change(function() {
		disabledFields(); 
		});
	
	/*$("input[@name=User_AccessReason]").focus(function() {
		selectOther(); 
		});*/
	
	});