
// User infoirmation
var g_isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var g_isIE5 = (navigator.appVersion.indexOf("5.") != -1) ? true : false;
var g_isIE6 = (navigator.appVersion.indexOf("6.") != -1) ? true : false;
var g_isNS = (navigator.appName.indexOf("Netscape") != -1) ? true : false;

// platform 
var g_isWin = (navigator.appVersion.indexOf("Win") != -1) ? true : false;
var g_isMac = (navigator.appVersion.indexOf("Mac") != -1) ? true : false;


// put this on a text box to trigger form submit when enter key is hit
function onKeyDownEvent( e, gotoPage ){
	if (( e.which && e.which == 13 ) || (e.keyCode && e.keyCode == 13)) {
		if( typeof(gotoPage) == 'undefined' )
			document.forms[0].submit();		
		else
			location.replace( gotoPage );
		return false;
	} else 
		return true;
}

/// Create a comparison function for strings
if (!String.compare) {
	String.compare = function(s1, s2) {
	
    if (s1 == s2) {
      return 0;
    }
    if (s1 > s2) {
      return 1;
    }
    return -1;
  };
}

 // This function will simply toggle the incoming form field to either be blank or a defaut message
 // Used on onBlur and onFocus events
 function updateSearchBox(element, message) {
	if ( String.compare(element.value, message) == 0 ) {
		element.value = '';
	}
	else if (element.value.length == 0) {
		element.value = message;
	}
 }

function openWin(strUrl, strName, sOptions){
		
	if(strName.toLowerCase() == 'add2myportfolio'){
		// need to add current page that we are browsing
		strUrl = strUrl + '?link=' + window.location.href + '?' + window.location.search;  // global JS varible set in userrolestyles.asp					
	}

	var w = window.open(strUrl, strName, sOptions);
	//if( w == null ){
	if( !w ){
		var msg = '';
		msg += 'It appears you have a popup blocker runnning on your browser.\r';
		msg += 'NYLearns.org utilizes popups in certain areas to provide a quality visiting \r';
		msg += 'experience to all of our users.  We do not use popups for advertisements \r';
		msg += 'or promotional materials.  To maximize your NYLearns.org experience, please \r';
		msg += 'allow popups on your browser for NYLearns.org';
		// alert user
		alert( msg );
	} else {
		// set focus on the window
		w.focus();
	} // end if
}

// ---------------------------------------------------- //

function setWindowStatus(sMessage){
	window.status = sMessage;
}

// ---------------------------------------------------- //

function getBrowserPlugin(sPlugin){
	// function
	// opens window with plugin
	var sUrl, swindowoptions;
		
	sUrl = '/utilities/getPlugin.asp?plugin=' + sPlugin ; 
	windowoptions = 'width=600,height=500,left=75,top=50,screenX=75,screenY=50, toolbars=no, scrollbars=yes, menubar=no,';
		
	var w = window.open(sUrl, 'plugin', windowoptions);
	w.focus();
}

// ---------------------------------------------------- //

function printMe(){
	// this function will be called to print
	// the current page
//	if(!(g_isMac && g_isIE5)){
		// wait a second
		setTimeout("window.print();", 1000);
//	}
}

// ----------------------------------------------------- //

function sendToFriend(){
	openWin('/send2friend.aspx?page=' + window.location.href , 'sendemail', 'width=475,height=500,scrollbars=1,toolbar=0,menubar=0;');
	//openWin('/send2friend.asp?page=' + window.location.href + '?' + window.location.search , 'sendemail', 'width=475,height=500,scrollbars=1,toolbar=0,menubar=0;');
}

// ----------------------------------------------------- //

function ReplaceVB(strSource, strFind, strReplace){
	var regExp = eval('/' + strFind + '/gi');
	var strReturn = strSource.replace(regExp, strReplace);
	return strReturn;
}

// ----------------------------------------------------- //

function showIntro(){
	openWin('/intro/intro.htm', 'intro', 'width=480,height=360,status=no,resizable=no');
}

// ---------------------------------------------------- //

function previewContent(lContentID){
	// open a preview window for the content
	openWin('/content/preview.asp?ContentID=' + lContentID, 'preview', 'width=800,height=600,left=100,top=100,screenX=75,screenY=50, resizable=1, toolbars=no, scrollbars=1, menubar=no');
}


function editContent( lContentID ){
	// open the editing page for content
	// location.href = '/registered/content/Content_1.asp?ContentID=' + lContentID;
	openWin( '/registered/content/Content_1.asp?ContentID=' + lContentID, 'pybeditor', 'width=800,height=600,left=100,top=100,screenX=75,screenY=50, resizable=1, toolbars=no, scrollbars=1, menubar=no');
}

// ---------------------------------------------------- //

function startHelp(sContext, lHelpID){
	openWin('helpdesk', 'Helpdesk', 'height=485,width=620,toolbars=0,scrollbars=1,menubar=0');
}


// ---------------------------------------------------- //

function openHTMLScratchPad(){
	openWin('/tools/scratchpad/', 'scratchpad' , 'width=420,height=500,left=100,top=100,screenX=75,screenY=50, toolbars=no, scrollbars=1, menubar=no');
} // opens HTMl Scratch Pad


function openCATEPad(){
	openWin('/tools/scratchpad/cate.asp', 'catepad' , 'width=600,height=500,left=100,top=100,screenX=75,screenY=50, toolbars=no, scrollbars=1, menubar=no');
} // opens HTMl Scratch Pad

function closeWindow(){
	window.close();
	return false;
}

// overview of Nylearns.org
var cd_url = '/cd/cd.aspx';
function Overview(){
	openWin(cd_url, 'Overview', 'width=620,height=640,left=100,top=100,screenX=75,screenY=75,location=0,toolbars=no,status=0,scrollbars=0,menubar=0,resizable=0')
}

// ----------------------------------------------------  //

function resizeWin( startSize , targetSize , moveX, finalX, finalY){
	var x;
	if (startSize < targetSize){
		for (x = startSize; x <= targetSize; x = x + moveX)
			window.resizeBy(moveX, 0);
	} else {
		for (x = startSize; x > targetSize; x = x - moveX)
			window.resizeBy(moveX, 0);
	}
	
	// finish this
	if (finalX != undefined)
			window.resizeTo(finalX, 450);			
			
	if (finalY != undefined)
			window.resizeTo(finalX, finalY);			
} // end of resize	

// ----------------------------------------------------  //

function organizationInfo(orgid){
	openWin('/public_web/pd/OrgInfo.asp?Orgid='+ orgid , 'org', 'width=660,height=500,left=100,top=100,screenX=75,screenY=50,location=no,status=no,menubar=no,toolbar=yes,resizable=yes,scrollbars=yes');
}

// ----------------------------------------------------  //

function openAtomicLearning( movieSrc , notFree){
	// http://www.atomiclearning.com/freealmovie?key= []
	// http://www.atomiclearning.com/cgi/atomicmovielog.cgi?movie=
	var url = '/content/goToATL.asp?id='+ movieSrc + '&fx=' + notFree;
	/*
	var url='';
	if( ( notFree == 'undefined' ) || ( notFree == 0 ) || ( notFree == null ) ){
		url += 'http://www.atomiclearning.com/freealmovie?key='+ movieSrc;
	} else {
		url += 'http://www.atomiclearning.com/almovie?key='+ movieSrc;
	}
	url += '&src=nylearns';
	*/
	// open the windows
	openWin( url , 'atomiclearning' , 'width=650,height=550,left=50,top=0');
}

// ----------------------------------------------------  //

function goDCV( movieID, playerServer ){
	if ( playerServer == 'undefined' ){
		// default to WM Player
		playerServer = 1;
	}
	//alert('/content/gotoDcVideo.asp?id='+ movieID + '&server=' + playerServer);
	openWin('/content/gotoDcVideo.asp?id='+ movieID + '&server=' + playerServer, 'DCVideo', 'width=780,height=600,left=100,top=100,screenX=75,screenY=50,location=no,status=no,menubar=no,toolbar=yes,resizable=yes,scrollbars=yes');
}

// ----------------------------------------------------  //

function openKidzonline( url ){
	openWin( url, 'kidzonline', 'width=750,height=450,left=100,top=100,screenX=75,screenY=50,location=no,status=no,menubar=no,toolbar=yes,resizable=yes,scrollbars=yes');
}

// ----------------------------------------------------- //

function showUpdate(){
	openWin('/update/update.asp', 'update', 'width=480,height=360,status=no,resizable=no');
}

// ----------------------------------------------------  //

// ----------------------------------------------	//	

function getBrowserPlugin( sPlugin ){
	// function
	// opens window with plugin
	var sUrl, swindowoptions;
		
	sUrl = '/utilities/getPlugin.asp?plugin=' + sPlugin ; 
	windowoptions = 'width=600,height=500,left=75,top=50,screenX=75,screenY=50, toolbars=no, scrollbars=yes, menubar=no,';
		
	var w = window.open(sUrl, 'plugin', windowoptions);
	w.focus();
}	

// nice function to call from an opener to refresh an openers data that always Bind
function reloadServerForm(){
	document.forms[0].submit();
}

// reload the Url, causing the Initial Page State to happen
function resetLocation(){
	// alert( location.href );
	var url = location.href;
	// try to replace the Url, and force a rebind of Data
	location.replace( url );
}

// ----------------------------------------------	//	

setWindowStatus('NYLearns.org - Be a part of the revolution');
