// JavaScript Document
//------------------------------ Search Form Function ------------------------------//
function checkValid() {
	if(document.formsearch.CiRestriction.value == ''){
		alert("Please type your keywords.");
		return false;
	}
	var reg2 = /[,|~|{|[|}|!|#|$|%|^|*|(|)|=|<|>|?|'|;|||]/;	
	 
	if ( reg2.test(document.formsearch.CiRestriction.value)){
		alert("Non alphanumeric characters are not allowed.");
		return false;	
	 }
    var str = document.formsearch.CiRestriction.value;
 
	 if  (str.indexOf(']')> -1){
		alert("Non alphanumeric characters are not allowed.");
		return false;
	}	
	if  (str.indexOf('\\')> -1){
		alert("Non alphanumeric characters are not allowed.");
		return false;
	}		
	if  (str.indexOf('\/')> -1){
		alert("Non alphanumeric characters are not allowed.");
		return false;
	}
	if  (str.indexOf(' ')== 0){
		alert("A space is not allowed as the first character.");
		return false;
	}	
	if  (str.indexOf(' ')== 1 &&  str.indexOf(' ',2)== 3){
		alert("A search string can not contain that many single chacters in a row.");
		return false;
	}				
	if (str.length == 3 && str.indexOf(' ')== 1){
		alert("Not enough valid alphanumeric characters to search on.");
		return false;
	}			
	if  (str.indexOf('__')> -1){
		alert("Non alphanumeric characters are not allowed.");
		return false;
	}	
	if (str.length==3 && str.indexOf('_')== 0 && str.lastIndexOf('_')== 2  ){
		alert("You search string must contain at least three alphanumeric characters.");
		return false;
	}		
	if (str.length<3){
		alert("You search string must contain at least three alphanumeric characters.");
		return false;
		}else{
		openNewWindow('/query_dev.idq?CiRestriction=' + document.getElementById("CiRestriction").value + '','Search','500','500');
		return true;
	}
}

//------------------------------- Starts: MENU SYSTEM ------------------------------------//	
var menuTimer=0;

function setTimer() {
	menuTimer=setTimeout("hideAll()",500);
}

function clrTimer() {
	clearTimeout(menuTimer);
}
function hideAll() { 
	hideLayer('dd1','dd2','dd3','dd4','dd5','dd6','dd7','sdd0'); 
	clrTimer();
}	
function showLayer() {
	hideAll();
	var n=showLayer.arguments.length; 
	for (var i=0; i<n; i++) { 
		if (document.getElementById(showLayer.arguments[i])) 
		{	
			var lyr = document.getElementById(showLayer.arguments[i]).style;
			if(lyr) { 
				lyr.visibility="visible";
			}
		} 
	} 
} 
function hideLayer() { 
	var n=hideLayer.arguments.length; 
	for (var i=0; i<n; i++) { 
		if (document.getElementById(hideLayer.arguments[i])) 
		{
			var lyr = document.getElementById(hideLayer.arguments[i]).style; 
			if(lyr) { 
				lyr.visibility = "hidden";
			} 
		}
	} 
}

function buildSubmenus(){
	var myText = "";
	myText += "<div id=\"dropdowns\">";
//Submenu 1
	myText += "<div id=\"dd1\"><ul>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Legislation/DGMS/\">DGMS</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Legislation/IBM/\">IBM</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Legislation/Environment/\">Environment</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Legislation/Forest/\">Forest</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Legislation/Explosive/\">Explosive</a></li>";
    myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Legislation/Electricity/\">Electricity</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Legislation/Labour/\">Labour</a></li>";
    myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Legislation/Miscellaneous/\">Miscellaneous</a></li>";
	myText += "</ul></div>";
//Submenu 2
	myText += "<div id=\"dd2\"><ul>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Mining_Database/State_Wise_Data/\">State Wise Data</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Mining_Database/Mineral_Wise_Data/\">Mineral Wise Data</a></li>";
	myText += "</ul></div>";
//Submneu3
	myText += "<div id=\"dd3\"><ul>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Examinations/Restricted/\">First Class (R) Questions</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Examinations/Restricted/\">First Class (R) Model Q&amp;A</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Examinations/Unrestricted/\">First Class (UR) Questions</a></li>"; 
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Examinations/Unrestricted/\">First Class (UR) Model Q&amp;A</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Examinations/Accident_Analysis/\">Accident Analysis</a></li>";
	myText += "</ul></div>";
//Submenu4
	myText += "<div id=\"dd4\"><ul>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Form_Return_Schedules/DGMS/\">DGMS</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Form_Return_Schedules/IBM/\">IBM</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Form_Return_Schedules/Environment/\">Environment</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Form_Return_Schedules/Forest/\">Forest</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Form_Return_Schedules/Explosive/\">Explosive</a></li>";
    myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Form_Return_Schedules/Electricity/\">Electricity</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Form_Return_Schedules/Labour/\">Labour</a></li>";
    myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Form_Return_Schedules/Miscellaneous/\">Miscellaneous</a></li>";
	myText += "</ul></div>";
//Submenu5
	myText += "<div id=\"dd5\"><ul>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Guidelines/Environmental_Clearance/\">Environmental Clearance</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Guidelines/Environmental_Laws/\">Regarding Environmental Laws</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Guidelines/Forest_Laws/\">Regarding Forest Laws</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Guidelines/Mining_Plans/\">Mining Plan, Mining Scheme & Mine Closure Plan</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Guidelines/Return_Submission/\">Return Submission to IBM</a></li>";
	myText += "</ul></div>";
//Submenu6
	myText += "<div id=\"dd6\"><ul>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Mining_Machinery/Indian_Industry/\">Overview of Indian Industry</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Mining_Machinery/HEMM/\">Heavy Earth Moving Machineries</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Mining_Machinery/Machineries_Selection/\">Machineries Selection</a></li>";
	myText += "</ul></div>";
//Submenu7
	myText += "<div id=\"dd7\"><ul>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Mineral_Processing/Crusher_Grinder/\">Crusher &amp; Grinder</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Mineral_Processing/Screen/\">Screen</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Mineral_Processing/Conveyor_Belt/\">Conveyor Belt</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Mineral_Processing/Classifier/\">Classifier</a></li>";	
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Mineral_Processing/Cyclone/\">Cyclone</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Mineral_Processing/Thickener/\">Thickener</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Mineral_Processing/Feeder/\">Feeder</a></li>";
	myText += "<li><a onmouseover=\"clrTimer()\" onmouseout=\"setTimer()\" href=\"/Mineral_Processing/Miscellaneous/\">Miscellaneous</a></li>";	
	myText += "</ul></div>";
	myText += "</div>";
	document.write(myText);
}

function buildNav(){
	var nav = "";
nav += "<table width=\"932\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"menuText\"><tr>";
nav += "      <td width=\"5\"><img src=\"/images/mainMenuLeftCol.gif\" width=\"5\" height=\"25\"></td>";
nav += "      <td width=\"94\" align=\"center\" valign=\"middle\" background=\"/images/mainMenuBg.gif\"><a href=\"" + strBaseUrl + "/Legislation/\" onmouseover=\"clrTimer();showLayer('dd1')\" onmouseout=\"setTimer()\"> Legislation</a></td>";
nav += "      <td width=\"2\"><img src=\"/images/mainMenuDivider.gif\" width=\"2\" height=\"25\"></td>";
nav += "      <td width=\"136\" align=\"center\" valign=\"middle\" background=\"/images/mainMenuBg.gif\"><a href=\"" + strBaseUrl + "/Mining_Database/\" onmouseover=\"clrTimer();showLayer('dd2')\" onmouseout=\"setTimer()\">Mining Database</a></td>";
nav += "      <td width=\"2\"><img src=\"/images/mainMenuDivider.gif\" width=\"2\" height=\"25\"></td>";
nav += "      <td width=\"112\" align=\"center\" valign=\"middle\" background=\"/images/mainMenuBg.gif\"><a href=\"" + strBaseUrl + "/Examinations/\" onmouseover=\"clrTimer();showLayer('dd3')\" onmouseout=\"setTimer()\">Examinations</a></td>";
nav += "      <td width=\"2\"><img src=\"/images/mainMenuDivider.gif\" width=\"2\" height=\"25\"></td>";
nav += "      <td width=\"194\" align=\"center\" valign=\"middle\" background=\"/images/mainMenuBg.gif\"><a href=\"" + strBaseUrl + "/Form_Return_Schedules/\" onmouseover=\"clrTimer();showLayer('dd4')\" onmouseout=\"setTimer()\">Form Return Schedules</a></td>";
nav += "      <td width=\"2\"><img src=\"/images/mainMenuDivider.gif\" width=\"2\" height=\"25\"></td>";
nav += "      <td width=\"92\" align=\"center\" valign=\"middle\" background=\"/images/mainMenuBg.gif\"><a href=\"" + strBaseUrl + "/Guidelines/\" onmouseover=\"clrTimer();showLayer('dd5')\" onmouseout=\"setTimer()\">Guidelines</a></td>";
nav += "      <td width=\"2\"><img src=\"/images/mainMenuDivider.gif\" width=\"2\" height=\"25\"></td>";
nav += "      <td width=\"140\" align=\"center\" valign=\"middle\" background=\"/images/mainMenuBg.gif\"><a href=\"" + strBaseUrl + "/Mining_Machinery/\" onmouseover=\"clrTimer();showLayer('dd6')\" onmouseout=\"setTimer()\">Mining Machinery</a></td>";
nav += "      <td width=\"2\"><img src=\"/images/mainMenuDivider.gif\" width=\"2\" height=\"25\"></td>";
nav += "      <td width=\"142\" align=\"center\" valign=\"middle\" background=\"/images/mainMenuBg.gif\"><a href=\"" + strBaseUrl + "/Mineral_Processing/\" onmouseover=\"clrTimer();showLayer('dd7')\" onmouseout=\"setTimer()\">Mineral Processing</a></td>";
nav += "      <td width=\"5\"><img src=\"/images/mainMenuRightCol.gif\" width=\"5\" height=\"25\"></td>";
nav += "    </tr></table>";
document.write (nav)
}
//------------------------------- Ends: MENU SYSTEM ------------------------------------//	


/*************************** Starts: Tab Switching *********************************************/
var undef;
function switchTab(tabToShow){
	//Find li of pressed tab 
	var ulArray = document.getElementsByTagName('ul');
	for (var i=0; i<ulArray.length; i++) {
		if(ulArray[i].className == 'tabs clearfix'){
			var liArray = ulArray[i].getElementsByTagName('li');
			for(t=0; t<liArray.length; t++){
				var activeIndex = liArray[t].className.indexOf('_a');
				if(t == (parseInt(tabToShow))-1){
					if (activeIndex != -1) {
						continue;
					} else {
						liArray[t].className = liArray[t].className+"_a";
					}
				} else {
					if (activeIndex != -1) {
						liArray[t].className = liArray[t].className.substring(0,activeIndex);
					}
				}
			}
		}		
	}
	var layername = "tabWeCanToggle" + tabToShow;
	//Count Number of Tabs
	var numerOfTabs = 0;
	for (var loop = 0; loop < document.getElementsByTagName('div').length; loop++) {
	var DivIdName = "document.getElementsByTagName('DIV')[" + loop + "].id";
		if (eval(DivIdName) && eval(DivIdName).indexOf('tabWeCanToggle') != -1){
		numerOfTabs++
		}
	}
	//Make Visible/Invisible
	for (var loop=1; loop <= numerOfTabs; loop++) {
	var currentTabId = 'tabWeCanToggle' + loop;
	var currentTabDisplay = "document.getElementById('" + currentTabId + "').style.display";
		if (loop == tabToShow) {
			eval(currentTabDisplay + " = 'block'");
		} else {
			eval(currentTabDisplay + " = 'none'");
		}
	}
}
/*************************** Ends: Tab Switching *********************************************/


/*************************** Starts: Tabber *********************************************/
/*==================================================
  $Id: tabber.js,v 1.9 2006/04/27 20:51:51 pat Exp $
  tabber.js by Patrick Fitzgerald pat@barelyfitz.com

  Documentation can be found at the following URL:
  http://www.barelyfitz.com/projects/tabber/

  License (http://www.opensource.org/licenses/mit-license.php)

  Copyright (c) 2006 Patrick Fitzgerald

  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation files
  (the "Software"), to deal in the Software without restriction,
  including without limitation the rights to use, copy, modify, merge,
  publish, distribute, sublicense, and/or sell copies of the Software,
  and to permit persons to whom the Software is furnished to do so,
  subject to the following conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.
  ==================================================*/

function tabberObj(argsObj)
{
  var arg;
  this.div = null;
  this.classMain = "tabber";
  this.classMainLive = "tabberlive";
  this.classTab = "tabbertab";
  this.classTabDefault = "tabbertabdefault";
  this.classNav = "tabbernav";
  this.classTabHide = "tabbertabhide";
  this.classNavActive = "tabberactive";
  this.titleElements = ['h2','h3','h4','h5','h6'];
  this.titleElementsStripHTML = true;
  this.removeTitle = true;
  this.addLinkId = false;
  this.linkIdFormat = '<tabberid>nav<tabnumberone>';
  for (arg in argsObj) { this[arg] = argsObj[arg]; }
  this.REclassMain = new RegExp('\\b' + this.classMain + '\\b', 'gi');
  this.REclassMainLive = new RegExp('\\b' + this.classMainLive + '\\b', 'gi');
  this.REclassTab = new RegExp('\\b' + this.classTab + '\\b', 'gi');
  this.REclassTabDefault = new RegExp('\\b' + this.classTabDefault + '\\b', 'gi');
  this.REclassTabHide = new RegExp('\\b' + this.classTabHide + '\\b', 'gi');
  this.tabs = new Array();
  if (this.div) {
    this.init(this.div);
    this.div = null;
  }
}

/*--------------------------------------------------
  Methods for tabberObj
  --------------------------------------------------*/

tabberObj.prototype.init = function(e)
{
  var childNodes, i, i2, t, defaultTab=0, DOM_ul, DOM_li, DOM_a, aId, headingElement;
  if (!document.getElementsByTagName) { return false; }
  if (e.id) {this.id = e.id;}
  this.tabs.length = 0;

  childNodes = e.childNodes;
  for(i=0; i < childNodes.length; i++) {

    if(childNodes[i].className &&
       childNodes[i].className.match(this.REclassTab)) {
      t = new Object();
      t.div = childNodes[i];
      this.tabs[this.tabs.length] = t;
      if (childNodes[i].className.match(this.REclassTabDefault)) {
	defaultTab = this.tabs.length-1;
      }
    }
  }

  DOM_ul = document.createElement("ul");
  DOM_ul.className = this.classNav;
  
  for (i=0; i < this.tabs.length; i++) {
    t = this.tabs[i];
    t.headingText = t.div.title;
    if (this.removeTitle) { t.div.title = ''; }
    if (!t.headingText) {
      for (i2=0; i2<this.titleElements.length; i2++) {
	headingElement = t.div.getElementsByTagName(this.titleElements[i2])[0];
	if (headingElement) {
	  t.headingText = headingElement.innerHTML;
	  if (this.titleElementsStripHTML) {
	    t.headingText.replace(/<br>/gi," ");
	    t.headingText = t.headingText.replace(/<[^>]+>/g,"");
	  }
	  break;
	}
      }
    }

    if (!t.headingText) {t.headingText = i + 1;}
    DOM_li = document.createElement("li");
    t.li = DOM_li;
    DOM_a = document.createElement("a");
    DOM_a.appendChild(document.createTextNode(t.headingText));
    DOM_a.href = "javascript:void(null);";
    DOM_a.title = t.headingText;
    DOM_a.onclick = this.navClick;
    DOM_a.tabber = this;
    DOM_a.tabberIndex = i;
    if (this.addLinkId && this.linkIdFormat) {
      aId = this.linkIdFormat;
      aId = aId.replace(/<tabberid>/gi, this.id);
      aId = aId.replace(/<tabnumberzero>/gi, i);
      aId = aId.replace(/<tabnumberone>/gi, i+1);
      aId = aId.replace(/<tabtitle>/gi, t.headingText.replace(/[^a-zA-Z0-9\-]/gi, ''));
      DOM_a.id = aId;
    }
    DOM_li.appendChild(DOM_a);
    DOM_ul.appendChild(DOM_li);
  }
  e.insertBefore(DOM_ul, e.firstChild);
  e.className = e.className.replace(this.REclassMain, this.classMainLive);
  this.tabShow(defaultTab);
  if (typeof this.onLoad == 'function') {this.onLoad({tabber:this});}
  return this;
};

tabberObj.prototype.navClick = function(event)
{
  var rVal, a, self, tabberIndex, onClickArgs; a = this;
  if (!a.tabber) { return false; }
  self = a.tabber;
  tabberIndex = a.tabberIndex;
  a.blur();
  if (typeof self.onClick == 'function') {
    onClickArgs = {'tabber':self, 'index':tabberIndex, 'event':event};
    if (!event) { onClickArgs.event = window.event; } rVal = self.onClick(onClickArgs);
    if (rVal === false) { return false; }
  }
  self.tabShow(tabberIndex);
  return false;
};

tabberObj.prototype.tabHideAll = function()
{
  var i;
  for (i = 0; i < this.tabs.length; i++) {this.tabHide(i);}
};

tabberObj.prototype.tabHide = function(tabberIndex)
{
  var div;
  if (!this.tabs[tabberIndex]) { return false; }
  div = this.tabs[tabberIndex].div;
  if (!div.className.match(this.REclassTabHide)) {div.className += ' ' + this.classTabHide;}
  this.navClearActive(tabberIndex);
  return this;
};

tabberObj.prototype.tabShow = function(tabberIndex)
{
  var div;
  if (!this.tabs[tabberIndex]) { return false; }
  this.tabHideAll();
  div = this.tabs[tabberIndex].div;
  div.className = div.className.replace(this.REclassTabHide, '');
  this.navSetActive(tabberIndex);
  if (typeof this.onTabDisplay == 'function') {this.onTabDisplay({'tabber':this, 'index':tabberIndex});}
  return this;
};
tabberObj.prototype.navSetActive = function(tabberIndex)
{this.tabs[tabberIndex].li.className = this.classNavActive;return this;};
tabberObj.prototype.navClearActive = function(tabberIndex)
{this.tabs[tabberIndex].li.className = '';return this;};

/*==================================================*/

function tabberAutomatic(tabberArgs)
{
  var tempObj,divs,i;
  if (!tabberArgs) { tabberArgs = {}; }
  tempObj = new tabberObj(tabberArgs);
  divs = document.getElementsByTagName("div");
  for (i=0; i < divs.length; i++) {if (divs[i].className && divs[i].className.match(tempObj.REclassMain)) {tabberArgs.div = divs[i];divs[i].tabber = new tabberObj(tabberArgs);}}
  return this;
}
/*==================================================*/

function tabberAutomaticOnLoad(tabberArgs)
{ var oldOnLoad;
  if (!tabberArgs) { tabberArgs = {}; }
  oldOnLoad = window.onload;
  if (typeof window.onload != 'function') {window.onload = function() {tabberAutomatic(tabberArgs);};} else {window.onload = function() {oldOnLoad();tabberAutomatic(tabberArgs);};}
}
if (typeof tabberOptions == 'undefined') {tabberAutomaticOnLoad();} else {if (!tabberOptions['manualStartup']) {tabberAutomaticOnLoad(tabberOptions);}}

/*************************** Ends: Tabber *********************************************/

