//Error handler
function silentHandler()  {return true}
window.onerror=silentHandler

var isSafari = '';


var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
var browserName  = navigator.appName;
var fullVersion  = ''+parseFloat(navigator.appVersion);
var majorVersion = parseInt(navigator.appVersion,10);
var nameOffset,verOffset,ix;
var isIE,isIE6,isIE7,isIE8;

// In MSIE, the true version is after "MSIE" in userAgent
if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
 browserName = "Microsoft Internet Explorer";
 fullVersion = nAgt.substring(verOffset+5);
}
// In Opera, the true version is after "Opera"
else if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
 browserName = "Opera";
 fullVersion = nAgt.substring(verOffset+6);
}
// In Chrome, the true version is after "Chrome"
else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
 browserName = "Chrome";
 fullVersion = nAgt.substring(verOffset+7);
}
// In Safari, the true version is after "Safari"
else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
 browserName = "Safari";
 fullVersion = nAgt.substring(verOffset+7);
}
// In Firefox, the true version is after "Firefox"
else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
 browserName = "Firefox";
 fullVersion = nAgt.substring(verOffset+8);
}
// In most other browsers, "name/version" is at the end of userAgent
else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) )
{
 browserName = nAgt.substring(nameOffset,verOffset);
 fullVersion = nAgt.substring(verOffset+1);
 if (browserName.toLowerCase()==browserName.toUpperCase()) {
  browserName = navigator.appName;
 }
}
// trim the fullVersion string at semicolon/space if present
if ((ix=fullVersion.indexOf(";"))!=-1) fullVersion=fullVersion.substring(0,ix);
if ((ix=fullVersion.indexOf(" "))!=-1) fullVersion=fullVersion.substring(0,ix);

majorVersion = parseInt(''+fullVersion,10);
if (isNaN(majorVersion)) {
 fullVersion  = ''+parseFloat(navigator.appVersion);
 majorVersion = parseInt(navigator.appVersion,10);
}
if(navigator.appName == 'Microsoft Internet Explorer')
{
    isIE = true;
}   else {
    isIE = false;
}



function submitSearch()
{
    var frm = document.getElementById("frmSearch");
    frm.submit();

}


function setLanguageLocation(lang_str, loc_str,reloadFlag)
{
   setCookie('languageSelection',lang_str,1000);
   setCookie('locationSelection',loc_str,1000);

   if(reloadFlag)
   {
    window.location.href=window.location.href
   }

}
function getLanguage()
{
    var loc_str = getCookie('locationSelection');
    if(loc_str = "")
    {
        setCookie('languageSelection',"United States",1000);
        loc_str = "United States";
    }

    return loc_str;

}
function getLocation()
{
    var lang_str = getCookie('languageSelection');
    if(lang_str = "")
    {
        setCookie('languageSelection',"en",1000);
        lang_str = "en";
    }

    return lang_str;

}
function setCookie(c_name,value,expiredays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function getCookie(c_name)
{
    if (document.cookie.length>0)
    {
        c_start=document.cookie.indexOf(c_name + "=");
        if (c_start!=-1)
        {
            c_start=c_start + c_name.length+1;
            c_end=document.cookie.indexOf(";",c_start);
            if (c_end==-1) c_end=document.cookie.length;
            return unescape(document.cookie.substring(c_start,c_end));
        }
    }
    return "";
}

function showDialog(id,x,y)

{
    var db = document.getElementById(id);

        db.style.display = "block";

        db.style.top= y + "px";

        db.style.left= x + "px";



}

function hideDialog(id)

{

    var db = document.getElementById(id);

        db.style.display = "none";

}

function toggleDialog(id)

{

    var mousex =   xMousePos ;

    var mousey = yMousePos;

    showDialog(id,mousex,mousey);

}



var mousex = 0;

var mousey = 0;

// Set Netscape up to run the "captureMousePosition" function whenever

// the mouse is moved. For Internet Explorer and Netscape 6, you can capture

// the movement a little easier.

if (document.layers) { // Netscape

    document.captureEvents(Event.MOUSEMOVE);

    document.onmousemove = captureMousePosition;

} else if (document.all) { // Internet Explorer

    document.onmousemove = captureMousePosition;

} else if (document.getElementById) { // Netcsape 6

    document.onmousemove = captureMousePosition;

}



// Global variables

xMousePos = 0; // Horizontal position of the mouse on the screen

yMousePos = 0; // Vertical position of the mouse on the screen

xMousePosMax = 0; // Width of the page

yMousePosMax = 0; // Height of the page



function captureMousePosition(e) {

    if (document.layers) {

        // When the page scrolls in Netscape, the event's mouse position

        // reflects the absolute position on the screen. innerHight/Width

        // is the position from the top/left of the screen that the user is

        // looking at. pageX/YOffset is the amount that the user has

        // scrolled into the page. So the values will be in relation to

        // each other as the total offsets into the page, no matter if

        // the user has scrolled or not.

        xMousePos = e.pageX;

        yMousePos = e.pageY;

        xMousePosMax = window.innerWidth+window.pageXOffset;

        yMousePosMax = window.innerHeight+window.pageYOffset;

    } else if (document.all) {

        // When the page scrolls in IE, the event's mouse position

        // reflects the position from the top/left of the screen the

        // user is looking at. scrollLeft/Top is the amount the user

        // has scrolled into the page. clientWidth/Height is the height/

        // width of the current page the user is looking at. So, to be

        // consistent with Netscape (above), add the scroll offsets to

        // both so we end up with an absolute value on the page, no

        // matter if the user has scrolled or not.

        xMousePos = window.event.x+document.body.scrollLeft;

        yMousePos = window.event.y+document.body.scrollTop;

        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;

        yMousePosMax = document.body.clientHeight+document.body.scrollTop;

    } else if (document.getElementById) {

        // Netscape 6 behaves the same as Netscape 4 in this regard

        xMousePos = e.pageX;

        yMousePos = e.pageY;

        xMousePosMax = window.innerWidth+window.pageXOffset;

        yMousePosMax = window.innerHeight+window.pageYOffset;

    }

}

function popUpWindow(URL,h,w) {
          day = new Date();
          id = day.getTime();
          eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=" + w + ",height=" + h + ",left = 690,top = 375');");
}

function showAllGroups()
{
    var grp = undefined;
    var i = 1;
    for(i = 1; i < 20; i++)
    {
      grp = document.getElementById('group-' + i);

      if(grp != undefined) grp.style.display = 'block';
    }

    /*
    var grp = document.getElementById('overflow-group');
    grp.style.display = 'block';
   */
    var sec = document.getElementById('show-all');
    sec.style.display = 'none';

    var sec2 = document.getElementById('hide-most');
    sec2.style.display = 'block';


}
function collapseGroups()
{

 var grp = undefined;
    var i = 2;
    for(i = 2; i < 20; i++)
    {
      grp = document.getElementById('group-' + i);
      if(grp != undefined) grp.style.display = 'none';

    }

    /*
    var grp = document.getElementById('overflow-group');
    grp.style.display = 'none';
    */

    var sec = document.getElementById('show-all');
    sec.style.display = 'block';

    var sec2 = document.getElementById('hide-most');
    sec2.style.display = 'none';


}




var curId = undefined;
function showItem()
{

    var item = document.getElementById(curId);
    item.style.display = "block";

}

function hideTab(id)
{
    var item = document.getElementById(id);
    item.style.display = "none";
}
function hideTab(id,tabNum)
{

    var item = document.getElementById(id);

    //tabNum = tabNum + 4;
    var tab = document.getElementById("stUI" + tabNum);
        if(item == undefined)
        {
            //It does not exist so do nothing

            //Hide the tab
            if(tab == undefined)
            {
                //The tab does not exist - why?
            } else {
   //             tab.style.display = "none";
            }

        } else {
            item.style.display = "none";

            //Show the tab
            if(tab == undefined)
            {
                //The tab does not exist - why?
            } else {
              //  tab.style.display = "block";
            }
        }


}


//--------------------------------------------------------
var requiredField_array = new Array();
var style_obj = new class_style_obj();
var requiredField_array = new Array();

function class_style_obj()
{
	this.required = new Object();
	this.failed = new Object();
	this.normal = new Object();
	this.passed = new Object();

}

function setStyle(p_status, p_border_width, p_border_color)
{
         style_obj[p_status].border_width =  p_border_width;
         style_obj[p_status].border_color =  p_border_color;

}
function setStyle(p_status, p_border_width, p_border_color)
{
         style_obj[p_status].border_width =  p_border_width;
         style_obj[p_status].border_color =  p_border_color;

}

function applyStyle(p_status, p_fieldName)
{
	var fld = document.forms[0][p_fieldName] ;
	var color =    style_obj[p_status].border_color;
	var width =    style_obj[p_status].border_width;

	fld.style.backgroundColor  = "#" + color;
	//fld.style.border  = width + "px solid #" + color;
}
function applyStyleByForm(frm,p_status, p_fieldName)
{
	var fld = frm[p_fieldName] ;
	var color =    style_obj[p_status].border_color;
	var width =    style_obj[p_status].border_width;
   // alert('form: ' + frm + '    p_fieldName: ' + p_fieldName);


	fld.style.backgroundColor  = "#" + color;
	//fld.style.border  = width + "px solid #" + color;
}

function addRequiredField(p_form, p_fieldName, p_prompt)
{
	var temp_obj        = new Object();
	temp_obj.form       = p_form;
	temp_obj.fieldName  = p_fieldName;
	temp_obj.prompt     = p_prompt;
	requiredField_array.push(temp_obj);

	applyStyleByForm(p_form,"required", p_fieldName)
}

function submitForm(form)
{
	if(checkFields(form))
	{
		form.submit();
	}
}



function checkFields(form)
{

    var i = 0;
    var msg_str	,failFlag, cr,tb
    cr = '\n';
    tb = '\t';
     msg_str = '' ;
	failFlag = false;
	var focusFieldName = "";
    //alert('here');
    for(i = 0; i <  requiredField_array.length; i ++)
    {

    	var temp_obj

    	temp_obj = requiredField_array[i];
        //alert(i + ' ' + temp_obj);

    	var fld = requiredField_array[i].form[requiredField_array[i].fieldName];
    	if(fld.value == undefined || fld.value == "")
    	{
			if(focusFieldName == "")
			{
				focusFieldName = 	 requiredField_array[i].fieldName;
			}
    		msg_str = msg_str + tb + requiredField_array[i].prompt + cr + cr;
			applyStyleByForm(form,"failed", requiredField_array[i].fieldName)
    		failFlag = true;
    	}	 else	{

    		//alert(fld.name + ": " + fld.value);
			applyStyleByForm(form,"passed", requiredField_array[i].fieldName)
    	}
    }
    if (failFlag)
    {
		form[focusFieldName].focus();
    	alert("One or more required fields must be completed:" + cr + cr + msg_str)
    	return false;
    } else {
    	return true;
    }
}







