///////////////////////////////////////////////////////////////////////////////
// Client - Patoka Registartion
// Developer - Sachin Gupta - Netsol 297
// Copyright © Net Solutions 2009. All rights reserved.
///////////////////////////////////////////////////////////////////////////////

var activeSub=0;
var SubNum=0;

function reDo()
{ 
    window.location.reload() 
}
//don't know why need this code?
//window.onresize = reDo;


//Define global variables

var timerID = null;
var timerOn = false;
var timecount = 1000;
var what = null;
var newbrowser = true;
var check = false;

function init()
{
    if (document.layers)
    {
        layerRef="document.layers";
        styleSwitch="";
        visibleVar="show";
		screenSize = window.innerWidth;
		what ="ns4";
    }
    else if(document.all)
    {
        layerRef="document.all";
        styleSwitch=".style";
        visibleVar="visible";
		screenSize = document.body.clientWidth + 18;
		what ="ie";
    }
    else if(document.getElementById)
    {
        layerRef="document.getElementByID";
        styleSwitch=".style";
        visibleVar="visible";
		what="moz";
	}
	else
	{
	    what="none";
		newbrowser = false;
	}
	window.status='status bar text to go here';
	check = true;
}

function showLayer(id) 
{
    var lyr = getElemRefs(id);
    if (lyr && lyr.css) 
        lyr.css.visibility = "visible";
}

function hideLayer(id) 
{
    var lyr = getElemRefs(id);
    if (lyr && lyr.css) 
        lyr.css.visibility = "hidden";
}

// Turns the layers on and off
function showLayer(layerName)
{
	if(check)
	{
		if (what =="none")
		{
			return;
		}
    	else if (what == "moz")
    	{
			document.getElementById(layerName).style.visibility="visible";
		}
		else
		{
            eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="visible"');
        }
    }
	else 
	{
		return;
    }
}

function hideLayer1(layerName)
{
    if(check)
	{
		if (what =="none")
		{
			return;
		}
		else if (what == "moz")
		{
			document.getElementById(layerName).style.visibility="hidden";
		}
		else
		{
            eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"');
		}

	}
	else 
	{
		return;
	}
}

function hideAll()
{
   
    hideLayer('layer1');
    hideLayer('layer2');
    hideLayer('layer3');
    hideLayer('layer4');
    hideLayer('layer5');
    hideLayer('layer6');
	
    hideLayer('traceability_layer1');
    hideLayer('traceability_layer2');
    hideLayer('traceability_layer3');
    hideLayer('traceability_layer4');
    hideLayer('traceability_layer5');
    hideLayer('traceability_layer6');

}

function startTime() 
{  
    if (timerOn == false) 
    {
        timerID=setTimeout( "hideAll()" , timecount);
        timerOn = true;
    }
}

function stopTime() 
{
    if (timerOn) 
    {
        clearTimeout(timerID);
        timerID = null;
        timerOn = false;
    }
}

function onLoad()
{
	init();
}

// Enter only float values in textbox	
function checkNaN(txt,e)
{
    var evt=(e)?e:(window.event)?window.event:null;
    if(evt)
    { 
        var key=(evt.charCode)?evt.charCode: ((evt.keyCode)?evt.keyCode:((evt.which)?evt.which:0)); 
        if(key!="8")
        {
            var str=txt;	
            if (!IsNumericPrice(str.value))			
	            str.value="0";
        } 
    }
}

//  check for valid numeric strings	
function IsNumericPrice(strString)
{
    var strValidChars = ".0123456789";
    var strChar;
    var blnResult = true;

    if (strString.length == 0) return false;

    for (i = 0; i < strString.length && blnResult == true; i++)
    {
    strChar = strString.charAt(i);
    if (strValidChars.indexOf(strChar) == -1)
	    {
		    blnResult = false;
	    }
    }
    return blnResult;
}

// Enter only float values in textbox	
function checkNaNBlank(txt,e)
{
    var evt=(e)?e:(window.event)?window.event:null;
    if(evt)
    { 
        var key=(evt.charCode)?evt.charCode: ((evt.keyCode)?evt.keyCode:((evt.which)?evt.which:0)); 
        if(key!="8")
        {
            var str=txt;	
            if (!IsNumericPrice(str.value))			
            {
                if(str.value.indexOf(',')!=-1)
                    str.value=str.value.replace(',','.');
                else
	                str.value='';
	        }
        }
    }
}

function checkNaN(event)
 {
    var charCode= event.keyCode ? event.keyCode : event.which;
    
    if(charCode==37)
    {
        if(navigator.appName.indexOf('Netscape')!=-1)
        {
            if(event.shiftKey)
                return false;
        }
        else
            return false;
    }
    if(charCode==37 || charCode==39)
        return true;
        
    if(charCode==46)
        return true;
    
    if (charCode > 31 && (charCode < 48 || charCode > 57))
    {
        return false;
    }
    return true;
}

function checkNaN(evt)
{ 
    var charCode= evt.charCode;
    var keyCode=evt.keyCode;
    
    if(typeof(charCode)!='undefined')
    {
        if(keyCode!=0)
        {
            return true; 
        } 
        if(charCode==46 || charCode==44)
            return true;
        if ((charCode < 48 || charCode > 57))
        {
            return false;
        }
        return true;
    }
    else
    {
        if(keyCode==46)
            return true;
        if ((keyCode < 48 || keyCode > 57))
        {
            return false;
        }
        else
            return true;
    }
}

function getElemRefs(id) 
{
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? getLyrRef(id,document): null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}

function MouseOverMenu(type)
{
    init();
    hideAll();
    showLayer('layer'+ type);
    stopTime();
    return fhover(true,type);
}

function MouseOutMenu(type)
{
    startTime();
    return fhover(false,type);
}

function MouseOverMenuWithOutSubMenu(type)
{
    hideAll();
    return fhover(true,type);
}

function MouseOutMenuWithOutSubMenu(type)
{
    startTime();
    return fhover(false,type);
}

function wopen(url, name, w, h)
{
  // Fudge factors for window decoration space.
  // In my tests these work well on all platforms & browsers.
  w += 32;
  h += 96;
  wleft = (screen.width - w) / 2;
  wtop = (screen.height - h) / 2;
  // IE5 and other old browsers might allow a window that is
  // partially offscreen or wider than the screen. Fix that.
  // (Newer browsers fix this for us, but let's be thorough.)
  if (wleft < 0) {
    w = screen.width;
    wleft = 0;
  }
  if (wtop < 0) {
    h = screen.height;
    wtop = 0;
  }
  var win = window.open(url,
    name,
    'width=' + w + ', height=' + h + ', ' +
    'left=' + wleft + ', top=' + wtop + ', ' +
    'location=no, menubar=no, ' +
    'status=no, toolbar=no, scrollbars=yes, resizable=no');
  // Just in case width and height are ignored
  win.resizeTo(w, h);
  // Just in case left and top are ignored
  win.moveTo(wleft, wtop);
  win.focus();
}

/**************************************************************************/
// SET GO TO TOP BUTTON VISIBILITY AND BROWSER MINIMUM HEIGHT
/**************************************************************************/
//function WindowResize() 
//{
//    var height;
//    if (self.innerHeight) // all except Explorer
//    {
//        height = self.innerHeight;
//    }
//    else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
//    {
//        height = document.documentElement.clientHeight;
//    }
//    else if (document.body) // other Explorers
//    {
//        height = document.body.clientHeight;
//    }    
//    if (document.body.scrollHeight <= height) 
//    {
//        document.getElementById("ContentTableId").style.height="550px";
//        document.getElementById("GotoTop").style.display = "none";
//    }
//    else 
//    {
//        document.getElementById("GotoTop").style.display = "";
//    }
//}
//WindowResize();
//window.onresize = WindowResize;   




 // helper functions
function f_clientWidth() 
{
    return f_filterResults 
    (
        window.innerWidth ? window.innerWidth : 0,
        document.documentElement ? document.documentElement.clientWidth : 0,
        document.body ? document.body.clientWidth : 0
    );
}

function f_clientHeight() 
{
    return f_filterResults 
    (
        window.innerHeight ? window.innerHeight : 0,
        document.documentElement ? document.documentElement.clientHeight : 0,
        document.body ? document.body.clientHeight : 0
    );
}

function f_scrollLeft() 
{
    return f_filterResults 
    (
        window.pageXOffset ? window.pageXOffset : 0,
        document.documentElement ? document.documentElement.scrollLeft : 0,
        document.body ? document.body.scrollLeft : 0
    );
}

function f_scrollTop() 
{
    return f_filterResults 
    (
        window.pageYOffset ? window.pageYOffset : 0,
        document.documentElement ? document.documentElement.scrollTop : 0,
        document.body ? document.body.scrollTop : 0
    );
}

function f_filterResults(n_win, n_docel, n_body) 
{
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

// get doc width
var docwidth = f_clientWidth();

// then use some code to check if docwidth is ok
/*if (<docwidth is not ok>)
{
    window.location = 'other_location.html';
}*/
/**************************************************************************/
