﻿var HTTPPOSTDONE = "HTTPPOSTDONE";
var httpRequest;
var httpRequestContainer;
var httpRequestSource;
var HttpPostDocument;
var httpPostResult;
var d = new Date();
var ID = d.getDate()+""+d.getMonth() + 1+""+d.getFullYear()+""+d.getHours()+""+d.getMinutes()+""+d.getSeconds();

function openPopupModal(page, caption, width, height)
{
        var browser=navigator.appName;
        var b_version=navigator.appVersion;
        var version=parseFloat(b_version);
        
        if(browser=="Netscape")
        {
             var left = (screen.width-width)/2;
		        var top = (screen.height-height)/2;
 		        winHandle = window.open(page, ID, "modal,toolbar=false,location=false,directories=false,status=false,menubar=false,scrollbars=no,resizable=no,left="+left+",top="+top+",width="+width+",height="+height);
		        winHandle.focus();
		   
        }
        else
	    {	    
	        if (window.showModalDialog)
            {
                var left = (screen.availWidth - width)/2;
                var top = (screen.availHeight - height)/2;
	            var dialogArguments = new Object();
	            var _R = window.showModalDialog(page, dialogArguments, "dialogWidth=" + width + "px;dialogHeight=" + height + "px;scroll=no;status=no;");
	            return _R;
            }
	    }
	
}
function showEquipment(pid)
        {
          var image=document.getElementById("ctl00_cpMain_imgEquPhoto");
          if(pid!='')
          {
              image.style.visibility='visible';
              image.src="uploadedimages\\equipment\\thumb\\"+ pid + ".jpg";
          }
          else
          {
            image.style.visibility='hidden';
          }
            
        }
function rtclickcheck(event, msg)
{ 
    var button;
    if (event.which == null)
    {
        if(event.button == 2)
        {
            alert(msg);
            return false;
        }
    }
    else
    {
        if(event.which == 3)
        {
            alert(msg);
            return false;
        }
    }
} 
function openPopupModalP(page, caption, width, height)
{
	if (window.showModalDialog)
	{
	    var left = (screen.availWidth - width)/2;
	    var top = (screen.availHeight - height)/2;
		var dialogArguments = new Object();
		var _R = window.showModalDialog(page, dialogArguments, "dialogWidth=" + width + "px;dialogHeight=" + height + "px;scroll=no;status=no;");
		__doPostBack('complaint','1');
		return false;
	}		
	else	//NS			
	{  	
		var left = (screen.width-width)/2;
		var top = (screen.height-height)/2;
 		winHandle = window.open(page, ID, "modal,toolbar=false,location=false,directories=false,status=false,menubar=false,scrollbars=no,resizable=no,left="+left+",top="+top+",width="+width+",height="+height);
		winHandle.focus();
		
	}
}

function openPopup(url, name, w, h)
{
  // Fudge factors for window decoration space.
  // In my tests these work well on all platforms & browsers.
  w += 32;
  h += 132;
  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=no, 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();
}

function DoBlur(fld) 
{
    fld.className='normalfld';
}

function DoFocus(fld) 
{
  
    fld.className='focusfld';
}
function DoBlurt(fld) 
{
    fld.className='textarea';
}

function DoFocust(fld) 
{
  
    fld.className='textareaNormal';
}
function DoBlurdrp(fld) 
{   
    fld.className='drpNormal';
    //fld.click();
    return true;
}

function DoFocusdrp(fld) 
{
    fld.className='drpFocus';
    //fld.click();
    return true;
}
function DoBlurp(fld) 
{
    fld.className='passNormal';
}

function DoFocusp(fld) 
{
  
    fld.className='passFocus';
}
function DoBlurc(fld) 
{
 
    fld.className='checkboxNormal';
}

function DoFocusc(fld) 
{
 
    fld.className='checkboxFocus';
}
function getTopPos(inputObj)
{
  var returnValue = inputObj.offsetTop + inputObj.offsetHeight;
  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop;
  return returnValue;
}

function getLeftPos(inputObj)
{
  var returnValue = inputObj.offsetLeft;
  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
  return returnValue;
}

function SetFocus(ClientID)
{
    document.getElementById(ClientID).focus();
    window.scrollBy(0,-20); 
}


function newHttp()
{
	if (window.ActiveXObject)
	{		
		return new ActiveXObject("Microsoft.XMLHTTP");	
	}	
	else
	{		
		return new XMLHttpRequest;	
	}
}

function getResponseHttp(url, container, trigger)
{	

	httpRequestContainer = container;

	httpRequest = newHttp();
	httpRequest.onreadystatechange = stateChangeHttp;

	httpRequest.open("GET", url, true);	
	httpRequest.send(null);
}

function readyStateText(readyState)
{
/*
	readyState
	0 = uninitialized
	1 = loading
	2 = loaded
	3 = interactive
	4 = complete

	status
	200 - page Ok
	404 - page Not found

	statusText
	status explanation returned
*/	
	var text = '';
	switch (readyState)
	{
		case 0 : text = 'uninitialized'; break;
		case 1 : text = 'loading'; break;
		case 2 : text = 'loaded'; break;
		case 3 : text = 'interactive'; break;
		case 4 : text = 'complete'; break;
	
	}
	return text;
}

function stateChangeHttp()
{
	if (httpRequest.readyState == 4)
	{
		if (httpRequest.status == 200)
		{
			httpPostResult = httpRequest.responseText;
			loadTarget();
		}
		httpRequest = null;
	}
}

function loadTarget()
{
    HttpPostDocument = new ActiveXObject("MSXML.DOMDocument");
	HttpPostDocument.loadXML(httpPostResult);
	
    var newOption;
	var elmList = HttpPostDocument.selectNodes('//ROW');
    var len = httpRequestContainer.options.length;
    for(i = 0; i < len; i++)
    {
        httpRequestContainer.options.remove(0);
    }
	for (i = 0; i < elmList.length; i++)
	{
	    elm = elmList[i];
		newOption = new Option(elm.getAttribute("Text"), elm.getAttribute("Value"));
        httpRequestContainer.options.add(newOption);  
	}
}

function loadParameterByValue(source, target, table, filterColumn, valueColumn, textColumn)
{
    var page = 'parameterList.aspx';
    var params = 'table=' + table + '&filter=' + filterColumn + '&value=' + source.value + '&valueCol=' + valueColumn + '&textCol=' + textColumn;
	getResponseHttp(page + '?' +  params, target, source);
}

	
	/************************************************************************************************************
	(C) www.dhtmlgoodies.com, October 2005
	
	Update log:
	Version 1.1 	December, 1st 2005: Critical update for the new Firefox 1.5 browser
	Version 1.2: 	December, 21th 2005 : Mouseover effect when mouse moves outside of a submenu items text
	
	
	This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
	
	Terms of use:
	You are free to use this script as long as the copyright message is kept intact. However, you may not
	redistribute, sell or repost it without our permission.
	
	Thank you!
	
	www.dhtmlgoodies.com
	Alf Magne Kalleland
	
	************************************************************************************************************/	
		
	var dhtmlgoodies_menuObj;	// Reference to the menu div
	var currentZIndex = 1000;
	var liIndex = 0;
	var visibleMenus = new Array();
	var activeMenuItem = false;
	var timeBeforeAutoHide = 1200; // Microseconds from mouse leaves menu to auto hide.
	var dhtmlgoodies_menu_arrow = 'images/arrow.gif';
	
	var MSIE = navigator.userAgent.indexOf('MSIE')>=0?true:false;
	var navigatorVersion = navigator.appVersion.replace(/.*?MSIE ([0-9]\.[0-9]).*/g,'$1')/1;
	var menuBlockArray = new Array();
	var menuParentOffsetLeft = false;	
	function getTopPos(inputObj)
	{
		
	  var returnValue = inputObj.offsetTop;
	  if(inputObj.tagName=='LI' && inputObj.parentNode.className=='menuBlock1'){
	  	var aTag = inputObj.getElementsByTagName('A')[0];
	  	if(aTag)returnValue += aTag.parentNode.offsetHeight;

	  }	  
	  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop;

	  return returnValue;
	}
	
	function getLeftPos(inputObj)
	{
	  var returnValue = inputObj.offsetLeft;
	  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
	  return returnValue;
	}
	
	function showHideSub()
	{

		var attr = this.parentNode.getAttribute('currentDepth');
		if(navigator.userAgent.indexOf('Opera')>=0){
			attr = this.parentNode.currentDepth;
		}
		
		this.className = 'currentDepth' + attr + 'over';
		
		if(activeMenuItem && activeMenuItem!=this){
			activeMenuItem.className=activeMenuItem.className.replace(/over/,'');
		}
		activeMenuItem = this;
	
		var numericIdThis = this.id.replace(/[^0-9]/g,'');
		var exceptionArray = new Array();
		// Showing sub item of this LI
		var sub = document.getElementById('subOf' + numericIdThis);
		if(sub){
			visibleMenus.push(sub);
			sub.style.display='';
			sub.parentNode.className = sub.parentNode.className + 'over';
			exceptionArray[sub.id] = true;
		}	
		
		// Showing parent items of this one
		
		var parent = this.parentNode;
		while(parent && parent.id && parent.tagName=='UL'){
			visibleMenus.push(parent);
			exceptionArray[parent.id] = true;
			parent.style.display='';
			
			var li = document.getElementById('dhtmlgoodies_listItem' + parent.id.replace(/[^0-9]/g,''));
			if(li.className.indexOf('over')<0)li.className = li.className + 'over';
			parent = li.parentNode;
			
		}

			
		hideMenuItems(exceptionArray);



	}

	function hideMenuItems(exceptionArray)
	{
		/*
		Hiding visible menu items
		*/
		var newVisibleMenuArray = new Array();
		for(var no=0;no<visibleMenus.length;no++){
			if(visibleMenus[no].className!='menuBlock1' && visibleMenus[no].id){
				if(!exceptionArray[visibleMenus[no].id]){
					var el = visibleMenus[no].getElementsByTagName('A')[0];
					visibleMenus[no].style.display = 'none';
					var li = document.getElementById('dhtmlgoodies_listItem' + visibleMenus[no].id.replace(/[^0-9]/g,''));
					if(li.className.indexOf('over')>0)li.className = li.className.replace(/over/,'');
				}else{				
					newVisibleMenuArray.push(visibleMenus[no]);
				}
			}
		}		
		visibleMenus = newVisibleMenuArray;		
	}
	
	function menuImageOver(image, action, imageName)
	{
	    var source = image.src;
	    if (Right(source, 8) == 'over.gif')
	        image.src = Left(source, source.length - 8) + '.gif';
	    else
	        image.src = Left(source, source.length - 4) + 'over.gif';
	}
	
	function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}


function ClickOnEnter(ClientID)
{
    var keyCode = window.event.keyCode;
    if (keyCode == 13)
    {
        document.getElementById(ClientID).click();
        return false;
    }
}

function textCounter(field, maxlimit) {

    if (field.value.length > maxlimit) 
        field.value = field.value.substring(0, maxlimit);
    else
    {
        var countfield = document.getElementById(field.id + 'Cnt');
        countfield.value = maxlimit - field.value.length;
    }
}

function ChangeColor(tbl,clr){
    tbl.style.backgroundColor = clr;
}

function checkRequired(clientID, msg)
{
    
    if (document.getElementById(clientID).value.length <= 0) 
    {
        alert(msg);
        SetFocus(clientID);
        return false;
    }
    else
    {
        return true;
    }
}

function comboBoxSelected(cmb)
{
    selVal = document.getElementById(cmb).selectedIndex;
   
    return (selVal > 0);
}

function upper(ctl)
{
    ctl.value = ctl.value.toUpperCase();
}





/*function ElementFocus(element)
{
    element.className = 'inputfocus';
}

function ElementBlur(element)
{
    element.className = 'input';
}

function ConfigureFocus()
{
    alert('s');
    var elms = document.forms[0].elements;
    var elm;
    alert('a');
    for(var i = 0; i < elms.length; i++)
    {
        elm = elms[i];
        alert(elm);
        try
        {
        elm.attachEvent('onfocus', ElementFocus(elm));
        elm.attachEvent('onblur', ElementBlur(elm));
        }
        catch
        {
        }
    }
}*/

//window.attachEvent("onload", ConfigureFocus);

