function openForgotTAP(pUrl){
	var hWnd;
	hWnd = window.open(pUrl,"forgotTAP","status=no,toolbar=no,resizable=yes,menubar=no,scrollbars=yes,height=600,width=660,top=40,left=150");
	hWnd.focus();
}

function GetXmlHttpObject()
{ 
    var objXMLHttp=null
    if (window.XMLHttpRequest)
    {
        objXMLHttp=new XMLHttpRequest()
    }
    else if (window.ActiveXObject)
    {
        objXMLHttp=new ActiveXObject("Microsoft.xmlHttp")
    }
    return objXMLHttp
} 


	function changeObjChecked(obj,enableObj,fromChkBox)
	{
	    if ( obj.disabled)
            return;
            
		if ( obj.checked )
		{
			if (!fromChkBox)
				obj.checked = false;
			
			if ( typeof(enableObj) != "undefined" )
				if (fromChkBox)
					enableObj.disabled = false;
				else
					enableObj.disabled = true;
		}
		else
		{
			if (!fromChkBox)
				obj.checked = true;
			if ( typeof(enableObj) != "undefined" )
				if (fromChkBox)
					enableObj.disabled = true;
				else
					enableObj.disabled = false;
		}
	}


// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

function trimIWField (fieldReference) {
	if (fieldReference != null) {
		if (fieldReference.value != "") {
            fieldReference.value = trim(fieldReference.value);
		}
	}
}

function isEmail(argvalue) {
	mailRegexTxt = "^(([\\^\"\\f\\n\\r\\t\\v\\b]+)|([\\w\\!#\\$%\\&\\'\\*\\+\\-~\\/\\^\\`\\|\\{\\}]+(\\.[\\w\\!#\\$%\\&\\'\\*\\+\\-~\\/\\^\\`\\|\\{\\}]+)*))@((\\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\\-])+\\.)+[A-Za-z\\-]+))$";
	mailRegex = new RegExp(mailRegexTxt);
	if( mailRegex.exec(argvalue) ) {
		retval = true;
	} else {
		retval = false;
	}

	return retval;
}

function FormatStringWithData(myString, myData)
{
	 var ArrayItem

	 FormattedString = myString;
	 ArrLen = myData.length+1;
	 for (ArrayItem=1;ArrayItem<ArrLen;ArrayItem++)
	 {
	    DataFormat='<iwdata' + ArrayItem + '>';
	    FoundData = myString.lastIndexOf(DataFormat);
	    if (FoundData > -1)
	    {

		FormattedString =FormattedString.replace(DataFormat, myData[ArrayItem-1]);
	    }
	    else
	    {
		FormattedString=FormattedString+' '+myData[ArrayItem-1]
	    }
	 }

	return(FormattedString);
}


function MM_goToURL() { //v2.0
	  for (var i=0; i< (MM_goToURL.arguments.length - 1); i+=2) //with arg pairs
	    eval(MM_goToURL.arguments[i]+".location='"+MM_goToURL.arguments[i+1]+"'");
	  document.MM_returnValue = false;
	}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	  window.open(theURL,winName,features);
	}
	
function GetCategoryFilterString(FormX)
{
 var ItemX;
 var ItemName = '';
 var fReturn = '';

	for (var i=0; i < FormX.length; i++)
	{
		if (FormX.item(i).type == 'select-one')
	{
			if (FormX.item(i).value > 0 )
			{
				ItemName =FormX.item(i).name;
				if (ItemName.substr(0,3) == 'Cat')
				{
					fReturn = fReturn + ' AND ' +  FormX.item(i).name + ' = \''+ FormX.item(i).value+'\''
				}
			}
	}
    }
	return(fReturn)
}



// Sets cookie values. Expiration date is optional//
function setCookie(name, value, expire)
{   document.cookie = name + "=" + escape(value)   + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}

function GetClientTimeZone()
{	
	x = new Date();
	TzOffset = x.getTimezoneOffset();
	TZString = TzOffset.toString();
	return(TZString);
}
function GetClientTimeZoneByEventUTC(pEventDateTimeUTC)
{
	var LocalDate,TimeZone
	LocalDate=GetClientDateTimeByEventUTC(pEventDateTimeUTC);
	TimeZone=LocalDate.getTimezoneOffset();	
	return(TimeZone.toString());
}
function GetClientDateTimeByEventUTC(pEventDateTimeUTC)
{	
	var ConvertDateTime	
	var DateTimeUTC
	DateTimeUTC=pEventDateTimeUTC.toString();	
	ConvertDateTime=new Date(DateTimeUTC + " UTC");	
	//Object Date automaticly translate UTC to Local
	return(ConvertDateTime);
}

function FormatTimeZone(pTimeZone,pFormatType,pGMTString) 
{
	var fReturn		
	var Sign		
										
	if (pTimeZone<0) {
		Sign=""}
	else {
		Sign="+"}
				
	fReturn="("+pGMTString+Sign+ConvertTimeZone(pTimeZone,2,1)+")"				
	return(fReturn);
}
function ConvertTimeZone(pTimeZone,pFromFormatType,pToFormatType)
{
	var fReturn
	var MinTimeZone
	var HourTimeZone
	var Sep	
	
	if (pTimeZone>0){				
		HourTimeZone=Math.floor(pTimeZone /60)		
		}
	else
		{
		HourTimeZone=Math.ceil(pTimeZone / 60)
		}
	MinTimeZone=pTimeZone % 60
	if (MinTimeZone==0) { MinTimeZone="00"}					
	fReturn=HourTimeZone+":"+MinTimeZone		
					
	return(fReturn)
}

function DLS(){
	
	UTC_NO_DLS_OFFSET = 0;	
	NO_DLS_MONTH = 1;
	DLS_MONTH = 2;

	MINUTE = 60*1000;
	HOUR = 60*60*1000;
	DAY = 24*60*60*1000;
	
	this.today = new Date()		// Today's date at the client's machine.
	this.offsetWithDLS = 0;		// Offset from UTC with DLS.
	this.offsetNoDLS = 0;		// Offset from UTC without DLS.
	this.noDLSFlag = false;		// Determines whether there is DLS settings at this client
	this.currDateVal = this.today.valueOf(); // Numerical value of today. 
	this.DLSShiftDate = '';		// Date string of the DLS changing date. 
	this.noDLSShiftDate = '';	// Date string of the no DLS changing date.
	this.shiftDateVal = 0		// Numerical value of the DLS changing date.
	this.nextShiftVal = 0;		// Numerical value of the no DLS changing date.
	this.nCurrentMonth = this.today.getMonth()+1;
		
	if (typeof(_DLS_prototype_called) == 'undefined')
    {
       _DLS_prototype_called = true;
       DLS.prototype.getClientDLSDate = _getClientDLSDate ;
       DLS.prototype.initateDLSswitchDates = _initateDLSswitchDates;
       DLS.prototype.searchCalanderForDLSDetails = _searchCalanderForDLSDetails;
       DLS.prototype.serchDate = _serchDate
    }
	
	
	function _getClientDLSDate(){
		
		var dlsStr;
		
		this.searchCalanderForDLSDetails()
		this.initateDLSswitchDates()
		
		dlsStr = this.DLSShiftDate +","+this.noDLSShiftDate;
		return dlsStr;
	}
	
	function _searchCalanderForDLSDetails(index){
		
		var monthGap = 3;
		var currentOffset = this.today.getTimezoneOffset()
		var checkMonth = this.nCurrentMonth - 1 + monthGap
		var checkDate = new Date(this.today.getYear(),this.today.getMonth()+monthGap,this.today.getDate())
		
		while (currentOffset == checkDate.getTimezoneOffset() && this.today.getMonth() != checkDate.getMonth()){
			checkMonth += monthGap;
			checkDate.setMonth(checkMonth);
			
		}
		
		if (currentOffset > checkDate.getTimezoneOffset()){
			this.offsetNoDLS = currentOffset;
			this.offsetWithDLS = checkDate.getTimezoneOffset();
		}
		else if (currentOffset < checkDate.getTimezoneOffset()){
			this.offsetNoDLS = checkDate.getTimezoneOffset();
			this.offsetWithDLS = currentOffset;
		}
		else {
			this.offsetNoDLS = currentOffset;
			this.offsetWithDLS = currentOffset;
			this.noDLSFlag = true;
		}
		this.shiftDateVal = checkDate.valueOf();
		
		var cnt=0
		while (currentOffset != checkDate.getTimezoneOffset() && cnt<20){
			cnt++;
			checkMonth += monthGap;
			checkDate.setMonth(checkMonth);
		}	
		this.nextShiftVal = checkDate.valueOf();
		
	}	
	function _initateDLSswitchDates(){
		
		if (this.noDLSFlag == true) return;
		
		var lowBound = this.currDateVal;
		var hiBound = this.shiftDateVal;
		var secHiBound = this.nextShiftVal;
		var lowDate 
		var hiDate 
		
		hiBound = this.serchDate(lowBound,hiBound)
		
		lowDate = new Date(hiBound - DAY)
		hiDate = new Date(hiBound + DAY)
		
		if (hiDate.getTimezoneOffset() > lowDate.getTimezoneOffset()) 
			this.noDLSShiftDate = hiDate.getMonth()+1 + "/" + hiDate.getDate() + "/" + hiDate.getFullYear();
		else 
			this.DLSShiftDate = hiDate.getMonth()+1 + "/" + hiDate.getDate() + "/" + hiDate.getFullYear();
		
		hiBound = this.serchDate(hiBound,secHiBound)
		
		lowDate = new Date(hiBound - DAY)
		hiDate = new Date(hiBound + DAY)
		
		if (hiDate.getTimezoneOffset() > lowDate.getTimezoneOffset()) 
			this.noDLSShiftDate = hiDate.getMonth()+1 + "/" + hiDate.getDate() + "/" + hiDate.getFullYear();
		else 
			this.DLSShiftDate = hiDate.getMonth()+1 + "/" + hiDate.getDate() + "/" + hiDate.getFullYear();
		
	}

	function _serchDate(lowBound,hiBound){

		var midBound;
		var midDate,lowDate,hiDate;

		var cnt=0

		lowDate = new Date(lowBound)
		while ((hiBound - lowBound) > DAY && cnt<20){
			cnt++;
			midBound = (lowBound + hiBound)/2
			midDate = new Date(midBound);
			if (midDate.getTimezoneOffset() != lowDate.getTimezoneOffset()){
				hiBound = midBound;
				hiDate = new Date(hiBound);	
			}
			else {
				lowBound = midBound;
				lowDate = new Date(lowBound);
			}

		}

		return hiBound;
	}	
	
	
} 

function splitString (pStringToSplit, pSeparator) {
	var arrayOfSearch;
	var fReturn = true;
	var ch;

	arrayOfSearch = pStringToSplit.split(pSeparator)
	for (var i = 0; i < arrayOfSearch.length && fReturn; i++)
	{
		ch = arrayOfSearch[i];
		ch = ch.replace(/'/g,"''");
		ch = strLeftTrim(ch);
		ch = strRightTrim(ch);
		if (ch == "")
		{
			fReturn = false;
		}
	}


	return (fReturn);					
}	
	

function strRightTrim (pStringToTrim){
	var bSpace = true;
	var nCurrentLen = 0;
	var trimStr = pStringToTrim
	var ch;
	while(bSpace){
		nCurrentLen = trimStr.length;
		ch = trimStr.charAt(nCurrentLen-1);
		if(ch == ' ') {
			trimStr = trimStr.substring(0,nCurrentLen-2);
			}
		else
			bSpace = false;
		}
	return (trimStr);		
	}
function strLeftTrim (pStringToTrim){
	var bSpace = true;
	var nCurrentLen = 0;
	var trimStr = pStringToTrim
	var ch;
	while(bSpace){
		ch = trimStr.charAt(0);
		if(ch == ' ') {
			trimStr = trimStr.substr(1, trimStr.length - 1);
			}
		else
			bSpace = false;
		}
	return (trimStr);		
	}
function TrimComas(TextField)
{
  var StrToFix = String(TextField)

  StrToFix = StrToFix.replace(/ +,/g,",")
  StrToFix = StrToFix.replace(/, +/g,",")
  StrToFix = StrToFix.replace(/,+/g,",")
  StrToFix = StrToFix.replace(/,$/g,"")
  StrToFix = StrToFix.replace(/^,/g,"")	  

  StrToFix = StrToFix.replace(/ +;/g,";")
  StrToFix = StrToFix.replace(/; +/g,";")
  StrToFix = StrToFix.replace(/;+/g,";")
  StrToFix = StrToFix.replace(/;$/g,"")
  StrToFix = StrToFix.replace(/^;/g,"")	  	  
  return StrToFix

}
function openGateWayNumbers(pUrl){
	var hWnd;
	hWnd = window.open(pUrl,"GateWayNumbers","status=no,toolbar=no,resizable=yes,menubar=no,scrollbars=yes,height=600,width=500,top=40,left=150");
	hWnd.focus();
}
function strtrim(xstr) {
    //Match spaces at beginning and end of text and replace
    //with null strings
    return xstr.replace(/^\s+/,'').replace(/\s+$/,'');
}

function preserveRadioGroup (evt) {
  this.checked = this.storedChecked;
  var rgb = this.form[this.name];
  if (!rgb.length && rgb.storedChecked)
    rgb.checked = true;
  else 
    for (var b = 0; b < rgb.length; b++)
      rgb[b].checked = rgb[b].storedChecked ? true : false;
}
function disableRadioGroup (radioGroup) {
  if (!radioGroup.disabled) {
    radioGroup.disabled = true;
    if (document.all || document.getElementById) {
      if (!radioGroup.length)
        radioGroup.disabled = true;
      else
        for (var b = 0; b < radioGroup.length; b++)
          radioGroup[b].disabled = true;
     }
    else {
      if (!radioGroup.length) {
        radioGroup.storedChecked = radioGroup.checked;
        radioGroup.oldOnClick = radioGroup.onclick;
        radioGroup.onclick = preserveRadioGroup;
      }
      else
        for (var b = 0; b < radioGroup.length; b++) {
          radioGroup[b].storedChecked = radioGroup[b].checked;
          radioGroup[b].oldOnClick = radioGroup[b].onclick;
          radioGroup[b].onclick = preserveRadioGroup;
        }
    }
  }
}
function enableRadioGroup (radioGroup) {
  if (radioGroup.disabled) {
    radioGroup.disabled = false;
    if (document.all || document.getElementById) {
      if (!radioGroup.length)
        radioGroup.disabled = false;
      else
        for (var b = 0; b < radioGroup.length; b++)
          radioGroup[b].disabled = false;
     }
    else {
      if (!radioGroup.length) {
        radioGroup.onclick = radioGroup.oldOnClick;
      }
      else
        for (var b = 0; b < radioGroup.length; b++) {
          radioGroup[b].onclick = radioGroup[b].oldOnClick;
        }
    }
  }
}	

function skip () { this.blur(); }

function doNothing() { }

function toggleSelect (select) {
  if (!select.disabled) {
    select.disabled = true;
    if (!document.all && !document.getElementById) {
      select.oldOnFocus = 
        select.onfocus ? select.onfocus : null;
      select.onfocus = skip;
    }
  }
  else {
    select.disabled = false;
    if (!document.all && !document.getElementById) {
      select.onfocus = select.oldOnFocus;
    }
  }
}


function catchEnterKey4Submit()
{
    try
    {
        key=window.event.keyCode
        if (key==13)
        {
	        SubmitMainForm();
	        return;
        }
    }
    catch(e)
    {}
}
function readKey(e)
{
    try
    {
        if (e.keyCode==13)
	        SubmitMainForm();
    }
    catch(e)
    {}
}
try
{
    document.onkeypress = readKey;
}
catch(e)
{}

