var NewWnd

/* New popup launch code that allows size to be set here for all instances

 */
function ShowPopupType(type, URL)
{
	var width; var height;

	if (type=="general" || type=="") {width=468; height=460;}
	if (type=="gallery") {width=468; height=460;}
	if (type=="fashion") {width=424; height=622;}
	if (type=="lovefilm") {width=468; height=400;}

	//NewWnd = window.open(URL, 'Details', 'width=' + width + ',height=' + height + ',top,resizable=1')
    //NewWnd = window.open('nowebpage' + URL, 'Details', 'width=' + width + ',height=' + height + ',top,resizable=1')
    NewWnd = window.open(URL, 'popup', 'width='+ width +',height='+ height +',top')
    if (NewWnd.opener==null) NewWnd.opener=self;
    NewWnd.focus();
    return void(false);
}

function HandbagPopup(sChannel, sSection, sRegion, width, height, top, left)
{
	var numargs = Popup.arguments.length;

	if (numargs < 3) return false;

	if (numargs < 4) var width = 485;
	if (numargs < 5) var height = 350;
	if (numargs < 6) var top = 100;
	if (numargs < 7) var left = 100;

	var sQueryString = '?Channel=' + escape(sChannel) + '&Section=' + escape(sSection) + '&Region=' + escape(sRegion)

    NewWnd = window.open('nowebpage' + sQueryString, 'HandbagPopup', 'width=' + width + ',height=' + height + ',top=' + top + ',left=' + left + ',resizable=0,menubar=0')
    if (NewWnd.opener == null) NewWnd.opener = self;
    NewWnd.focus();
    return true;
}

//amended by gsf on 10/4/2001. Function can now take width and height parameters should the popup need to be
//a different size to the default of 485 x 350.
//call to the function in the admin system is now: onmousedown="javascript:ShowPopup('/hb/popup/popup.asp?template=Foetal','',470,450)"
//if you need to put in width and height, you need to make sure you use the channelID parameter too!!!! just use empty string ''
function ShowPopup(URL, iChannelID, width, height)
{
	var iNumargs = ShowPopup.arguments.length;

	if (iNumargs < 1) return false;
	if (iNumargs < 2) var iChannelID = '';
	if (iNumargs < 3) var width = 485;
	if (iNumargs < 4) var height = 350;

    if (iNumargs > 1) URL += '&ChannelID='+iChannelID;

	// allow for legacy popup calls using obsolete width of 511px
	if (width==511) width=468;

	//NewWnd = window.open(URL, 'Details', 'width=' + width + ',height=' + height + ',top,resizable=1')
    //NewWnd = window.open('http://www.handbag.com' + URL, 'Details', 'width=' + width + ',height=' + height + ',top,resizable=1')
    NewWnd = window.open(URL, 'Details', 'width=' + width + ',height=' + height + ',top')
    if (NewWnd.opener == null) NewWnd.opener = self;
    NewWnd.focus();
    return false;
}

function showGallery(URL)
{
    NewWnd = window.open(URL, 'Details', 'width=890,height=640,top=100,left=100,status=1')
    if (NewWnd.opener == null) NewWnd.opener = self;
    NewWnd.focus();
}

// Determines whether search is site-wide or across web:

function SubmitSearchForm (SearchString)
{
	if(document.frmSearch.Mode[0].checked==true)
	{
		document.frmSearch.submit();
	}
	else
	{
		OpenFullWindow('nowebpage','noweblink' + SearchString, '' );
	}
}


function ShowEmailPopup(URL, iChannelID)
{
    NewWnd = window.open('noweblink' + URL+'&ChannelID='+iChannelID, 'newwin', 'width=500,height=340,top');
    if (NewWnd.opener == null) NewWnd.opener = self;
    NewWnd.focus();
    return false;
}

function nonesearch(form){
var URL = "nolink" + document.autolinks.othersearch[document.autolinks.othersearch.selectedIndex].value;
window.location.href = URL;

// url is nolink/"value".html
}


// function formclick
// Purpose: Created specifically to work in Recipes.asp (Location:  \nolocation\mapped\site\content\)
//	1. Displays different pages by taking ptype arguement, assigining it to form element "pagetype". This is
//		picked up in querystring and fed into a Select Case strPageType to determine what to display.
//  2. Submits form - we couldn't simple use a querystring hyperlink, e.g. ?pagetype="whatever",
//		because they wanted any terms entered in text box to be passed into the box on subsequent pages.

function formclick(ptype)
{
	document.frmChoose.pagetype.value = ptype;
	// have it sent back to an initial search screen, not results listing:
	document.frmChoose.context.value = "";
	document.frmChoose.submit();
}


// As for formclick but passes a value of 1 for "quick" to build up the SQL string and goes directly
// to the results listing

function quicksearch(q)
{
	document.frmChoose.quick.value = q;
	document.frmChoose.submit();
}

// ******** this window is not important ********
//used for the popup windows
function popup(word)
{
	window.open('nowebpage'+word,'nothing','height=360,width=485');
}

// Opens a full-sized window succesively loading 2 URLs:

function OpenFullWindow( aURLfirst, aURLsecond, aWinName )
{
   var wOpen;
   var sOptions;

   sOptions = 'status=yes,menubar=yes,scrollbars=yes,resizable=yes,toolbar=yes';
   sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString();
   sOptions = sOptions + ',height=' + (screen.availHeight - 85).toString();
   sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';

   wOpen = window.open( '', aWinName, sOptions );
   wOpen.location = aURLfirst;
   wOpen.location = aURLsecond;
   wOpen.focus();
   return wOpen;
}

// Determines whether search is site-wide or across web:

function SubmitSearchForm (SearchString)
{
	if(document.frmSearch.Mode[0].checked==true)
	{
		document.frmSearch.submit();
	}
	else
	{
		OpenFullWindow('nowebpage','nowebpage' + SearchString, '' );
	}
}

// loads score for each question into member of array:
function QuestionScore(questionnumber,scorevalue)
{
	score[questionnumber] = scorevalue;
}

// sums the value of the array members and submits form:
function TotalScore(startcount,endcount,posted) {

	var total=0
	for(var i=startcount;i<endcount;i++)
		{
		total = total + score[i];
		}

	document.frmTicklist.score.value = eval(total) + eval(document.frmTicklist.totalscorecount.value);
	document.frmTicklist.submitted.value = posted;
	document.frmTicklist.submit();

}
// Displays list of permiited quizzes:
function displayQuiz(sURL)
{
	ShowPopup(sURL);
	window.close();
}

// Redirects to display list of remaining available quizzes to try
function redirect(message)
{
	loc = 'nowebpage' + message + '&amp;quizlist=1'
	window.open(loc,'here','scrollbars=yes','resizable=yes');
	window.close();
}

/* Netscape event handling - Do Not Know
 * Use window.onload = AddNSEvents
 */
/*function AddNSEvents ()
{
	if (navigator.appName.indexOf("Microsoft")>=0)
	{
		window.addEventListener("click", SetEvent, false);
	}
}
function SetEvent (e)
{
	//alert("setEvent; typeof(e)="+typeof(e));
	window.event = e;
}*/

/* EXIT POPUP FUNCTIONS */

/* Capture the click event for ns6 (for IE this is done on the body tag) */
function addNS6Events() {
	if (!document.all) {
		// this one is to close the more channels menu - see nav.js
		window.addEventListener("click", navhandlerFunction, false);

		// this one if for exit popup detection
		window.addEventListener("click", popupclick, false);
	}
}

/* Get the destination url when user clicks an anchor or image link */
function popupclick(e)
{
	if(navigator.appName=="Microsoft Internet Explorer")
	{
		if (event.srcElement.tagName=="A")
		{
			// For anchors, activeElement returns the href
			url = document.activeElement;
		}

		if (event.srcElement.tagName=="IMG")
		{
			// If image is not a link, activeElement returns [object]
			// else it returns the href
			var home_banner_href = new String(document.activeElement);
			if (home_banner_href.indexOf('http://')!= -1)
			{
				url = document.activeElement;
			}
		}
	}
	else if (navigator.appName=="Netscape")
	{
		// For some reason the target.parentNode is the anchor tag whether the anchor is
		// clicked or the 'IMG' within the anchor - Chris
		if (e.target.parentNode.tagName == "A")
		{
			url = e.target.parentNode.href;
		}
	}
	return true;
}

/*	Function below adjusts the height of a popup to show all of its content
	This is used to call it:
	<script language="JavaScript1.2" for="window" event="onload">PopupResize()</script>
*/
function PopupResize()
{
	if (document.all) {
		if (document.body.scrollHeight < 454){
			self.resizeTo(480,483);
		} else {
			var xh = document.body.scrollHeight + 29;
			self.resizeTo(480,xh);
		}
	}
	if (!document.all){
		if (document.height < 450){
			window.innerHeight = (450);
			window.innerWidth = (468);
		} else {
			var xh = document.height;
			window.innerHeight = (xh);
			window.innerWidth = (468);
		}
	}
}

/* Old exit popup functions no longer used I think - Chris 05 Feb 2003 */

/* Superseded by addNS6Events() above - L.webauthor 31.01.06 */
function popupload()
{
	if (navigator.appName=="Netscape")
	{
		//window.onclick = get_netscape_anchor_data;
		window.onclick = popupclick;
	}
	return true;
}

function get_netscape_anchor_data(e)
{
	// For some reason the target.parentNode is the anchor tag whether the anchor is
	// clicked or the 'IMG' within the anchor - Chris
	if (e.target.parentNode.tagName == "A")
	{
		//alert('a');
		url = e.target.parentNode.href;
	}
	return true;
}

function HBGetCookie(name) {
	var p1 = document.cookie.indexOf(name+"=");
	var n = p1+name.length+1;
	if ((!p1) && (name != document.cookie.substring(0,name.length))) return null;
	if (p1 == -1) return null;
	var p2 = document.cookie.indexOf(";",n);
	if (p2 == -1) p2 = document.cookie.length;
	return unescape(document.cookie.substring(n,p2));
}

function HBSetCookie (name, value) {
	var argv = HBSetCookie.arguments;
	var argc = HBSetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
}

/* Useful functions for checking radio groups */
function reg_RadioValue(oRb)
{
	for(var i = 0;i < oRb.length;i++)
	{
		if(oRb[i].checked)
		{
			return oRb[i].value;
		}
	}
	return "";
}
function reg_RadioSetValue(oRb, sValue)
{
	for(var i = 0;i < oRb.length;i++)
	{
		if(oRb[i].value == sValue)
		{
			oRb[i].checked = true;
			return;
		}
	}
}
function reg_RadioIsChecked(oRb)
{
	for(var i = 0;i < oRb.length;i++)
	{
		if(oRb[i].checked)
		{
			return true;
		}
	}
	return false;
}

