window.onerror = new Function("return true");

function open_window(url, win_name, win_width, win_height, resize, scrollbars) { if (url != '') newWindow=window.open(url, win_name, 'menubar=no,toolbar=no,status=yes,resizable='+resize+',scrollbars='+scrollbars+',width='+win_width+',height='+win_height); }

function bLink(qString,nWind,popUp,popNam,popWid,popHei,popRes,popScr,disNB)
{
	if (qString != '')
	{
		var afterQuest = '';

		// get the current location
		var currURL = location.href;
		
		// but first we have to see if the link is in fact
		// an internal link
		if (qString.indexOf('link_id') != -1 && qString.indexOf('http://') == -1)
		{
			// we are on an internal link so all we want is the path
			if (currURL.indexOf('?') != -1)
			{
				// get everything before the ?
				currURL = currURL.substring(0,currURL.indexOf('?') + 1);
			}
			else
			{
				currURL += '?';
			}
		}
		// we are not on an internal link
		else
		{
			// is there anything in the querystring
			if (currURL.indexOf('?') != -1 && qString.indexOf('fid') != -1)
			{
				var linkId = '';
				lPos = currURL.indexOf('link_id');

				// we want to get the link_id out if possible
				if (lPos != -1)
				{
					rPos = currURL.indexOf('&',lPos);
					
					if (rPos != -1)
					{
						linkId = currURL.substring(lPos,(rPos-lPos));
						currURL += currURL.substring(0,currURL.indexOf('?') + 1) + linkId;
					}
					
					// just check that there is not an ancor link found
					if (currURL.indexOf('#') != -1)
					{
						// remove the ancor link from the end of the string
						currURL = currURL.substring(0, currURL.indexOf('#'));
					}

					currURL += '&';
				}
			}
			else
			{
				// this is an external url
				currURL = '';
			}
		}
		
		// attach the required data
		currURL += qString;
		
		// replace from formatting
		currURL = replace(currURL,'%3D','=');
		currURL = replace(currURL,'%26','&');
		currURL = replace(currURL,'%3A',':');
		
		// is it to open in a new window
		if (nWind != 'Y')
		{
			// is the nav bar allowed
			if (disNB != 'Y')
			{
				window.location.href = currURL;
			}
			else
			{
				// enable the nav bar
				alert('Display Bar Not Functioning Correctly');
			}
		}
		else
		{
			// is in a new window
			if (popUp != 'Y')
			{
				// just a normal new window
				newWindow = window.open(currURL,'newWindow', 'location=1,menubar=1,toolbar=1,status=1,resizable=1,scrollbars=1,width=500,height=400');
			}
			else
			{
				// remove any unwanted elements from the popup name
				popNam = replace(popNam,' ','');
				popNam = replace(popNam,'.','');
				popNam = replace(popNam,'/','');
				popNam = replace(popNam,'_','');
			
				// is the nav bar allowed
				if (disNB != 'Y')
				{
					// have to use the required data to build the popup window
					open_window(currURL,popNam,popWid,popHei,popRes,popScr);
				}
				else
				{
					// enable the nav bar
					open_window('index.aspx?tmp=popupnavbar&html=force&scroll=' + popScr + '&exist=' + escape(currURL),popNam,popWid,popHei,popRes,popScr);
				}
			}
			
		}
	}
}

function replace(string,text,by)
{
	var strLength = string.length;
	var txtLength = text.length;
	if ((strLength == 0) || (txtLength == 0)) return string;

	var i = string.indexOf(text);
	if ((!i) && (text != string.substring(0,txtLength))) return string;
	if (i == -1) return string;

	var newstr = string.substring(0,i) + by;

	if (i + txtLength < strLength) { newstr += replace(string.substring(i + txtLength,strLength),text,by); }

	return newstr;
}

function keyCheck(eventObj, obj)
{
    var CurrentKeyCode;
	var str=obj.value;

	if (document.all){ keyCode = eventObj.keyCode; } else{ keyCode = eventObj.which; }

	if(keyCode<48 || keyCode >58) { return false; }

	return true;
}

function checkForm(objForm, text)
{
	if (objForm.radio1[0].checked || objForm.radio2[0].checked)
	{
		var itemCounter = 0;
		for(i=0; i<objForm.check1.length; i++)
		{
			if (objForm.check1[i].checked)
			{
				itemCounter++;
			}
		}

		if (itemCounter >= 4)
		{
			alert('Your answers suggest that you may have ' + text + '.  You may want to talk to a health professional, such as a doctor or counsellor, to discuss this further.');
			return;
		}
	}
	
	alert('Your answers suggest that you do not have ' + text + '.  If you are still concerned, you may want to talk to a health professional, such as a doctor or counsellor.');
	return;
}

function QueryString(item)
{
	if (IsNotEmpty(item))
	{
		var locHref = location.href;
		var itmLoc = locHref.indexOf(item);
		
		if (itmLoc != -1)
		{

			var endAmpChar = locHref.indexOf('&', itmLoc);
			var itemAndText = '';
			
			if (endAmpChar != -1) { itemAndText = locHref.substring(itmLoc, endAmpChar); }
			else { itemAndText = locHref.substring(itmLoc, locHref.length); }
			
			return itemAndText.substring(item.length + 1,  itemAndText.length);

		}
	}

	return '';
}

function IsNotEmpty(itemValue)
{
	if (itemValue != null && itemValue != '') { return true; }
	return false;
}

function EnableOurStories(chk)
{
	if(chk.checked)
	{
		control = document.getElementById('butt');
		butt.disabled = false;
	}
	else
	{
		control = document.getElementById('butt');
		butt.disabled = true;
	}
}