var win = null; // Window
// #############################################################################
// lets define the browser we have 
var userAgent = navigator.userAgent.toLowerCase();
var is_opera  = (userAgent.indexOf('opera') != -1);
var is_saf    = ((userAgent.indexOf('safari') != -1) || (navigator.vendor == "Apple Computer, Inc."));
var is_webtv  = (userAgent.indexOf('webtv') != -1);
var is_ie     = ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv));
var is_ie4    = ((is_ie) && (userAgent.indexOf("msie 4.") != -1));
var is_moz    = ((navigator.product == 'Gecko') && (!is_saf));
var is_kon    = (userAgent.indexOf('konqueror') != -1);
var is_ns     = ((userAgent.indexOf('compatible') == -1) && (userAgent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_saf));
var is_ns4    = ((is_ns) && (parseInt(navigator.appVersion) == 4));

// catch possible bugs with WebTV and other older browser
var is_regexp = (window.RegExp) ? true : false;

// #############################################################################
// let's find out what DOM functions we can use
var vbDOMtype = '';
if (document.getElementById)
{
	vbDOMtype = "std";
}
else if (document.all)
{
	vbDOMtype = "ie4";
}
else if (document.layers)
{
	vbDOMtype = "ns4";
}

// make an array to store cached locations of objects called by fetch_object
var vBobjects = new Array();

// #############################################################################
// function to emulate document.getElementById
function fetch_object(idname, forcefetch)
{
	if (forcefetch || typeof(vBobjects[idname]) == "undefined")
	{
		switch (vbDOMtype)
		{
			case "std":
			{
				vBobjects[idname] = document.getElementById(idname);
			}
			break;

			case "ie4":
			{
				vBobjects[idname] = document.all[idname];
			}
			break;

			case "ns4":
			{
				vBobjects[idname] = document.layers[idname];
			}
			break;
		}
	}
	return vBobjects[idname];
}

// #############################################################################
// function to toggle the collapse state of an object
function toggle_collapse(objid)
{
	if (!is_regexp)
	{
		return false;
	}
	
	obj = fetch_object("collapseobj_" + objid);	


	if (obj.style.display == "none")
	{
		obj.style.display = "";
	}
	else
	{
		obj.style.display = "none";
	}
	return false;
}


// #############################################################################
// function to toggle the collapse state of an object in admin area
function admin_toggle_collapse(objid)
{
	if (!is_regexp)
	{
		return false;
	}
	
	obj = fetch_object("collapseobj_" + objid);	


	if (obj.style.display == "none")
	{
		var x = 0;
		do 
		{
			objname = fetch_object("collapseobj_" + x);
			if (objname != null)
			{
				if (objname.style.display != "none")
				{
					objname.style.display = "none";
				}
			}  
			x = x + 1 ; 
		}	
		while (x < 6);
		obj.style.display = "";

	}
	else
	{
		obj.style.display = "none";
	}
	return false;
}

function newWindow(mypage,myname,w,h,features) {
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;
	var settings = 'height=' + h + ',';
	
	settings += 'width=' + w + ',';
	settings += 'top=' + wint + ',';
	settings += 'left=' + winl + ',';
	settings += features;

	win = window.open(mypage,myname,settings).focus(); 
}

function viewContentByURL(url){
	var wintop;
	var winheight= 768;
	var winleft;
	var winwidth = 1024;
	wintop = (screen.height/2) - (winheight/2)
	if(wintop < 0)
	{
		wintop = 0;
	}
	winleft = (screen.width/2) - (winwidth/2)
	if(winleft < 0) 
	{
		winleft = 0;
	}
	
	window.open(url,'UserContent','height=' + winheight + ',width=' + winwidth + ',top=' + wintop + ',left=' + winleft + ',scrollbars=yes,addressbar=yes,location=yes,toolbar=yes,statusbar=yes,menubar=yes,resizable=yes');
	
}

function SameWindow(mypage) {
	document.location.href = mypage;		
}

function ShowMe(product_id, language_id, show_id, show_file_type_id,topic_id)
{
	var wintop;
	var winheight;
	var winleft;
	var winwidth;
	var dirLevel = "";
	
	if (!topic_id) 
	{
		topic_id = '';
	}
	
	if (document.getElementById("dirLevel"))
	{
		dirLevel = document.getElementById("dirLevel").value;
	}
	var myWin
	switch (show_file_type_id){
		case 1 : //How-To SWF
			if(screen.width > 800)
				{
				winheight = 600;
				winwidth = 800;

				wintop = (screen.height/2) - (winheight/2)
				if(wintop < 0)
				{
					wintop = 0;
				}

				winleft = (screen.width/2) - (winwidth/2)
				if(winleft < 0)
				{
					winleft = 0;
				}
				myWin = window.open(dirLevel + 'play_howto_swf.asp?product_id=' + product_id + '_' + language_id + '&show_id=' + show_id + '&topic_id=' + topic_id, 'ShowMe', 'height=' + winheight + ',width=' + winwidth + ',top=' + wintop + ',left=' + winleft + ',scrollbars=no, alwaysRaised=yes');
			}
			else
			{
				myWin = window.open(dirLevel + 'play_howto_swf.asp?product_id=' + product_id + '_' + language_id + '&show_id=' + show_id + '&topic_id=' + topic_id,'ShowMe','fullscreen=yes, scrollbars=no, alwaysRaised=yes');			
			}
		
			break

		case 2 : //How-To WMV
			if(screen.width > 800)
			{
				winheight = 600;
				winwidth = 800;

				wintop = (screen.height/2) - (winheight/2)
				if(wintop < 0)
				{
					wintop = 0;
				}

				winleft = (screen.width/2) - (winwidth/2)
				if(winleft < 0)
				{
					winleft = 0;
				}

				window.open(dirLevel + 'play_howto_wmv.asp?product_id=' + product_id + '_' + language_id + '&show_id=' + show_id + '&topic_id=' + topic_id,'ShowMe','height=' + winheight + ',width=' + winwidth + ',top=' + wintop + ',left=' + winleft + ',scrollbars=no');
			}
			else
			{
				window.open(dirLevel + 'play_howto_wmv.asp?product_id=' + product_id + '_' + language_id + '&show_id=' + show_id + '&topic_id=' + topic_id,'ShowMe','fullscreen=yes, scrollbars=no');
			}

			break

		case 3 : //How-To SNT
			if((navigator.family == 'gecko') || (navigator.family == 'ie4' && navigator.version >= 6))
			{   
				frames['ie_playsnt'].location.href = 'play_howto_snt.asp?product_id=' + product_id + '_' + language_id + '&show_id=' + show_id + '&topic_id=' + topic_id;
			}
			else if(navigator.family == 'ie4' && navigator.version < 6)
			{
				document.all.ie_playsnt.src = 'play_howto_snt.asp?product_id=' + product_id + '_' + language_id + '&show_id=' + show_id + '&topic_id=' + topic_id;
			} 
			else if(navigator.family == 'nn4')
			{
				document.layers["netscape_playsnt"].src = 'play_howto_snt.asp?product_id=' + product_id + '_' + language_id + '&show_id=' + show_id + '&topic_id=' + topic_id;
			} 
			else 
			{
				alert('Internet Explorer 4.0+ or Netscape 4.0+ are required to view this content.');
			}

			break

		default : //Unhandled
			alert('Unhandled Show File Type');
	}

	//window.focus();			// focus the player
//	if(topic_id != '') 
//	{
//		history.go(0);
//	}
}

function ReadMe(product_id, language_id, show_id, topic_id)
{
	var wintop;
	var winheight;
	var winleft;
	var winwidth;

	if (!topic_id)
	{
		topic_id = '';
	}

	winheight = 500;
	winwidth = 600;

	wintop = (screen.height/2) - (winheight/2)
	if(wintop < 0)
	{
		wintop = 0;
	}

	winleft = (screen.width/2) - (winwidth/2)
	if(winleft < 0)
	{
		winleft = 0;
	}

	window.open('readme.asp?product_id=' + product_id + '_' + language_id + '&show_id=' + show_id + '&topic_id=' + topic_id,'ReadMe','height=' + winheight + ',width=' + winwidth + ',top=' + wintop + ',left=' + winleft + ',scrollbars=yes');

//	if(topic_id != '')
//	{
		history.go(0);
//	}
}

function HelpAFriend(product_id, language_id, show_id)
{
	var wintop;
	var winheight;
	var winleft;
	var winwidth;
	var dirLevel = "";

	winheight = 450;
	winwidth = 600;
	
	if (document.getElementById("dirLevel"))
	{
		dirLevel = document.getElementById("dirLevel").value;
	}

	wintop = (screen.height/2) - (winheight/2)
	if (wintop < 0)
	{
		wintop = 0;
	}

	winleft = (screen.width/2) - (winwidth/2)
	if(winleft < 0) 
	{
		winleft = 0;
	}

	window.open(dirLevel + 'helpafriend.asp?product_id=' + product_id + '_' + language_id + '&show_id=' + show_id + '&popup=1','HelpAFriend','height=' + winheight + ',width=' + winwidth + ',top=' + wintop + ',left=' + winleft + ',location=no,scrollbars=yes');
}

function Link(url){
	//if (confirm('Please Note: Clicking on links in this document may take you to a site outside of HelpNow! control. HelpNow! administrators are not responsible for external site content including links, language or quality of information. For concerns/questions, please contact the administrator of the site accessed - not HelpNow!. Thank you.'))	
	//{
		window.open(url,'_blank');
	//}
}

function Topic_Description(topic_id)
{
	var wintop;
	var winheight;
	var winleft;
	var winwidth;

	winheight = 450;
	winwidth = 600;

	wintop = (screen.height/2) - (winheight/2)
	if(wintop < 0) 
	{	
		wintop = 0;
	}

	winleft = (screen.width/2) - (winwidth/2)
	if(winleft < 0) 
	{
		winleft = 0;
	}

	window.open('topiclibrary_topicdescription.asp?topic_id=' + topic_id,'TopicDescription','height=' + winheight + ',width=' + winwidth + ',top=' + wintop + ',left=' + winleft + ',scrollbars=yes');
}

function Topic_Send(topic_id)
{
	var wintop;
	var winheight;
	var winleft;
	var winwidth;

	winheight = 450;
	winwidth = 600;

	wintop = (screen.height/2) - (winheight/2)
	if(wintop < 0)
	{
		wintop = 0;
	}

	winleft = (screen.width/2) - (winwidth/2)
	if(winleft < 0) 
	{
		winleft = 0;
	}

	window.open('topiclibrary_sendtopic.asp?topic_id=' + topic_id,'TopicSend','height=' + winheight + ',width=' + winwidth + ',top=' + wintop + ',left=' + winleft + ',scrollbars=yes');
}


function ICantFindIt()
{
	var wintop;
	var winheight;
	var winleft;
	var winwidth;

	winheight = 600;
	winwidth = 600;

	wintop = (screen.height/2) - (winheight/2)
	if(wintop < 0)
	{
		wintop = 0;
	}

	winleft = (screen.width/2) - (winwidth/2)
	if(winleft < 0) 
	{
		winleft = 0;
	}

	window.open('feedbackformpopup.asp?type=4&category_id=3','ICantFindIt','height=' + winheight + ',width=' + winwidth + ',top=' + wintop + ',left=' + winleft + ',scrollbars=yes');
}


function ICantFindItWArgs(pageName, product_id)
{
	var wintop;
	var winheight;
	var winleft;
	var winwidth;

	winheight = 600;
	winwidth = 600;

	wintop = (screen.height/2) - (winheight/2)
	if(wintop < 0)
	{
		wintop = 0;
	}

	winleft = (screen.width/2) - (winwidth/2)
	if(winleft < 0) 
	{
		winleft = 0;
	}

	window.open('feedbackformpopup.asp?type=4&category_id=3&product_id='+ product_id,'ICantFindIt','height=' + winheight + ',width=' + winwidth + ',top=' + wintop + ',left=' + winleft + ',scrollbars=yes');
}


function ucFeeback(pid, lid, ucid)
{
	var wintop;
	var winheight;
	var winleft;
	var winwidth;

	winheight = 600;
	winwidth = 600;

	wintop = (screen.height/2) - (winheight/2);
	if(wintop < 0)
	{
		wintop = 0;
	}

	winleft = (screen.width/2) - (winwidth/2);
	if(winleft < 0) 
	{
		winleft = 0;
	}

	window.open("feedbackformpopup.asp?type=2&category_id=3&product_id=" + pid + "_" + lid + "&ucid=" + ucid, "Feedback", "height=" + winheight + ", width=" + winwidth + ", top=" + wintop + ", left=" + winleft + ", scrollbars=yes");
}


function detectCookiesEnabled() {
	document.cookie = "test=cookiesEnabled";
	var pos = document.cookie.indexOf( "test=" );
	if( pos == -1 ) {
		document.all('yescookies').style.display='none';	
		document.all('nocookies').style.display='inline';
	}
	else {
		document.all('yescookies').style.display='inline';
		document.all('nocookies').style.display='none';		
	}
}

function checkKeyword(keyword_field, msg) {

	if( keyword_field.value == ""){
		alert(msg);
		return false;
	}
	else {
		return true;
	}
}


function viewCourse(guid, lid, clid, pid,url)
{
	var wintop;
	var winheight;
	var winleft;
	var winwidth;
	var browser;

	browser='ie';
	if (is_ns){
		browser='firefox';
	}

	winheight = 600;
	winwidth = 800;

	wintop = (screen.height/2) - (winheight/2)
	if(wintop < 0)
	{
		wintop = 0;
	}

	winleft = (screen.width/2) - (winwidth/2)
	if(winleft < 0) 
	{
		winleft = 0;
	}
	if (screen.height < 800)
	{
		if (!url){	
			window.open('viewer/play.asp?clid='+ clid +'&guid='+guid + '&lid='+ lid + '&pid=' + pid +'&browser=' + browser,'CoursePlayer','height=' + winheight + ',width=' + winwidth + ',top=' + wintop + ',left=' + winleft + ',scrollbars=no, title=no,status=no,resizable=no,channelmode=yes,fullscreen=yes');
		}else{	
			
			window.open('../viewer/play.asp?clid='+ clid +'&guid='+guid + '&lid='+ lid + '&pid=' + pid +'&browser=' + browser,'CoursePlayer','height=' + winheight + ',width=' + winwidth + ',top=' + wintop + ',left=' + winleft + ', ccp_800x600=yes, scrollbars=no, title=no,status=no,resizable=no,channelmode=yes,fullscreen=yes');
		}
	}
	else
	{
		winheight = 720;
		winwidth = 1024;
		if (!url){	
			window.open('viewer/play.asp?clid='+ clid +'&guid='+guid + '&lid='+ lid + '&pid=' + pid +'&browser=' + browser,'CoursePlayer','height=' + winheight + ',width=' + winwidth + ',top=' + wintop + ',left=' + winleft + ',scrollbars=no, title=no,status=no,resizable=no');
		}else{	
			
			window.open('../viewer/play.asp?clid='+ clid +'&guid='+guid + '&lid='+ lid + '&pid=' + pid +'&browser=' + browser,'CoursePlayer','height=' + winheight + ',width=' + winwidth + ',top=' + wintop + ',left=' + winleft + ', ccp_800x600=yes, scrollbars=no, title=no,status=no,resizable=no');
		}
	}
}



function viewHelpGUID(product_id, language_id, show_id, GUID)
{
	var wintop;
	var winheight;
	var winleft;
	var winwidth;

	winheight = 600;
	winwidth = 600;

	wintop = (screen.height/2) - (winheight/2)
	if(wintop < 0)
	{
		wintop = 0;
	}

	winleft = (screen.width/2) - (winwidth/2)
	if(winleft < 0) 
	{
		winleft = 0;
	}

	window.open('view_organization.asp?guid=' + guid + '&pid=' + product_id + '&lid=' + language_id + '&swid=' + show_id,'View','height=' + winheight + ',width=' + winwidth + ',top=' + wintop + ',left=' + winleft + ',scrollbars=yes');
}




function viewHelp(product_id, language_id, show_id)
{
	var wintop;
	var winheight;
	var winleft;
	var winwidth;
	var dirLevel = "";

	winheight = 600;
	winwidth = 600;
	
	if (document.getElementById("dirLevel"))
	{
		dirLevel = document.getElementById("dirLevel").value;
	}

	wintop = (screen.height/2) - (winheight/2)
	if(wintop < 0)
	{
		wintop = 0;
	}

	winleft = (screen.width/2) - (winwidth/2)
	if(winleft < 0) 
	{
		winleft = 0;
	}

	window.open(dirLevel + 'viewTitle.asp?pid=' + product_id + '&lid=' + language_id + '&swid=' + show_id,'View','height=' + winheight + ',width=' + winwidth + ',top=' + wintop + ',left=' + winleft + ',scrollbars=yes');
}


function viewHelpRef(product_id, language_id, show_id, ref)
{
	var wintop;
	var winheight;
	var winleft;
	var winwidth;

	winheight = 600;
	winwidth = 600;

	wintop = (screen.height/2) - (winheight/2)
	if(wintop < 0)
	{
		wintop = 0;
	}

	winleft = (screen.width/2) - (winwidth/2)
	if(winleft < 0) 
	{
		winleft = 0;
	}

	window.open('viewTitle.asp?pid=' + product_id + '&lid=' + language_id + '&swid=' + show_id + '&ref=' + ref,'View','height=' + winheight + ',width=' + winwidth + ',top=' + wintop + ',left=' + winleft + ',scrollbars=yes');
}

	function viewTopic(sid, pid, tid)
	{
		var wintop;
		var winheight;
		var winleft;
		var winwidth;

		winheight = 600;
		winwidth = 600;

		wintop = screen.height / 2 - winheight / 2;
		if(wintop < 0)
		{
			wintop = 0;
		}

		winleft = screen.width / 2 - winwidth / 2;
		
		if(winleft < 0)
		{
			winleft = 0;
		}
		
		window.open("send_topic.asp?sid=" + sid + "&pid=" + pid + "&tid=" + tid, "ViewTopic", "height=" + winheight + ",width=" + winwidth + ",top=" + wintop + ",left=" + winleft + ",scrollbars=yes");
	}



	//finds the index for GetResultsPage() & SortColumn()
	function GetFormIndex()
	{
		var i = 0; 
		var found = false;
		
		while (!found && i <= 100)  
			if (eval(document.forms[i++].page))
				found = true;

		return i - 1;
		
	}

	function GetResultsPage(iPageNo,iPageSize)
	{
		var idx = GetFormIndex();
		
		document.forms[idx].page.value = iPageNo;
		document.forms[idx].pagesize.value = iPageSize;
		document.forms[idx].submit();
	}
	
	function SortColumn(fieldName, AscDesc,Img)
	{
		var idx = GetFormIndex();

		document.forms[idx].sort.value = fieldName + ';' + AscDesc + ';' + Img;
		document.forms[idx].submit();
	}	

	
function viewSearchResult(url)
{
	var wintop;
	var winheight;
	var winleft;
	var winwidth;

	winheight = 600;
	winwidth = 600;

	wintop = (screen.height/2) - (winheight/2)
	if(wintop < 0)
	{
		wintop = 0;
	}

	winleft = (screen.width/2) - (winwidth/2)
	if(winleft < 0) 
	{
		winleft = 0;
	}
	
	window.open(url,'View','height=' + winheight + ',width=' + winwidth + ',top=' + wintop + ',left=' + winleft + ',scrollbars=yes');
}	

function viewHelpWithSource(product_id, language_id, show_id,ref)
{
	var wintop;
	var winheight;
	var winleft;
	var winwidth;

	winheight = 600;
	winwidth = 600;

	wintop = (screen.height/2) - (winheight/2)
	if(wintop < 0)
	{
		wintop = 0;
	}

	winleft = (screen.width/2) - (winwidth/2)
	if(winleft < 0) 
	{
		winleft = 0;
	}

	window.open('viewTitle.asp?pid=' + product_id + '&lid=' + language_id + '&swid=' + show_id + '&ref='+ ref,'View','height=' + winheight + ',width=' + winwidth + ',top=' + wintop + ',left=' + winleft + ',scrollbars=yes');
}

function viewUserContent(product_id, language_id, uc_id)
{
	var wintop;
	var winheight;
	var winleft;
	var winwidth;

	winheight = 400;
	winwidth = 600;

	wintop = (screen.height/2) - (winheight/2)
	if(wintop < 0)
	{
		wintop = 0;
	}

	winleft = (screen.width/2) - (winwidth/2)
	if(winleft < 0) 
	{
		winleft = 0;
	}

	window.open('viewContent.asp?pid=' + product_id + '&lid=' + language_id + '&ucid=' + uc_id,'View','height=' + winheight + ',width=' + winwidth + ',top=' + wintop + ',left=' + winleft + ',scrollbars=yes,addressbar=yes,location=yes,toolbar=yes,statusbar=yes,menubar=yes,resizable=yes');

}

function viewTopicPopup(tid,url)
{
	var wintop;
	var winheight;
	var winleft;
	var winwidth;

	winheight = 600;	//590;
	winwidth = 600;		//530;

	wintop = (screen.height/2) - (winheight/2)
	if(wintop < 0)
	{
		wintop = 0;
	}

	winleft = (screen.width/2) - (winwidth/2)
	if(winleft < 0) 
	{
		winleft = 0;
	}

	if (!url){
		window.open('topic.asp?tid=' +tid,'','top=' + wintop + ',left=' + winleft + ',height=' + winheight + ',width=' + winwidth + ',resizable=no,scrollbars=no');
	} else {
		window.open(url+'/topic.asp?tid=' +tid,'','top=' + wintop + ',left=' + winleft + ',height=' + winheight + ',width=' + winwidth + ',resizable=no,scrollbars=no');
	}

}

function SendSolution(product_id, language_id, show_id)
{
	var wintop;
	var winheight;
	var winleft;
	var winwidth;

	winheight = 600;
	winwidth = 600;

	wintop = (screen.height/2) - (winheight/2)
	if(wintop < 0)
	{
		wintop = 0;
	}

	winleft = (screen.width/2) - (winwidth/2)
	if(winleft < 0) 
	{
		winleft = 0;
	}

	window.open('helpafriend.asp?watchshow=True&product_id=' + product_id + '_' + language_id + '&show_id=' + show_id,'Send','height=' + winheight + ',width=' + winwidth + ',top=' + wintop + ',left=' + winleft + ',scrollbars=yes');
}

function getElement(id){
	if(document.all){
		return document.all(id);
	}else if(document.getElementById){
		return document.getElementById(id);
	}
}


function popupWindow(location){
	window.open(location, 'Welcome', 'toolbar=no,titlebar=no,scrollbars,width=750,height=500,top=25,left=25,statusbar,resizable');
}

function questionmark(link_name){
	window.open("features.asp?#"+link_name,"","top=25,left=25,width=600,height=400,scrollbars,toolbar=no,menu=no,resizable");
}

function Login()
{
	//window.open('login.asp','User_Login','top=100,left=100,width=600,height=400,resizable');
	if (document.getElementById("logindiv"))
	{
		document.getElementById("logindiv").style.display = 'inline';
	}	
}
