function confirmFields(formName) {
	var errorMessage = false;

	for (var i = 0; i < document.forms[formName].elements.length; i++) 
	{
		if (document.forms[formName].elements[i].value == "" && document.forms[formName].elements[i].attributes["required"] != null )
	      errorMessage = true;
	}

	if (errorMessage) 
	{
		alert ("Please fill in all answers before continuing!");
		return false;
	} 
	else 
		return true;
}

function confirmSelection(btn) 
{
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) 
        {
        	cnt = i; i = -1;
        }
    }
    if (cnt > -1) 
    	return true;
    else 
    {
    	alert('Please make a section before continuing!');
    	return false;
    }
}

function bookmark(path, title)
{
  if (window.sidebar) { // firefox
     window.sidebar.addPanel(title, path, "");
  } else if (document.all) { // IE
     window.external.AddFavorite(path, title);
  } else if (window.opera && window.print) { // opera
     var elem = document.createElement('a');
     elem.setAttribute('href',path);
     elem.setAttribute('title',title);
     elem.setAttribute('rel','sidebar');
     elem.click();
  }
} 

function highlight(index, on)
{
	div = document.getElementById('desc-' + index);

	if (div != null && typeof(div) != 'undefined')
	{
		if (on)
			div.style.fontWeight = 'bold';
		else
			div.style.fontWeight = 'normal';
	}
}

function deleteSection(section_id)
{
	if (confirm("This action cannot be undone.  Are you sure you want to delete?"))
	{
		document.getElementById('sectionId').value = section_id;
		return true;
	}
	else
		return false;
}		

function confirmAdd(id) {

	box = document.getElementById('a-' + id);
	
	if (box.value == '')
	{
		alert("Please enter text before adding!");
		return false;
	}
	else {
		document.getElementById('sectionId').value = id;
		return true;				
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return curtop;
}

function valiateNumber(text)
{
	if (IsNumeric(text) && text.length < 4)
		return true;
	else
	{
		alert("Please enter a valid number!");
		return false;
	}
}

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 setLastYPos(formName)
{
	if (window.scrollY)
		pos = window.scrollY;
	 else 
		pos = document.documentElement.scrollTop;
		
	document.forms[formName].elements['lastYPos'].value = pos;
}

function showDisclaimer() {
	 alert("The IB Roof Systems (IBRS) Assembly must be installed according to IBRS current Specification Manual and Approved Commercial Roofing Details. All other related roofing components must meet or exceed current editions of IBRS Standards, FM Approvals Loss Prevention Data Sheets, SMACNA's Architectural Sheet Metal Manual, ANSI/SPRI ES 'Wind Design Standard for Edge Systems Used with Low-slope Roofing Systems, NRCA's Roofing and Waterproofing Manual, Florida Building Code -Test Protocol HVHZ Roofing Application Standard (RAS) No. 111, 'Standard Requirements for Attachment of Perimeter Wood Blocking and Metal Flashing' or International Building Code requirements or recommendations with the most stringent prevailing. \n\n The roof system attachment requirements herein relate solely to components and cladding of new the roof assembly.  IBRS does not purport to address wind loading or adequacy of the Roof Deck, perimeter edge terminations, flashings or rooftop equipment.  The performance of each of these components in a wind event is vital to performance of the roof assembly itself, and should also be designed and installed to meet wind-loading criteria of the current ASCE-07 Document. \n\n IBRS offers this Spec Writer Tool for your guidance and assistance with the creation of a project specification with the understanding that information contained in this Specification does  not constitute any representations, endorsements of, or an assumption by IBRS of any liability for the adequacy of the design of this building, or any material not supplied by IBRS.  THE SPECIFIER OF RECORD DETERMINES WHETHER THE PROPOSED ROOF ASSEMBLY MEETS THE REQUIREMENTS OF THE LOCAL OR STATE BUILDING CODE(S).  If this project requires the roof assembly to meet specific requirements for FM Approved Roof Systems, IBRS suggests that the local FM engineer be consulted for Final Approval of the roof assembly.");
	return true;
}

	function checkUncheckAll(theElement) 
	{
     var theForm = theElement.form, z = 0;
	 	 for(z=0; z<theForm.length;z++){
      if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
	 		 theForm[z].checked = theElement.checked;
	 		 }
     }
   }

