﻿// JScript File

/******************************************************************************
*   Name:   init
*   Param:  nothing
*   Description: initialize variables and events when window is loading
*
******************************************************************************/
function init() {
    window.status = "Orange Coast College - 2701 Fairview Road, Costa Mesa, California 92626 - 714.432.0202";
    CheckWindowMode();
}

/******************************************************************************
*   Name:   cast_url
*   Param:  url - url to link
*   Description: Remove "home" in url if host is "www.orangecoastcollege.edu"
*
******************************************************************************/
function cast_url(url) {
    var host = document.domain;
    if ((host == "www.orangecoastcollege.edu") || (host == "orangecoastcollege.edu")){
        return "/" + url;
        }
    else {
        return  "/home/" + url;
        }
}

/******************************************************************************
*   Name:   
*   Param:  
*   Description: 
*
******************************************************************************/
function anchor_link(comp, url) {
    comp.href = cast_url(url);
}

/******************************************************************************
*   Name:   jsredirect
*   Param:  url - url to redirect
*   Description: Redirect the web site to another location
*
******************************************************************************/
function jsredirect(url) {
    window.location = cast_url(url);
}

/******************************************************************************
*   Name:   OpenPrintableVersion
*   Param:  
*   Description: Open new window with new window.name = "PrintableVersion"
*       but same url as parent window
*
******************************************************************************/
function OpenPrintableVersion() {
    window.open(window.location, "PrintableVersion");
}

/******************************************************************************
*   Name:   CheckWindowMode
*   Param:  
*   Description: Check window name to see if either is a Printable Mode or
*       Viewable Mode.  If it's Printable Mode, call PrintableVersion();
*
******************************************************************************/
function CheckWindowMode() {
    if (window.name == "PrintableVersion") {
        PrintableVersion();
        }
}

/******************************************************************************
*   Name:   PrintableVersion
*   Param:  
*   Description: Show the page in printable version and enable printing 
*       property
*
******************************************************************************/
function PrintableVersion() {
    var form_body = document.getElementById("htmlFormBodyContent");
    var print_content = document.getElementById("htmlFriendlyPrintingContent");
    var page_content = document.getElementById("htmlPageContent");
    
    if ((page_content != null) 
        && (print_content != null) 
        && (form_body != null)) {
            document.body.style.background = "white";
            print_content.innerHTML = "<p style='font-weight: bold; font-size: 11pt; "
                            + "font-family: Arial; border-bottom: double line;'> " 
                            + document.title + "</p><div style='font-size: 10pt; font-family: Arial;'" 
                            + page_content.innerHTML + "</div>";
            form_body.style.display = "none";
            //alert("To view the site back in original mode, press F5 or click Refesh.");
            //window.print();
            var printMode = document.getElementsByName("printablemode");
            if (printMode.length > 0)
            for (var i = 0; i < printMode.length; i++)
                { printMode[i].style.display = "none"; }
                
        }    
}

/******************************************************************************
*   Name:   GetBrowser
*   Param:  
*   Description: Get Browser
*
******************************************************************************/
var Browser = new Object();
Browser.browserName = navigator.appName; 
Browser.browserVersion = parseInt(navigator.appVersion);
Browser.UA = navigator.userAgent.toLowerCase();
Browser.isIE6or7 = false;
Browser.isFirefox = false;
Browser.isInternetExplorer = false;
Browser.isMozilla = false;
Browser.isNetscape4 = false;

GetBrowser();

function GetBrowser() {
    if (Browser.browserName == 'Microsoft Internet Explorer')
    {
        if (Browser.browserVersion > 3)
        {
            Browser.isInternetExplorer = true;
            if ( (Browser.UA.indexOf("msie 6") != -1) || (Browser.UA.indexOf("msie 7") != -1) )
            {
                Browser.isIE6or7 = true;
            }
        }
    }

    if (Browser.browserName == 'Netscape')
    {
        if (Browser.browserVersion == 4)
        {
            Browser.isNetscape4 = true;
        }
        if (Browser.browserVersion > 4)
        {
            Browser.isMozilla = true;
        }
        if ( Browser.UA.indexOf("firefox") != -1 )
        {
	        Browser.isFirefox = true;
        }
    }
}

/******************************************************************************
*   Name:   getElmById
*   Param:  
*   Description: Get element ID (cross flatform)
*
******************************************************************************/
function getElmById(aID){ 
  var element = null; 

  if (Browser.isMozilla || Browser.isIE6or7) 
    element = document.getElementById(aID);
  else if (Browser.isNetscape4) 
    element = document.layers[aID];
  else if ((!Browser.isIE6or7) && Browser.isInternetExplorer) 
    element = document.all[aID];

  return element; 
}

/******************************************************************************
*   Name:   restoreInputStyles
*   Param:  
*   Description: remove google autofill
*
******************************************************************************/
function restoreInputStyles(){
    var inputList = document.getElementsByTagName("INPUT");
    for(i=0;i<inputList.length;i++){
        if(inputList[i].title.toLowerCase() == "required field") {
            inputList[i].style.backgroundColor = "yellow";
            }
        else {
            inputList[i].style.backgroundColor = "";
            }        
        }
    selectList = document.getElementsByTagName("SELECT");
    for(i=0;i<selectList.length;i++){
        if(selectList[i].title.toLowerCase() == "required field") {
            selectList[i].style.backgroundColor = "yellow";
            }
        else {
            selectList[i].style.backgroundColor = "";
            }
        }
    window.setTimeout(restoreInputStyles, 100);
}


/******************************************************************************
*   Name:   findObjPos
*   Param:  obj - reference to an object
*   Description: Find Object Position, return an array of (x,y) prepresent
*   x-coord and y-coord.
*
******************************************************************************/
function findObjPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
	    curleft = obj.offsetLeft;
	    curtop = obj.offsetTop;
	    while (obj = obj.offsetParent) {
		    curleft += obj.offsetLeft;
		    curtop += obj.offsetTop;
	    }
    }
    return [curleft,curtop];
}


/******************************************************************************
*   Name:   detectFMX
*   Param:  
*   Description: Detect flash plugin
*
******************************************************************************/
/*
function DetectFlash(){ 
	var reqVer = 6;
	//var pluginChk = false;
	
	if (document.all){
		document.write('<scr' + 'ipt language="VBScript"\> \n');
		document.write('function chkIe()\n');
		document.write('  on error resume next\n');
		document.write('	dim success : success = false\n');
		document.write('	dim flashVer : flashVer = 0\n');
		document.write('	dim i\n');
		document.write('	for i=9 to i=0 step -1\n');
		document.write('		set oFlash = createObject("shockwaveflash.shockwaveflash." & i)\n');
		document.write('		if isObject(oFlash) then\n');
		document.write('			flashVer = cStr(i)\n');
		document.write('			exit for\n');
		document.write('		end if\n');
		document.write('	next\n');
		document.write('	if flashVer  '+reqVer+' then\n');
		document.write('		success = false\n');
		document.write('	else\n');	
		document.write('		success = true');
		document.write('	end if\n');
		document.write('chkIe = success\n');
		document.write('end function\n');
		document.write('</scr' + 'ipt\> \n'); 
		pluginChk = chkIe(); 
	} else {
		if (navigator.plugins != null && navigator.plugins.length > 0) {
			var daPlugin = navigator.plugins['Shockwave Flash'];
			if (daPlugin) {
				for (i=9;i>0;i--){
					if (daPlugin.description.indexOf(i+'.') != -1){
						var flashVersion = i;
						break;
					}
				}
			}
			
			if (!daPlugin || flashVersion < reqVer){
			  pluginChk = false; 
			} else {
			  pluginChk = true;     
			}
		}
	}
      
    var nonflashObj = document.getElementsByName("NoFlash");		
  
    alert(nonflashObj.length):
  
	if (pluginChk){	
		// do something
		//alert("you have the current plugin");
		if (nonflashObj.length > 0)
            for (var i = 0; i < nonflashObj.length; i++)
                { nonflashObj[i].style.display = "none"; }
	} else {
		// do something else
		if (nonflashObj.length > 0) {
            for (var i = 0; i < nonflashObj.length; i++)
                { nonflashObj[i].style.display = "inline"; }
        } else {
            var msg = '';
		    msg = 'This site uses the Macromedia Flash Plugin to display content.\n';
		    msg += 'The plugin is safe, fast and painless to download from www.macromedia.com\n';
		    msg += 'Would you like to go there now?';
		    if (confirm(msg)){
			    document.location='http://www.macromedia.com/downloads/';
		    }    		
        }
	}
	
}	
*/