isNS4 = (document.layers) ? true : false;
isIE4 = (document.all && !document.getElementById) ? true : false;
isIE5 = (document.all && document.getElementById) ? true : false;
isNS6 = (!document.all && document.getElementById) ? true : false;

function ValidTopic(theForm) {
	if (theForm.q2)			// search form
	{
		if (theForm.q2.selectedIndex != 0)
		{
			if (theForm.q2.options[theForm.q2.selectedIndex].value == "")
			{
				alert("Please select one of the \"Topic\" options, not a category heading.");
				theForm.q2.focus();
				return(false);
			}
			else
			{
				theForm.topic.value = theForm.q2.options[theForm.q2.selectedIndex].value;
				return(true);
			}
		}
		else
		{
			theForm.q2.value = "";
			return(true);
		}
	}
	else
	{
		if (theForm.Topic.selectedIndex <= 0 || theForm.Topic.options[theForm.Topic.selectedIndex].value == "") {
		    alert("Please select one of the \"Topic\" options, not a category heading.");
		    theForm.Topic.focus();
		    return(false);
		}
		window.open(theForm.Topic.value);
		return(true);
	}
}

function CFpopUp(sURL)
{
	window.open("http://www.legalmart.com.au/corporatefirst/popup.asp?pageURL=" + sURL, "LMpopup", "top=20,left=20,width=500,height=500,toolbar=no,menubar=no,status=no,scrollbars=yes,resizable=yes",true);
}

function LMpopUp(sURL)
{
	window.open("http://www.legalmart.com.au/popup.asp?pageURL=" + sURL, "LMpopup", "top=20,left=20,width=500,height=500,toolbar=no,menubar=no,status=no,scrollbars=yes,resizable=yes",true);
}

function LMlargepopUp(sURL)
{
	window.open("http://www.legalmart.com.au/popup.asp?pageURL=" + sURL, "LMpopup", "top=20,left=20,width=640,height=600,toolbar=no,menubar=no,status=no,scrollbars=yes,resizable=yes",true);
//	window.open("/default.asp", "LMpopup");
}

function setSKU(frm)
{
	b_checked = false;

	for (i = 0; i < frm.pf_id.length; i++)
	{
		if (frm.pf_id[i].checked)
		{
			b_checked = true;
			frm.dept_id.value = frm.pf_id[i].value.substr(0,4);
			frm.sku.value = frm.pf_id[i].value + "-" + frm.state.value;
		}
	}

	if (!b_checked)
	{
		alert("Please select a product before continuing.");
	}

	return b_checked	
}

function setSKUproduct(frm)
{
	b_checked = false;

	if (frm.pf_id.value.toString() != "")
	{
		b_checked = true;
		frm.sku.value = frm.pf_id.value + "-" + frm.state.value;
	}

	if (!b_checked)
	{
		alert("Please select a product before continuing.");
	}

	return b_checked	
}

function set_pf_id(frm)
{
	b_checked = false;

	for (i = 0; i < frm.sku.length; i++)
	{
		if (frm.sku[i].checked)
		{
			b_checked = true;
			frm.pf_id.value = frm.sku[i].value.substr(0,7);
		}
	}

	if (!b_checked)
	{
		alert("Please select a product before continuing.");
	}

	return b_checked	
}

function PrintIt()
{
	factory.printing.header = "Legalmart: Your Instant Lawyers Online";
	factory.printing.footer = "(c)<% =Year(Date) %> Legalmart. All Rights Reserved.&b&bPage &p of &P";
	factory.printing.Portrait = true;
	factory.printing.printBackground = true;
	factory.printing.Print(true);
}

function setFocus(question)
{
	if(question.length) question = question[0]
	question.focus();
}

function checkRequired(theform)
{
	if(!document.all) return true;
	
	var i, question, visibleQuestion;
	var reqInfo = document.all('ReqInfo');
	
	if(!reqInfo) return true;

	if(reqInfo.length)
	{
		for(i=0;i<reqInfo.length;i++)
			if(!checkQuestion(reqInfo[i]))
				return false;
	}
	else if(!checkQuestion(reqInfo)) return false;
			
	return true;
}

function checkQuestion(Item)
{
	var question = document.all('Req_' + Item.className);
	var visibleQuestion = document.all(Item.className);

	if(!isAnswered(question))
	{
		showObject(Item);
		setFocus(visibleQuestion);
		return false;
	}
	else hideObject(Item);
	return true;
}

function isAnswered(question)
{
	if(question.length) question = question[0];
	return (question.value.length!=0);
}

function checkHiddenField(txt, isChecked)
{
	if (isChecked)
		txt.value='Yes';
	else
		txt.value='No';
}

function checkPostCode(frm)
{
	if (!isNaN(frm.postcode.value) && frm.postcode.value > 0 && frm.postcode.value <= 9999)
		return true;
		
	alert('You have entered an invalid postcode. Please try again.');
	frm.postcode.value = '';
	frm.postcode.focus();
	return false;
}

function toMoney(amount)
{	
	var sAmount = amount.toString()
	var iDotPos = sAmount.lastIndexOf('.');

	if(iDotPos == -1)
		sAmount += '.00';
	else
	{
		sAmount = sAmount.substr(0, iDotPos + 3);
		for(i=sAmount.length; i < iDotPos + 3; i++)
			sAmount += '0';
	}

	return '$' + sAmount;
}

function trimLeadingSpaces(str)
{
	var i;
	var c;
	
	for(i=0;i<str.length; i++)
	{
		c = str.charAt(i);
		
		if(c != ' ')
			break;
	}
	if(i < str.length)
		str = str.substring(i, str.length)
	
	return str;
}

function isNS()
{
	if(navigator.appName == 'Netscape') return true;
	return false	
}

function isIE()
{
	if(navigator.appName == 'Netscape') return false;
	return true
}

function showSectionNS6(sections, sectionName)
{
	var objSections = document.getElementsByTagName('div');
	
	for(var i=0; i < objSections.length; i++)
		if(objSections[i].id == sections)
			if(objSections[i].className == sectionName)
				objSections[i].style.display = '';
			else
				objSections[i].style.display = 'none';
}

function showSectionNS4(sections, sectionName)
{
	var objSections = document.layers(sections);
	
	for(var i=0; i < objSections.length; i++)
		if(objSections[i].className == sectionName)
			objSections[i].visibility = 'visible';
		else
			objSections[i].visibility = 'hidden';
}

function showSection(sections, sectionName)
{	
	var objSections = document.all[sections];

	if(typeof(objSections)=='undefined')
		return false;

	if(typeof(objSections.length)=='undefined')
	{
		if(objSections.className == sectionName)
			objSections.style.display = '';
		else
			objSections.style.display = 'none';
		return true
	}
	
	for(i=0; i < objSections.length; i++)
	{		
		if(objSections[i].className == sectionName)
			objSections[i].style.display = '';
		else
			objSections[i].style.display = 'none';
	}
	return true;
}

function radioButtonClick(obj, qNum, section, sectionName, required)
{
	if(required)
		if(isNS())
			document.wizard['Req_Q' + qNum].value = obj.value;
		else
			wizard.all('Req_Q' + qNum).value=obj.value;

	if(section!='')
	{
		if(isNS6)
			showSectionNS6('Section_' + qNum, sectionName);
		else if(isNS4)
			showSectionNS4('Section_' + qNum, sectionName);
		else
			showSection('Section_' + qNum, sectionName);
	}
}

function showObject(object)
{
    if (document.getElementById && document.getElementById(object) != null)
        node = document.getElementById(object).style.visibility='visible';
    else if (document.layers && document.layers[object] != null)
        document.layers[object].visibility = 'visible';
    else if (document.all)
		object.style.display = '';
}

function hideObject(object)
{
    if (document.getElementById && document.getElementById(object) != null)
        node = document.getElementById(object).style.visibility='hidden';
    else if (document.layers && document.layers[object] != null)
        document.layers[object].visibility = 'hidden';
    else if (document.all)
		object.style.display = 'none';
}

function propagateControl(ctl)
{
	var n, obj

	if(document.getElementsByName)
		obj = document.getElementsByName(ctl.name);
	else if(document.all)
		obj = document.all(ctl.name);

	if(obj && obj.length && obj.length > 1)
		for(n=0;n<obj.length;n++)
			obj[n].value = ctl.value;
}
