function prepareField(name)
{
		var obj = $("#" + name);
		
		if(obj)
		{
				obj.val("");
				if(name == "pass")
				{
					$("#passlabel").hide();
					$("#pass").show();
					$("#pass").focus();
				}
		}
		return false;
}
function toggleDiv(divId)
{
	// use Jquery
	$("#" + divId).toggle();
}
function showDiv(divId, type)
{
	document.getElementById(divId).style.display = type;
}
function hideDiv(divId)
{
	document.getElementById(divId).style.display = "none";
}
function toggleCheckbox(checkId)
{
	var box = document.getElementById(checkId);
	box.checked = box.checked ? false : true;
}
function toggleMultipleCheckbox(value, checkIdList)
{
	var element;
	var elementList = checkIdList.split(",");
	for(var j = 0; j < elementList.length; j++)
	{	
		element = document.getElementById(elementList[j]);
		if(value)
			element.checked = false;
	}
}
function submitCompareForm()
{
	var formObj = document.getElementById('compareForm');
	if(!formObj) return false;
	
	var counter = 0;
	if(formObj.comparelist)
	{
		for(var i=0;i<formObj.comparelist.length;i++)
		{
			if(formObj.comparelist[i].checked)
			{
				counter++;
			}
		}
	}
	if(counter > 1)
	{
		formObj.submit();
	}
	else
	{
		alert("You must select at least 2 handsets to compare");
	}
	return;
}

var ajaxResult;
function getDownload(documentId, root)
{
	ajaxResult = new sack();		
	ajaxResult.requestFile = root + '/ajax/get-download.asp?documentId=' + documentId;	// Specifying which file to get
	//alert(ajaxResult.requestFile);
	ajaxResult.onCompletion = function(){ evalDownload(documentId, root); };	// Specify function that will be executed after file has been found
	ajaxResult.runAJAX();		// Execute AJAX function	
	
	//alert(dlResult);
	//return dlResult;
	
}
function evalDownload(documentId, root)
{
	var result = ajaxResult.response;
	if(result == "true")
	{
		document.location = root + "/downloads/get/" + documentId + "/"
	}
	else
	{
		$("#loginoverlaycontainer").show();
	}
}

/* Fish CMS Document Picker JS */
function addDocumentContainer()
{
	var documentPickerParentObj = document.getElementById("documentpickers");
	var documentPickerTemplateObj = document.getElementById("documentpickertemplate");
	var documentCounter = document.getElementById("documentcounter");
	
	var newnode = documentPickerTemplateObj.cloneNode(true);
	
	var value = parseInt(documentCounter.value);
	
	newnode.style.display = "block";
	newnode.setAttribute("id", "documentpicker_" + value)
	newnode.getElementsByTagName("select")[0].setAttribute("name", "document_" + value); 
	newnode.getElementsByTagName("select")[0].setAttribute("id", "document_" + value); 
	newnode.getElementsByTagName("label")[0].setAttribute("for", "document_" + value); 
	newnode.getElementsByTagName("img")[0].onclick = function(){ deleteDocumentContainer(value);  }
	
	documentPickerParentObj.appendChild(newnode);
	
	documentCounter.value = value + 1;
}	
function deleteDocumentContainer(id)
{
	var documentPickerToDeleteObj = document.getElementById("documentpicker_" + id);
	documentPickerToDeleteObj.style.display = "none";
	documentPickerToDeleteObj.getElementsByTagName("select")[0].setAttribute("name", "documentdeleted_" + id);
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}