﻿// JScript File

function openWinPass(url, name) { 
    
	popupWin = window.open(url, name, "toolbar=no,location=center,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=520,height=220"); 
	
} 

var oPopup = window.createPopup();
function openPopup(hiddenID, divID, passwordID)
{   
        
    var hid = document.getElementById(hiddenID);
    if (hid.value == 1)
    {
    
        //get popup body
        var oPopBody = oPopup.document.body;
        
        //get popup header
        
        //var oPopHead = oPopup.document
    
        // The following HTML that populates the popup object with a string.
        var ctrlDiv = document.getElementById(divID);
        oPopBody.innerHTML = ctrlDiv.innerHTML;
        
       
        
        var ctrl =  document.getElementById(passwordID);
    
        //oPopup.show(getAbsPos(ctrl).x , getAbsPos(ctrl).y + ctrl.clientHeight + 5, 245, 93, document.body);
        //oPopup.show(getAbsPos(ctrl).x , getAbsPos(ctrl).y + ctrl.clientHeight + 5, ctrlDiv.parentNode.offsetWidth, ctrlDiv.parentNode.offsetHeight, document.body);
        
        oPopup.show(getAbsPos(ctrl).x , getAbsPos(ctrl).y + ctrl.clientHeight + 5, 245, ctrlDiv.offsetParent.offsetHeight, document.body);
        
         
        
    }
    
}


function getAbsPos(p)
{
    var s = { x:0, y:0 };
        
    while (p.offsetParent)
    {
        s.x += p.offsetLeft;
        s.y += p.offsetTop;
        p = p.offsetParent;
    }
        
    return s;
}

function GetTimeZone() {
    
    var d = new Date()
    var str = (d.getTimezoneOffset()/60)*(-1);
    var ctrlHid = document.getElementById("hd_time");
    ctrlHid.value = str;
    
}

function openSignWin(hiddenID, Url) { 
   
	
    var hid = document.getElementById(hiddenID);
    if (hid.value == 1)
    {
        popupWin = window.open(Url, "window", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=520,height=320"); 
    }
    return true;  
} 



function openWin(url, name) { 
  popupWin = window.open(url, name, "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=460,height=300"); 
   return true; 
} 

function openSizeWin(url, name, iHeight, iWidth) { 
  popupWin = window.open(url, name, "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=" + iWidth + ",height=" + iHeight); 
   return true;
} 

function openBigWin(url) { 
  popupWin = window.open(url); 
   
}

function openNewWin(url, name) { 
	popupWin = window.open(url, name); 
	 
} 



var RequiredFXVersion = "2.0.50727"
    
    function testFrameworkVersion(iHiddenID)
    {
        var hid = document.getElementById(iHiddenID);
        var foundVer = CheckRequiredFXVersion(RequiredFXVersion);
        if (foundVer != null)
        {
            hid.value = 1;                      
        } 
        else
        {
            hid.value = 0;
        }
      //result.innerHTML="Helo world"
    }
    
    //
    // Retrieve available versions from the user agent string
    // and check if any of them match the required version.
    //
    function CheckRequiredFXVersion(requiredVersion)
    {
      var userAgentString = navigator.userAgent.match(/\.NET CLR[ .][0-9.]+/g);
      if (userAgentString != null)
      {
        var i;
        for (i = 0; i < userAgentString.length; ++i)
        {
          var ver = userAgentString[i].slice(9);
          if (CheckVersion(requiredVersion, ver))
            return ver;
        }
      }
      return null;
    }

    //
    // Check if a specific version satisfies the version requirement.
    //
    function CheckVersion(requiredVersion, ver)
    {
      requiredVersion = requiredVersion.split(".");
      ver = ver.split(".");
      
      // Major versions must match exactly.
      if (requiredVersion[0] != ver[0])
        return false;
      
      // Minor/build numbers must be at least the required version.
      var i;
      for (i = 1; i < requiredVersion.length && i < ver.length; i++)
      {
        if (new Number(ver[i]) < new Number(requiredVersion[i]))
          return false;
      }
      return true;
    }
    
    
  //check numbers
function CheckNumbers (ctrl, startChar)
{
    var allowChars;
    allowChars = "0123456789";

    var i = 0;
    
    //check firs digit
    if (ctrl.value.charAt(0) == startChar)
        ctrl.value = ctrl.value.replace(startChar, "");
    else startChar = "";
    
    
    for(i=0; i<ctrl.value.length; i++)
        if(allowChars.indexOf(ctrl.value.charAt(i))==-1)
            ctrl.value = ctrl.value.replace(ctrl.value.charAt(i), "", 1);
            
   ctrl.value = startChar + ctrl.value;         
 }
 
 
// -------------------------------------------------------------------------------------------------------------
// functions for checking length of text aria

function setMaxLength() {
	var x = document.getElementsByTagName('textarea');
	var counter = document.createElement('div');
	counter.className = 'counter';
	for (var i=0;i<x.length;i++) {
		if (x[i].getAttribute('maxlength')) {
			var counterClone = counter.cloneNode(true);
			counterClone.relatedElement = x[i];
			counterClone.innerHTML = '<span style="font-size=11">0<span style="font-size=11">/'+x[i].getAttribute('maxlength')+'</span>';
			x[i].parentNode.insertBefore(counterClone,x[i].nextSibling);
			x[i].relatedElement = counterClone.getElementsByTagName('span')[0];
			
			x[i].onkeyup = x[i].onchange = checkMaxLength;
			x[i].onkeyup();
		}
	}
}

function checkMaxLength() {
	var maxLength = this.getAttribute('maxlength');
	var currentLength = this.value.length;
	if (currentLength > maxLength)
	{
		//this.relatedElement.className = 'toomuch';
		var curS = new String(this.value);
		this.value = curS.substr(0, maxLength);
		currentLength = this.value.length;
	}
	else
		this.relatedElement.className = '';
	this.relatedElement.firstChild.nodeValue = currentLength;
	// not innerHTML
}
//--------------------------------------------------------------------------------------------------------------

function OnLoadDefaultPage()
{
    GetTimeZone();
    setMaxLength();
}