// pop ups
function openPDF()
{
	var url = "GetPDF.aspx?u=" + window.location.href + "&pn=" + document.title;				
	openWindow( url,'width=1024,height=768' );
}

function openNewsLetter()
{
	openWindow( 'docs/NewsLetter.html','width=500,height=300' );
}

function openSendToFriend()
{
	openWindow( 'docs/SendToFriend.aspx','width=500,height=300' )
}

function openWindow( url,winSize ) {
  popWindow = window.open(url,'poppedWindow',winSize,'toolbar=no,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizeable=1');
  if ( !popWindow )
	alert("Please disable your pop-up blocker to access this portion of the site.");
  else
    popWindow.focus();
}


/* ---------------------------- =Popup Window -------------------------------*/

function popupWindow (url, name, width, height, properties) {
	if (!name) name = "popWin";
	if (!width) width = "800";
	if (!height) height = "500";
	
	var features = "width=" + width + ",height=" + height;

	//	-- properties --
	//	not set or false    : standard clean window with no address bar, etc.
	//	some string         : use the string
	
	if (!properties || properties == false) {
		features += ",left=0,top=0,toolbar=1,location=1,directories=0,status=1,menubar=1,resizable=1,scrollbars=1";
	} else {
		features += properties;
	}
	
	var popWin = window.open(url, name, features);	
	checkPopped(popWin);
	return popWin;
}

function checkPopped (winName) {
	if (winName)
		winName.focus();
	else {
	    var popupWarning = 'Pop-up blocking software in your browser has prevented us from opening a new window. In order for this site to function properly please disable your Pop-up blocking software for this site.';
		alert(popupWarning);
		return;
	}
}

function openFlashMap () {
	popupWindow('http://www.songdo.com/uploads/documentrepository/songdo_flash_map/gale_web.html','flashWin','1000','562','left=0,top=0,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no');
}




//-----------------------------------------------------------------------------
// Toggle Search

function toggleLayer(whichLayer) {
	if (document.getElementById) {
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
	} else if (document.all) {
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
	} else if (document.layers) {
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
	//this path could change
	if (style2.display) document.forms[0]._ctl0_Header_Search_txtSearch.focus();
}


//-------------------------------------------------------------------------------
// Toggle Layer based on drop down value
function toggleOtherLayer(whichLayer, whichDDL, testValue) {
	var ddl;
	var style2;
	if (document.getElementById) {
		// this is the way the standards work
		ddl = document.getElementById(whichDDL);
		style2 = document.getElementById(whichLayer).style;		
	} else if (document.all) {
		// this is the way old msie versions work
		ddl = document.all[whichDDL];
		style2 = document.all[whichLayer].style;
		
	} else if (document.layers) {
		// this is the way nn4 works		
		style2 = document.layers[whichLayer].style;		
		style2.display = "block";
		return;
	}
	if ( ddl.options[ddl.selectedindex] == testValue )
		style2.display = "block";
	else
		style2.display = "";
		
	return;
}


//-----------------------------------------------------------------------------
// Preload Images

loc_1=new Image();
loc_1.src="images/n_location.jpg";

loc_2=new Image();
loc_2.src="images/n_location2.jpg";

team_1=new Image();
team_1.src="images/n_team.jpg";

team_2=new Image();
team_2.src="images/n_team2.jpg";

plan_1=new Image();
plan_1.src="images/n_plan.jpg";

plan_2=new Image();
plan_2.src="images/n_plan2.jpg";

phasing_1=new Image();
phasing_1.src="images/n_phasing.jpg";

phasing_2=new Image();
phasing_2.src="images/n_phasing2.jpg";





//-----------------------------------------------------------------------------
// Flash Detect + Embed
// ----------------------------------------------------------------------------

function flashInit( FlashPath, ImgPath, width, height, flashVersion, redirect)
{
	if (!width) { width = "602"; }
	if (!height) 
	{
		var size = FlashPath.indexOf('&');
		if(size > 0)
		{
			size = FlashPath.substring((FlashPath.indexOf('&')) +1);
			size = size.substring(0 , (size.indexOf('.')));
			height = size;
			FlashPath = FlashPath.substring(0 , (FlashPath.indexOf('&'))) + FlashPath.substring((FlashPath.indexOf('.')));
		}
		else{height = "214";}
	}
	
	if (!flashVersion) { flashVersion = 7; }

	// Globals
	// Major version of Flash required
	var requiredMajorVersion = flashVersion;
	// Minor version of Flash required
	var requiredMinorVersion = 0;
	// Revision of Flash required
	var requiredRevision = 0;
	// the version of javascript supported
	var jsVersion = 1.0;
	// -----------------------------------------------------------------------------

	// Visual basic helper required to detect Flash Player ActiveX control version information
	if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 
		&& (navigator.appVersion.indexOf("Win") != -1)) {
			var detectThroughVB = '<script language="VBScript" type="text/vbscript">\r'
				+ 'Function VBGetSwfVer(i)\r'
				+ '\ton error resume next\r'
				+ '\tDim swControl, swVersion\r'
				+ '\tswVersion = 0\r'
				+ '\tset swControl = CreateObject("ShockwaveFlash.ShockwaveFlash." + CStr(i))\r'
				+ '\tif (IsObject(swControl)) then\r'
				+ '\t\tswVersion = swControl.GetVariable("$version")\r'
				+ '\tend if\r'
				+ '\tVBGetSwfVer = swVersion\r'
				+ 'End Function\r'
				+ '</script>';
			document.write(detectThroughVB);   // write the detect through VB script
	}

	// Detect Client Browser type
	var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
	var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
	jsVersion = 1.1;
	// JavaScript helper required to detect Flash Player PlugIn version information
	function JSGetSwfVer(i){
		// NS/Opera version >= 3 check for Flash plugin in plugin array
		if (navigator.plugins != null && navigator.plugins.length > 0) {
			if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
				var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
				var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
				descArray = flashDescription.split(" ");
				tempArrayMajor = descArray[2].split(".");
				versionMajor = tempArrayMajor[0];
				versionMinor = tempArrayMajor[1];
				if ( descArray[3] != "" ) {
					tempArrayMinor = descArray[3].split("r");
				} else {
					tempArrayMinor = descArray[4].split("r");
				}
				versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
				flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
			} else {
				flashVer = -1;
			}
		}
		// MSN/WebTV 2.6 supports Flash 4
		else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
		// WebTV 2.5 supports Flash 3
		else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
		// older WebTV supports Flash 2
		else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
		// Can't detect in all other cases
		else {
			
			flashVer = -1;
		}
		return flashVer;
	}
	// If called with no parameters this function returns a floating point value 
	// which should be the version of the Flash Player or 0.0 
	// ex: Flash Player 7r14 returns 7.14
	// If called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
	function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
	{
		reqVer = parseFloat(reqMajorVer + "." + reqRevision);
		// loop backwards through the versions until we find the newest version	
		for (i=25;i>0;i--) {	
			if (isIE && isWin && !isOpera) {
				versionStr = VBGetSwfVer(i);
			} else {
				versionStr = JSGetSwfVer(i);
			}
			if (versionStr == -1 ) { 
				return false;
			} else if (versionStr != 0) {
				if(isIE && isWin && !isOpera) {
					tempArray         = versionStr.split(" ");
					tempString        = tempArray[1];
					versionArray      = tempString .split(",");
				} else {
					versionArray      = versionStr.split(".");
				}
				versionMajor      = versionArray[0];
				versionMinor      = versionArray[1];
				versionRevision   = versionArray[2];
				
				versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
				versionNum        = parseFloat(versionString);
				
				// is the major.revision >= requested major.revision AND the minor version >= requested minor
				if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
					return true;
				} else {
					return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
				}
			}
		}	
		return (reqVer ? false : 0.0);
	}

	var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

	if(hasRightVersion) {  // if we've detected an acceptable version
		var oeTags = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
		+ 'width="' + width + '" height="' + height + '"'
		+ 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
		+ '<param name="movie" value="' + FlashPath + '" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><param name="WMode" value="Transparent">'
		+ '<embed src="' + FlashPath + '" quality="high" bgcolor="#ffffff" '
		+ 'width="' + width + '" height="' + height + '" name="home" align="middle"'
		+ 'play="true"'
		+ 'loop="false"'
		+ 'quality="high"'
		+ 'wmode="transparent"'
		+ 'allowScriptAccess="sameDomain"'
		+ 'type="application/x-shockwave-flash"'
		+ 'pluginspage="http://www.macromedia.com/go/getflashplayer">'
		+ '<\/embed>'
		+ '<\/object>';
		document.write(oeTags);   // embed the flash movie
	} else {  // flash is too old or we can't detect the plugin
		if (redirect) 
			window.location = redirect;
		else if (ImgPath != '') document.write('<img src="' + ImgPath +'" width="' + width + '" height="' + height + '" alt="" border="0" />');
	}
}


//-----------------------------------------------------------------------------
// Mail To

function mailTo(username, domain)
{
	document.location = 'mailto: ' + username + '@' + domain + '?subject=New Songdo City Website Contact';
}


/* ---------------------------- =Event Listener / Handler Wire-up -----------------*/

// obj        : object to apply listener to
// eventType  : event type - i.e. load, click, mouseover, mouseout
// fn         : function to call on event

// Example - addListener(window, "load", someFunction);

function addListener (obj, eventType, fn){
	if (obj.addEventListener){
		obj.addEventListener(eventType, fn, false);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on" + eventType, fn);
		return r;
	} else {
		alert("Handler could not be attached");
	}
}

function removeListener (obj, eventType, fn ){
	if (obj.removeEventListener){
		obj.removeEventListener(eventType, fn, false);
		return true;
	} else if (obj.detachEvent){
		var r = obj.detachEvent("on" + eventType, fn);
		return r;
	} else {
		alert("Handler could not be removed");
	}
}