/*******************************************************************************
*                                                                              *
*   Earl Wild Official Web Site                                                *
*                                                                              *
*	filename: common.js                                                        *
*	path: rootPath/includes/                                                   *
*	date: 09/23/2003                                                           *
*                                                                              *
*   ************************************************************************   *
*                                                                              *
*	Following scripts are basis of the whole site.                             *
*                                                                              *
*	Including:                                                                 *
*	   -Browser Detection                                                      *
*	   -Get File Path Function                                                 *
*	   -Get Parameter Function                                                 *
*	   -Load Script Function                                                   *
*	   -Site Root Path Configuration                                           *
*	   -BgColor Change Function                                                *
* 	   -Sub Window Check Function                                              *
*	   -New Window Function                                                    *
*	   -Image Window Function                                                  *
*	   -Scroller Function                                                      *
* 	   -StyleSheet Selection                                                   *
* 	   -Advanced StyleSheet Configuration                                      *
*                                                                              *
*	Don't touch this script set.                                               *
*	Don't change order of following scripts.                                   *
*                                                                              *
*   ************************************************************************   *
*                                                                              *
*   Can I use this script set?                                                 *
*                                                                              *
*     -No.                                                                     *
*                                                                              *
*   ************************************************************************   *
*                                                                              *
*   Web Site Design                                                            *
*                                                                              *
*     design: bussiness like+                                                  *
*     style: text based (56Kb dial-up friendly)                                *
*                                                                              *
*	(c) reinnovation - accommodate radical creation                            *
*	    www.reinnovation.com                                                   *
*                                                                              *
*******************************************************************************/


	var c = config;
	var d = document;


/*******************************************************************************
*  Browser Detection                                                           *
*******************************************************************************/


	isIE = isNS = isNS4 = isNS5 = isNS6 = isNS7 = isNS8 = isFlash5 = isFlashMX = false;

	// Browser Information

	if(navigator.appName.indexOf('Netscape') != -1) isNS = true;
	if(navigator.appName.indexOf('Microsoft') != -1) isIE = true;

	isUNIX = (window.navigator.appVersion.indexOf('X11') != -1)
				|| (window.navigator.appVersion.indexOf('Linux') != -1)
				|| (window.navigator.appVersion.indexOf('SunOS') != -1)
				|| (window.navigator.appVersion.indexOf('IRIX') != -1)
				|| (window.navigator.appVersion.indexOf('HP-UX') != -1);
	isMac = (window.navigator.appVersion.indexOf('Mac') != -1);
	isWindows = navigator.userAgent.indexOf('Windows 95') != -1
				|| navigator.userAgent.indexOf('Windows 98') != -1
				|| navigator.userAgent.indexOf('Windows NT') != -1;
	isMacIE = (isMac && isIE);

	// Netscape Version

	if(isNS) {

		v = parseInt(navigator.appVersion);

		if(v <= 4) {
			isNS4 = true;
		} else if(v >= 5) {
			isNS5 = true;
			p = navigator.userAgent.lastIndexOf('/');
			v = parseInt(navigator.userAgent.substr(p+1));
			eval('isNS' + v + ' = true');
		}
	}

	// Flash Version

	if (navigator.mimeTypes && navigator.mimeTypes['application/x-shockwave-flash'] && navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin) {

		if (navigator.plugins && navigator.plugins['Shockwave Flash'] && (versionIndex = navigator.plugins['Shockwave Flash'].description.indexOf('.')) != - 1) {

			var versionString = navigator.plugins['Shockwave Flash'].description.substring(versionIndex-1, versionIndex);
			versionIndex = parseInt( versionString );

			if ( versionIndex >= 5 ) {
				isFlash5 = true;
			}

			if ( versionIndex >= 6 ) {
				isFlashMX = true;
			}

		}

	} else if (isIE && isWindows) {

		d.write('<script language="VBScript">\n');
		d.write('	on error resume next\n');
		d.write('	isFlash5 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5")))\n');
		d.write('	isFlashMX = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6")))\n');
		d.write('</script>\n');

	}


/*******************************************************************************
*  Get File Path Function                                                      *
*******************************************************************************/


	function getFilePath() {

		if (location.protocol.indexOf("file") != -1) {
			rootPath = rootURL = location.protocol + "///" + c.rootPath;
		} else {
			rootPath = rootURL = location.protocol + "//" + c.rootPath;
		}

		while (rootURL.indexOf(" ") != -1) {
			rootURL = rootURL.replace(" ", "%20")
		}

		var fPath = new Object();
		var aPath = location.href;
		var rPath = aPath.substr(rootURL.length);
		var rPathDirectrys = rPath.split("/");

		for (var i = 0; i < rPathDirectrys.length; i++){

			while (rPathDirectrys[i].indexOf("%20") != -1){
				rPathDirectrys[i] = rPathDirectrys[i].replace("%20", " ");
			}

			var dot = rPathDirectrys[i].indexOf(".");

			if (dot != -1){
				fPath[i] = rPathDirectrys[i].substring(0, dot);
			} else {
				fPath[i] = rPathDirectrys[i];
			}

		}

		if (fPath[0] == "") fPath[0] = "index";

		return fPath;

	}

	var filePath = getFilePath(); 

	// Browsing Control
	// if(!isNS5 && !isIE) {
	// 	d.write('<meta http-equiv="refresh" content="0; url='+ rootPath +'browser.html">\n');
	// }

	// Redirect invalid access
	if ((d.referrer.indexOf(rootPath) != -1) || (d.referrer.length == 0) || (d.referrer == null) ){
		if (!window.parent.fr_mid_left) {
			location.href = rootPath + 'index.html';
		}
	}


/*******************************************************************************
*  Get Parameter Function                                                      *
*******************************************************************************/


	function getParam() {

		var args = new Object();
		var query = location.search.substring(1);
		var pairs = query.split('&');

		for(var i = 0; i < pairs.length; i++){

			var pair = pairs[i];
			var index = pair.indexOf('=');

			if(index == -1) continue;

			var key = pair.substring(0, index);
			var value = pair.substring(index+1);

			args[key] = unescape(value);

		}

		return args;

	}

	var param = getParam();


/*******************************************************************************
*  Site Root Path Configuration                                                *
*******************************************************************************/


	d.write('<base href="'+ rootPath +'">');


/*******************************************************************************
*  BgColor Change Function                                                     *
*******************************************************************************/


	function mPoint(src, txtColor, bgColor){

		src.style.color = txtColor;
		src.style.backgroundColor = bgColor;

	}

	function mOvr(src){ 

		if (isIE){
			if (!src.contains(event.fromElement)){
				src.style.cursor = 'hand';
			}
		}

	}

	function mOut(src){

		if (isIE){
			if (!src.contains(event.toElement)){
				src.style.cursor = 'default';
			}
		}

	}

	function mClk(src){

		if (isIE){
			if (event.srcElement.tagName == 'td'){
				src.children.tags('a')[0].mPoint();
			}
		}

	}


/*******************************************************************************
*  Sub Window Check Function                                                   *
*******************************************************************************/


	function sbwin_closed(winVar) {

		if ( !!winVar )
			if ( isIE !=-1 && isWindows ) 
				return winVar.closed
			else return typeof winVar.d != 'object'
		else return true

	}


/*******************************************************************************
*  New Window Function                                                         *
*******************************************************************************/


	function openWindow(loc, name, features) {

		var newWindow;

		newWindow = window.open(loc, name, features);
		newWindow.focus();

	}


/*******************************************************************************
*  Image Window Function                                                       *
*******************************************************************************/


	var imageWindow;

	function imagewin(imagePath) {

		if (sbwin_closed(imagePath)) {
			imageWindow = window.open(rootPath +'imagewin.html?image='+ imagePath,'image','left=0,top=0,menubar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0');
			imageWindow.focus();
		} else {
			imageWindow = window.open(rootPath +'imagewin.html?image='+ imagePath,'image','left=0,top=0,menubar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0');
			imageWindow.focus();
		}

	}


/*******************************************************************************
*  Page Top Function                                                           *
*******************************************************************************/


	function getScroll(){

		var y;

		if(isIE){
			y = d.body.scrollTop;
		} else if (isNS){
			y = window.pageYOffset;
		} else {
			y = gy = 0;
		}

		return {y: y};

	}

	var SCROLL;

	function pageTop(edging){

		SCROLL = getScroll();

		if(SCROLL.y > 0){

			var ny = Math.floor(SCROLL.y+(0-SCROLL.y)/edging);

			window.scrollTo(0, ny);

			var startScroll = setTimeout("pageTop("+ edging +");", 15);

		} else {

			clearTimeout(startScroll);
			window.scrollTo(0, 0);

		}

	}


/*******************************************************************************
*  StyleSheet Selection                                                        *
*******************************************************************************/


	if (isIE) {
		d.write('<link rel="StyleSheet" type="text/css" href="'+ rootPath +'includes/mrdp.css">');
	} else if (isNS5) {
		d.write('<link rel="StyleSheet" type="text/css" href="'+ rootPath +'includes/mrdp.css">');
	} else {
		d.write('<link rel="StyleSheet" type="text/css" href="'+ rootPath +'includes/mrdp.css">');
	}


/*******************************************************************************
*  Advanced StyleSheet Configuration                                           *
*******************************************************************************/


	if (param['referrer']) {
		var category_color = c[param['referrer']+'_color'];
	} else {
		var category_color = c[filePath[0]+"_color"];
	}

	if (!link_color) var link_color = category_color;

	var colors, colorR, colorG, colorB, colorP, links, linkR, linkG, linkB, link0, link1, link2, title_color;

	function convert(rgb, operator, num){

		i = rgb.charAt(0);

		if (i == "a" || i == "A") x = 10;
		else if(i == "b" || i == "B") x = 11;
		else if(i == "c" || i == "C") x = 12;
		else if(i == "d" || i == "D") x = 13;
		else if(i == "e" || i == "E") x = 14;
		else if(i == "f" || i == "F") x = 15;
		else x = parseInt(i);

		if (i != "f" && i != "F" && i != "0"){
			if (operator == "add" ) x += num;
			else if (operator == "minus" ) x -= num;
			else x = x;
		}

		if (x == 10) x = "a";
		else if(x == 11) x = "b";
		else if(x == 12) x = "c";
		else if(x == 13) x = "d";
		else if(x == 14) x = "e";
		else if(x == 15) x = "f";
		else if(x >= 16) x = "f";
		else x = parseInt(x);

		if (x <= 0 ) x = 0;

		rgb = String(x) + String(x);

		return rgb;

    }

	colors = category_color.substring(1, 7);
	colorR = colors.substring(0, 2);
	colorG = colors.substring(2, 4);
	colorB = colors.substring(4, 6);

	links = link_color.substring(1, 7);
	linkR = links.substring(0, 2);
	linkG = links.substring(2, 4);
	linkB = links.substring(4, 6);

	colorP = "#" + convert(colorR, 'minus', 3) + convert(colorG, 'minus', 3) + convert(colorB, 'minus', 3);

	link0 = "#" + convert(linkR, 'minus', 2) + convert(linkG, 'minus', 2) + convert(linkB, 'minus', 2);
	link1 = "#" + convert(linkR, 'minus', 3) + convert(linkG, 'minus', 3) + convert(linkB, 'minus', 3);
	link2 = "#" + convert(linkR, 'add', 3) + convert(linkG, 'add', 3) + convert(linkB, 'add', 3);

	title_color = "#" + convert(colorR, 'minus', 3) + convert(colorG, 'minus', 3) + convert(colorB, 'minus', 3);

	if (!menuText_color) var menuText_color = colorP;

	// Additional Style

		d.write('',
			'<style type="text/css">',
			'',
			'	<!--',
			'',
			'		a:link',
			'',
			'			{',
			'				color: '+ link0 +';',
			'				text-decoration: underline;',
			'			}',
			'',
			'		a:visited',
			'',
			'			{',
			'				color: '+ link1 +';',
			'				text-decoration: underline;',
			'			}',
			'',
			'		a:active',
			'',
			'			{',
			'				background-color: '+ link0 +';',
			'				color: #ffffff;',
			'				text-decoration: none;',
			'			}',
			'',
			'		a:hover',
			'',
			'			{',
			'				background-color: '+ link0 +';',
			'				color: #ffffff;',
			'				text-decoration: none;',
			'			}',
			'',
			'		body',
			'',
			'			{',
			'				scrollbar-arrow-color: '+ category_color +';',
			'			}',
			'',
			'		p',
			'',
			'			{',
			'				color: '+ colorP +';',
			'				font-family: verdana, Arial;',
			'				font-size: 16px;',
			'				font-style: normal;',
			'				font-weight: bold;',
			'				letter-spacing: 0px;',
			'				line-height: 120%;',
			'				margin-bottom: 0px;',
			'				margin-left: 0px;',
			'				margin-right: 0px;',
			'				margin-top: 0px;',
			'				padding-bottom: 0px;',
			'				padding-left: 0px;',
			'				padding-right: 0px;',
			'				padding-top: 0px;',
			'			}',
			'',
			'		span',
			'',
			'			{',
			'				color: '+ colorP +';',
			'				font-family: verdana, Arial;',
			'				font-size: 12px;',
			'				font-style: normal;',
			'				letter-spacing: 0px;',
			'				line-height: 130%;',
			'				margin-bottom: 0px;',
			'				margin-left: 0px;',
			'				margin-right: 0px;',
			'				margin-top: 0px;',
			'				padding-bottom: 0px;',
			'				padding-left: 0px;',
			'				padding-right: 0px;',
			'				padding-top: 0px;',
			'			}',
			'',
			'		.menu',
			'',
			'			{',
			'				color: '+ link0 +';',
			'				font-style: normal;',
			'				letter-spacing: 0px;',
			'				line-height: 130%;',
			'				margin-top: 0px;',
			'				margin-bottom: 0px;',
			'				margin-left: 0px;',
			'				margin-right: 0px;',
			' 				padding-top: 0px;',
			'				padding-bottom: 0px;',
			'				padding-left: 5px;',
			'				padding-right: 5px;',
			'			}',
			'',
			'		.1stLetter',
			'',
			'			{',
			'				color: '+ colorP +';',
			'				font-size: 20px;',
			'			}',
			'',
			'	-->',
			'',
			'</style>',
			'');


/***** Additional Extensions will be writen follow. */

