var i = 1;
var bg_TabGray = "#5A5A5A";

jsHover = function() {
	var hEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0, len=hEls.length; i<len; i++) {
		hEls[i].onmouseover=function() { this.className+=" jshover"; }
		hEls[i].onmouseout=function() { this.className=this.className.replace(" jshover", ""); }
	}

}
if (window.attachEvent && navigator.userAgent.indexOf("Opera")==-1) window.attachEvent("onload", jsHover);

function overlayBg(elementid) {
	el1 = document.getElementById("overlay");
	el1.style.display = (el1.style.display == "block") ? "none" : "block";

	el = document.getElementById(elementid);
	el.style.display = (el.style.display == "block") ? "none" : "block";
}

function overlay(elementid) {
	el = document.getElementById(elementid);
	el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
}

function addFriend() {
	var context = "<div><p align=\"left\">FRIEND NO."+ ++i +"<img src=\"img/line.png\" style=\"margin: -10px 0px 0px 0px; padding: 0px; height: 7px; width:175px;\"></p>NAME <input type=\"text\" name=\"text\" style=\"margin: 0px 0px 2px 42px;\" /><br />EMAIL <input type=\"text\" name=\"text\" style=\"margin: 0px 0px 2px 40px;\" /></div>";
	document.getElementById("taf_friend").innerHTML += context;

}

function changeContexModule1(menuName) {

	// Ver 2.0.091221 mod by RWWWS

	var tabs = new Array("mod1default", "drills", "falevel", "freetour", "coaching", "joinnow");
	var a;
	var elm;

	for (a in tabs)
		if (elm = document.getElementById(tabs[a])) {

			elm.style.display = "none";

			if (elm = document.getElementById("videoflash_" + tabs[a]))
				elm.innerHTML = "&nbsp;";

		}

	el = document.getElementById(menuName);
	el.style.display = "block";

	elm = document.getElementById( "module1_menu" );

	videofile = '';
	picturefile = '';
	acache = '?1';

	var images = new Array(RootUrl + "themes/default/img/module1_menu1_bg.gif" + acache,
				RootUrl + "themes/default/img/module1_menu2_bg.gif" + acache,
				RootUrl + "themes/default/img/module1_menu3_bg.gif" + acache,
				RootUrl + "themes/default/img/module1_menu4_bg.gif" + acache,
				RootUrl + "themes/default/img/module1_menu5_bg.gif" + acache);

	for (var i = 0; i < images.length; i++) {

		var img = new Image();

		img.src = images[i];

	}

	if (menuName == "mod1default") {

		elm.style.background = "transparent url(" + images[0] + ") no-repeat scroll 0%";
		videofile = 'welcome.flv'; //Drill_video_1.flv
		picturefile = 'welcome_frame1.png';

	} else
	if (menuName == "drills") {

		elm.style.background = "transparent url(" + images[1] + ") no-repeat scroll 0%";
		videofile = 'Animated_3D_Drills.flv'; //TurningCircle.flv
		picturefile = 'drillslide.png';

	} else
	if (menuName == "falevel") {

		elm.style.background = "transparent url(" + images[2] + ") no-repeat scroll 0%";
		videofile = 'FA_Level_2.flv'; //GRC_fal2.swf
		picturefile = 'falevel02.jpg';

	} else
	if (menuName == "freetour") {

		elm.style.background = "transparent url(" + images[3] + ") no-repeat scroll 0%";
		videofile = 'GRC_free_tour_2.swf';

	} else
	if (menuName == "joinnow") {

		elm.style.background = "transparent url(" + images[4] + ") no-repeat scroll 0%";

	}

	if (videofile != '') {

//		if (videofile.indexOf(".swf") < 0)

		videofile = "http://monitor.grassrootscoaching.com/" + videofile;
		write_flash( videofile, picturefile, 'videoflash_' + menuName, 'videoflash_mod1default|videoflash_drills|videoflash_falevel' );

	}

}

function changeContexModule2(menuName) {

	document.getElementById("coacheschalkboard").style.display = "none";
	document.getElementById("newsletter").style.display = "none";
	document.getElementById("benefits").style.display = "none";

	el = document.getElementById(menuName);

	if ( menuName == "newsletter" )
		if ( el.style.display != "block" ) {
			makeRequest( RootUrl + "get_country.php" );
		}

	el.style.display = "block";

}


	function IndexOfValue( arr, value ) {
		var ii = -1;
		for( Index = 0; Index < arr.length; Index++ ) {
			if ( arr[ Index ] == value ) {
				ii = Index;
				break;
			}
		}
		return ii;
	}

	function Tab_ChangeTab( BLOCK_NAME, ShowTab, AllTabs ) {
    arr = AllTabs.split( '|' );

		//  Fill all cells with gray color

		for( Index = 0; Index < arr.length; Index++ ) {
			e = document.getElementById( 'tab_' + arr[ Index ] );
			if ( e != null ) {
				//e.style.visibility = "hidden";
				e.style.display = "none";
			}
			e1 = document.getElementById( 'menutab_' + arr[ Index ] );
			if ( e1 != null ) {
				color_s = bg_TabGray;

				e1.style.background = " url(" + RootUrl + "themes/default/img/tab_bg_center.png) no-repeat scroll right center";
				//e1.style.background = color_s + " url(" + RootUrl + "themes/default/img/tab_bg_center.png) no-repeat scroll right center";
			}

			e = document.getElementById( 'tabstyle_' + arr[ Index ] );
			if ( e1 != null ) {
				e.style.background = bg_TabGray;
			}
		}
		elm1 = document.getElementById( "menutab_" + arr[ arr.length - 1 ] );
		elm1.style.background = " url(" + RootUrl + "themes/default/img/tab_bg_end.png) no-repeat scroll right center";


    // Select page

		e = document.getElementById( 'tab_' + ShowTab );
		if ( e != null ) {
			e.style.display = "block";

			if ( ShowTab == "newsletter" ) {
				makeRequest( RootUrl + "get_country.php" );
			}

		}


		e1 = document.getElementById( 'menutab_' + ShowTab );
		if ( ShowTab == arr[ arr.length - 1 ] ) {
			e1.style.background = " url(" + RootUrl + "themes/default/img/tab_bg_end2.png) no-repeat scroll right center";
		} else {
			e1.style.background = " url(" + RootUrl + "themes/default/img/tab_bg_center2.png) no-repeat scroll right center";
    }

    e1 = document.getElementById( 'tabstyle_' + ShowTab );
		if ( ShowTab == arr[ arr.length - 1 ] ) {
			e1.style.background = "#7ACB20 ";
		} else {
			e1.style.background = "#7ACB20 ";
    }

		ElmIndex = IndexOfValue( arr, ShowTab );
		if ( ElmIndex > 0 ) {
			elm1 = document.getElementById( "menutab_" + arr[ ElmIndex - 1 ] );
			elm1.style.background = " url(" + RootUrl + "themes/default/img/tab_bg_center3.png) no-repeat scroll right center";

			elm1 = document.getElementById( "tabstyle_" + arr[ ElmIndex - 1 ] );
			elm1.style.background = bg_TabGray;

			elm1 = document.getElementById( "menutab0_" + BLOCK_NAME );
			if ( elm1 == null )
				elm1 = document.getElementById(   BLOCK_NAME );

			elm1.style.background = " url(" + RootUrl + "themes/default/img/tab_bg_begin.png) no-repeat scroll left center";
		}
		if ( ElmIndex == 0 ) {
		  elm1 = document.getElementById( "menutab0_" + BLOCK_NAME );
		  if ( elm1 == null )
				elm1 = document.getElementById(   BLOCK_NAME );

			elm1.style.background = " url(" + RootUrl + "themes/default/img/tab_bg_begin2.png) no-repeat scroll left center";
		}

	}


	function Tab_ChangeTab2( BLOCK_NAME, ShowTab, AllTabs ) {

		arr = AllTabs.split( '|' );
		elm1 = document.getElementById( BLOCK_NAME );
		elm1.style.background = "url(" + RootUrl + "themes/default/img/tab_bg_begin.jpg) no-repeat scroll left center";
		for( Index = 0; Index < arr.length; Index++ ) {
			e = document.getElementById( 'tab_' + arr[ Index ] );
			if ( e != null ) {
				e.style.display = "none";
			}
			e1 = document.getElementById( 'menutab_' + arr[ Index ] );
			if ( e1 != null ) {
				color_s = bg_TabGray;

				e1.style.background = bg_TabGray + " url(" + RootUrl + "themes/default/img/tab_bg_center.jpg) no-repeat scroll right center";
			}

		}

		elm1 = document.getElementById( "menutab_" + arr[ arr.length - 1 ] );
		elm1.style.background = bg_TabGray + " url(" + RootUrl + "themes/default/img/tab_bg_end.jpg) no-repeat scroll right center";

		e = document.getElementById( 'tab_' + ShowTab );
		if ( e != null ) {
			e.style.display = "block";

			if ( ShowTab == "newsletter" ) {
				makeRequest( RootUrl + "get_country.php" );
			}

		}


		e1 = document.getElementById( 'menutab_' + ShowTab );
		if ( ShowTab == arr[ arr.length - 1 ] ) {
			e1.style.background = "#7ACB20 url(" + RootUrl + "themes/default/img/tab_bg_end2.jpg) no-repeat scroll right center";
		} else {
			e1.style.background = "#7ACB20 url(" + RootUrl + "themes/default/img/tab_bg_center2.jpg) no-repeat scroll right center";
    }

		ElmIndex = IndexOfValue( arr, ShowTab );
		if ( ElmIndex > 0 ) {
			elm1 = document.getElementById( "menutab_" + arr[ ElmIndex - 1 ] );
			elm1.style.background = bg_TabGray + " url(" + RootUrl + "themes/default/img/tab_bg_center3.jpg) no-repeat scroll right center";

		}
		if ( ElmIndex == 0 ) {
			elm1 = document.getElementById( BLOCK_NAME );
			elm1.style.background = " url(" + RootUrl + "themes/default/img/tab_bg_begin2.jpg) no-repeat scroll left center";
		}


	}


	function select_menupage( menuid ) {
		makeRequest2( RootUrl + "selectmenu.php?selectmenu=" + menuid );
		pause( 200 );
	}

	function makeRequest2(url) {
		var http_request = false;

		if (window.XMLHttpRequest) { // Mozilla, Safari, ...
			http_request = new XMLHttpRequest();
			if (http_request.overrideMimeType) {
				http_request.overrideMimeType('text/xml');
				// Читайте ниже об этой строке
			}
		} else
		if (window.ActiveXObject) { // IE
			try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
			try {
			http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
			}
		}

		if (!http_request) {
			alert('Не вышло  Невозможно создать экземпляр класса XMLHTTP ');
			return false;
		}
		//http_request.onreadystatechange = function() {  };
		http_request.open('GET', url, true);
		http_request.send(null);
	}

	function alertContents(http_request) {
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				alert(http_request.responseText);
			} else {
				alert('С запросом возникла проблема.');
			}
		}
	}


	function pause(ms)
	{
		var date = new Date();
		var curDate = null;
		do { curDate = new Date(); }
		while(curDate-date < ms);
	}


		function UniversalCheckForm( frm, SymCount ) {

			flag = true;

			for( Index = 0; Index <  frm.elements.length; Index++ ) {

				if ( 	( frm.elements[ Index ].type == 'text' ) ||	( frm.elements[ Index ].type == 'textarea' ) ) {

					if ( frm.elements[ Index ].value.length <  SymCount ) {
						//alert( "Fields must be filled in right! Answers must have more than 4 letters! " +  SymCount + " symbols!" );
						flag = false;
						break;
					}

				}
			}

			return flag;

		}


	function checkmail(value) {
		reg = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;
		if (!value.match(reg))
			 return false;
		else
			return true;
	}


	function CheckForm( frm ) {

		flag = checkmail( frm.email.value );

		if ( checkmail ) {
			flag = UniversalCheckForm( frm, 2 );

			if ( !flag )
				alert( "Your must fill all fields!" );

		} else {

			alert( "Your e-mail is incorrect!" );
		}

		return flag;
	}


	///    TICKER

	var theCharacterTimeout = 50;
	var theStoryTimeout     = 5000;
	var theWidgetOne        = "_";
	var theWidgetTwo        = "-";
	var theWidgetNone       = "";
	var theLeadString       = "LATEST:&nbsp;";



	// Ticker startup
	function startTicker()
	{
		// Define run time values
		theCurrentStory     = -1;
		theCurrentLength    = 0;
		// Locate base objects
		if (document.getElementById) {
			theAnchorObject     = document.getElementById("tickerAnchor");
			runTheTicker();
		} else {
      document.write("<style>.ticki{display:none;}.ticko{border:0px; padding:0px;}</style>");
      return true;
		}
	}
	// Ticker main run loop
	function runTheTicker()
	{
		var myTimeout;
		// Go for the next story data block
		if(theCurrentLength == 0)
		{
			theCurrentStory++;
			theCurrentStory      = theCurrentStory % theItemCount;
			theStorySummary      = theSummaries[theCurrentStory].replace(/&quot;/g,'"');
			theTargetLink        = theSiteLinks[theCurrentStory];
			theAnchorObject.href = theTargetLink;
			thePrefix 	     = "<span class=\"tickls\">" + theLeadString + "</span>";
		}
		// Stuff the current ticker text into the anchor
		theAnchorObject.innerHTML = thePrefix +
		theStorySummary.substring(0,theCurrentLength) + whatWidget();
		// Modify the length for the substring and define the timer
		if(theCurrentLength != theStorySummary.length)
		{
			theCurrentLength++;
			myTimeout = theCharacterTimeout;
		}
		else
		{
			theCurrentLength = 0;
			myTimeout = theStoryTimeout;
		}
		// Call up the next cycle of the ticker
		setTimeout("runTheTicker()", myTimeout);
	}
	// Widget generator
	function whatWidget()
	{
		if(theCurrentLength == theStorySummary.length)
		{
			return theWidgetNone;
		}

		if((theCurrentLength % 2) == 1)
		{
			return theWidgetOne;
		}
		else
		{
			return theWidgetTwo;
		}
	}
	//

function Embed(p_id,m_src,m_width,m_height) {
  document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="',m_width,'" height="',m_height,'" id="',p_id,'">\n');
  document.write('<param name="movie" value="',m_src,'" />\n');
  document.write('<param name="quality" value="high" />\n');
  document.write('<param name="settings" value="hide" />\n');
  document.write('<param name="wmode" value="transparent" />\n');
  document.write('<param name="allowFullScreen" value="true" />\n');
  document.write('<embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="',m_width,'" height="',m_height,'" name="',p_id,'" src="',m_src,'" quality="high" settings="hide" allowFullScreen="true" />\n');
  document.write('</object>\n');
}



	function VideoOnLoad(f) {
		var old = window.onload;

		if (typeof old != 'function') window.onload = f
		else { window.onload = function() { old(); f() }}
	}

	function VideoStart() {  // alert( "onload" );
		videofile = "http://monitor.grassrootscoaching.com/Drill_video_1.flv";
    picturefile = 'welcome_frame1.png';

		write_flash( videofile, picturefile, 'videoflash_mod1default', 'videoflash_mod1default|videoflash_drills|videoflash_falevel' );

		//write_flash('', 421, 310, 'transparent', '', 0.1, 'videoflash_mod1default', 'videoflash_mod1default|videoflash_drills|videoflash_falevel' );
	}

	VideoOnLoad( VideoStart );