// JavaScript Document

// Description : This will be used to validate numbers only
//               on text box

function numbersonly(e){
var unicode=e.charCode? e.charCode : e.keyCode
if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
if (unicode<48||unicode>57) //if not a number
return false //disable key press
}
}
/* DIV related functions */
function showHideDIV(divId, divMode) {
	if (divMode == 1) {
		with(document.getElementById(divId)) {
			style.display = 'block';							 
		}
	} else {
		with(document.getElementById(divId)) {
			style.display = 'none';							 
		}	
	}
}
/* DIV related functions */
function showHideDIVByMode(divId, divMode) {
	if (divMode == 1) {
		with(document.getElementById(divId)) {
			style.display = 'block';							 
		}
	} else {
		with(document.getElementById(divId)) {
			style.display = 'none';							 
		}	
	}
}

/* Hide or show given set of DIV elements*/
function showHideDIVgroupByMode(tControls,ctrlMode) {
		tmpControls = tControls.split(',');
		j = 0;
		
		while (j < tmpControls.length) {
			if (ctrlMode == 0) {
				document.getElementById(tmpControls[j]).style.display = 'none';
			} else {
				document.getElementById(tmpControls[j]).style.display = 'block';
			}
			j++;
		}
}


function showHideDIV(hideDIV, showDIV) {
	with(document.getElementById(hideDIV)) {
		style.display = 'none';							 
	}
	with(document.getElementById(showDIV)) {
		style.display = 'block';							 
	}
}
function showHideDIV2(hideDIV1, hideDIV2, showDIV) {
	with(document.getElementById(hideDIV1)) {
		style.display = 'none';							 
	}
	with(document.getElementById(hideDIV2)) {
		style.display = 'none';							 
	}
	with(document.getElementById(showDIV)) {
		style.display = 'block';							 
	}
}

function showHideDIV3(divId, divMode) {
	if (divMode == 1) {
		with(document.getElementById(divId)) {
			style.display = 'block';							 
		}
	} else {
		with(document.getElementById(divId)) {
			style.display = 'none';							 
		}	
	}
}

/* Hide or show given set of DIV elements*/
function showHideDIVgroup(tControls,ctrlMode) {
		tmpControls = tControls.split(',');
		j = 0;
		
		while (j < tmpControls.length) {
			if (ctrlMode == 0) {
				document.getElementById(tmpControls[j]).style.display = 'none';
			} else {
				document.getElementById(tmpControls[j]).style.display = 'block';
			}
			j++;
		}
}



/* Roll over image functions */
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

 //Opens a new window to display the print preview.     
    function OpenPrintPreview()
    {    
        if(window.location.href.toLowerCase().indexOf('aiotl.aspx')<0){ 
            printPreviewWindow = window.open(window.location.href,"PrintPreview");   
        }
        else{
            if(window.location.href.indexOf('?')!=-1)
                printPreviewWindow = window.open(window.location.href+'&printView=1',"PrintPreview");
            else
                printPreviewWindow = window.open(window.location.href+'?printView=1',"PrintPreview");
        }
        printPreviewWindow.opener = window;
    }     

    //Sets the style sheet to the print style sheet.
    function SetPrintStyleSheet() 
    {
        if (window.name == 'PrintPreview')
        {            
            //document.styleSheets[3].href='../styles/print.css';
            document.styleSheets[3].disabled = false;
            if (document.getElementById('divFloat') != null)
            {            
                document.getElementById('divFloat').style.display='none';
            }
        }
        else
        {
            document.styleSheets[3].disabled = true;
        }
    }
    
// restricts the inputs to the specified set of characters when OnBlur happens
function validateTextInputOnBlur(type, object)
{
    var expr
    var inputText
    
    with(document.getElementById(object))
        {
            inputText = value;
        }
        
    switch (type) 
    {
        case 1: //Numerics
            expr = /[^0-9]/
            if ( expr.test(inputText) )
                {
	            //removes the newly insetted character
                    with(document.getElementById(object))
                        {
			    while(expr.test(value))
			    {
                               //object.value = text1.substr(0,text1.length-1);
	                       value = value.substr(0,value.length-1);
			    }
                        }
                            
                }
            break
        case 2: //Alphanumerics + ' + Space
            expr = /[^a-zA-Z'\s]/
            if ( expr.test(inputText) )
            {
                //removes the newly insetted character
                with(document.getElementById(object))
                {
                    //object.value = text2.substr(0,text2.length-1);
                    value = inputText.substr(0,inputText.length-1);
                }
            }
            break
        case 3: //Alphanumerics + @ + .
            expr = /[^0-9a-zA-Z\s]/
            if ( expr.test(inputText) )
            {
                //removes the newly insetted character
                with(document.getElementById(object))
                {
                    //object.value = text3.substr(0,text3.length-1);
                    value = inputText.substr(0,inputText.length-1);
                }
            }
            break
      case 4: //Decimal
            expr = /[^0-9.]/
            if ( expr.test(inputText) )
                {
                    //removes the newly insetted character
                    with(document.getElementById(object))
                        {
                            //object.value = text1.substr(0,text1.length-1);
                            value = inputText.substr(0,inputText.length-1);
                        }
                            
                }
             
            break
    }
    
}

// restricts the inputs to the specified set of characters
function validateTextInput(type, object)
{
    var expr
    var inputText
    
    with(document.getElementById(object))
        {
            inputText = value;
        }
        
    switch (type) 
    {
        case 1: //Numerics
            expr = /[^0-9]/
            if ( expr.test(inputText) )
                {
	            //removes the newly insetted character
                    with(document.getElementById(object))
                        {
			    while(expr.test(value))
			    {
                               //object.value = text1.substr(0,text1.length-1);
	                       value = value.substr(0,value.length-1);
			    }
                        }
                            
                }
            break
        case 2: //Alphanumerics + ' + Space
            expr = /[^a-zA-Z'\s]/
            if ( expr.test(inputText) )
            {
                //removes the newly insetted character
                with(document.getElementById(object))
                {
                    //object.value = text2.substr(0,text2.length-1);
                    value = inputText.substr(0,inputText.length-1);
                }
            }
            break
        case 3: //Alphanumerics + @ + .
            expr = /[^0-9a-zA-Z\s]/
            if ( expr.test(inputText) )
            {
                //removes the newly insetted character
                with(document.getElementById(object))
                {
                    //object.value = text3.substr(0,text3.length-1);
                    value = inputText.substr(0,inputText.length-1);
                }
            }
            break
      case 4: //Decimal
            expr = /[^0-9.]/
            if ( expr.test(inputText) )
                {
                    //removes the newly insetted character
                    with(document.getElementById(object))
                        {while(expr.test(value))
			    {
                               //object.value = text1.substr(0,text1.length-1);
	                       value = value.substr(0,value.length-1);
			    }
                        }
                            
                }
             
            break
    }
    
}

// This method validate the value of the text box and move the cursor to the next text box in the sequence 
function autoTab(type, thisControl, textLength, nextControl) {

    validateTextInput(type, thisControl);
    
    if (document.getElementById(thisControl).value.length == textLength && nextControl != null) {
        document.getElementById(nextControl).focus();
    }

}

function collapse(obj, div){
	with(document.getElementById(div)){
		if (style.display == 'none'){
			style.display='block';
			
			if (obj.getElementsByTagName("IMG") != null && obj.getElementsByTagName("IMG").length > 0)
			{
			    obj.getElementsByTagName("IMG")[0].src="/images/twisty_collapsed.gif";
			}
		}else{
			style.display='none';
			
			if (obj.getElementsByTagName("IMG") != null && obj.getElementsByTagName("IMG").length > 0)
			{
			    obj.getElementsByTagName("IMG")[0].src="/images/twisty_default.gif";
			}
		}
	}	
}




//A fucntion that's used to close the AddressLookup popup and 
    //calls the opener window. 
    function closeAddressLookup(addressID, addressString)
    {          
        var controlID = getQueryVariable('ControlID');
        var hiddenID = getQueryVariable('HiddenID');
        if ((controlID != null) && (hiddenID != null) && (controlID != '') && (hiddenID != '')) 
        {
            window.opener.setAddress(addressString, controlID, addressID, hiddenID);
        }   
        window.close();       
    }
    
    function openAddressLookup(ControlID, HiddenID)
    {
        var pageURL = '/SharedWebSite/FindAddress.aspx?ControlID=';
        pageURL += ControlID;
        pageURL += '&HiddenID=';
        pageURL += HiddenID;        
        window.open(pageURL, 'FindAddress','height=600,width=750,status=yes,toolbar=no,menubar=no,location=no,left=100,top=100,titlebar=no,scrollbars=yes,resizable =yes');
    }
    
    function openAddressLookupWithAddress(HiddenID)
    {        
        var pageURL = '/SharedWebSite/FindAddress.aspx?Criteria=True';
        pageURL += '&HiddenID=';
        pageURL += HiddenID;    
        var FindAddressWindow = window.open(pageURL, 'FindAddressWindow','height=600,width=750,status=yes,toolbar=no,menubar=no,location=no,left=100,top=100,titlebar=no,scrollbars=yes,resizable =yes');                
    }
    
    function closeAddressLookupWithAddress(addressXmlString)
    {   
        var hiddenID = getQueryVariable('HiddenID');        
        if ((hiddenID != null) && (hiddenID != '')) 
        {
            window.opener.setOpenerHiddenAddressXml(addressXmlString, hiddenID);
        }   
        window.close();       
    }
    
    function SetAddressHiddenXml(hiddenID)
    {        
        var varEnteredAddress = window.opener.GetEnteredAddress();
        if ((varEnteredAddress != null) & (varEnteredAddress != ''))
        {
            document.getElementById(hiddenID).value= varEnteredAddress;
            __doPostBack();
        }
    }
    
    function setOpenerHiddenAddressXml(selectedAddressXml, hiddenID)
    {         
        if ((hiddenID != null) && (hiddenID != '')) 
        {            
            document.getElementById(hiddenID).value= selectedAddressXml;	
        }
        __doPostBack();
	   
    }
    
    function setAddress(selectedAddress, controlID, addressID, hiddenID)
    {       
        document.getElementById(controlID).value= selectedAddress;
        document.getElementById(hiddenID).value= addressID;
	
	var msgDiv = document.getElementById('validationPassed');
	msgDiv.style.display = 'block';
    }
    
    
//******************** Address control scripts ****************

// Popup the address lookup window (called from inline control)
function openGeoAddressLookup(XID, PIID, MIID, OIID, Map, Multi, FN, D)
{
    var pageBase;
    if( Map != '1' && document.getElementById(XID).value != null && document.getElementById(XID).value != '' )
    {
        pageBase = '/SharedWebSite/GeoLaunchAddress.aspx';
    }
    else if( FN == 'CivicMailing' )
    {
        pageBase = '/SharedWebSite/GeoCivicMailingFindAddress.aspx';
    }
    else if( FN == 'Mailing' )
    {
        pageBase = '/SharedWebSite/GeoMailingFindAddress.aspx';
    }
    else if( FN == 'OOP' )
    {
        pageBase = '/SharedWebSite/GeoOopFindAddress.aspx';
    }
    else
    {
        pageBase = '/SharedWebSite/GeoFindAddress.aspx';
    }
    var pageURL = pageBase + '?XID=' + XID + '&PIID=' + PIID + '&MIID=' + MIID + '&OIID=' + OIID + '&Map=' + Map + '&Multi=' + Multi + '&FN=' + FN + '&D=' + D;
    window.open(pageURL, 'GeoFindAddress','height=600,width=750,status=yes,toolbar=no,menubar=no,location=no,left=100,top=100,titlebar=no,scrollbars=yes,resizable=yes');
}

// Close the popup control and return results (called from shared control)
function closeGeoAddressLookup(PIIDV, PIID, MIIDV, MIID, OIIDV, OIID, AddressXML, XID)
{
    if( window.opener != null )
    {
        window.opener.saveGeoAddressLookup(PIIDV, PIID, MIIDV, MIID, OIIDV, OIID, AddressXML, XID)
        window.close();
    }
}

// Used to return result to inline control (defined on the inline control page)
function saveGeoAddressLookup(PIIDV, PIID, MIIDV, MIID, OIIDV, OIID, AddressXML, XID)
{
    document.getElementById(PIID).value = PIIDV;
    document.getElementById(MIID).value = MIIDV;
    document.getElementById(OIID).value = OIIDV;
    document.getElementById(XID).value = AddressXML;
    __doPostBack();
}

    
// Validate the day of the month
function checkDate(day, month, year)
{
    var Day = day;
    var Month = month;
    var Year = year;
   
    if ((Month == 2) && (Day == 29) && ((Year%4)!=0))
    {
        alert('This is not a valid date.'); 
    }
    else if ((Month == 2) && (Day == 30)) 
    {
    alert('This is not a valid date.'); 
    }
    else if ((Month == 2) && (Day == 31)) 
    {
    alert('This is not a valid date.'); 
    }
    else if
    ((Month == 4) && (Day == 31)) 
    {
    alert('This is not a valid date.'); 
    }
    else if
    ((Month == 6) && (Day == 31)) 
    {
    alert('This is not a valid date.'); 
    }
    else if
    ((Month == 9) && (Day == 31)) 
    {
    alert('This is not a valid date.'); 
    }
    else if
    ((Month == 11) && (Day == 31)) 
    {
    alert('This is not a valid date.'); 
    }
    else 
    {
    }
     
}   

// Validate the day of the month
function checkDateCulture(day, month, year, culture)
{
    var Day = day;
    var Month = month;
    var Year = year;
    var culture = culture;
   
    if ((Month == 2) && (Day == 29) && ((Year%4)!=0))
    {
        if(culture == 'fr-CA')
        {
            alert("Cette date n'est pas valide."); 
        }else
        {
            alert('This is not a valid date.'); 
        }
    }
    else if ((Month == 2) && (Day == 30)) 
    {
        if(culture == 'fr-CA')
        {
            alert("Cette date n'est pas valide."); 
        }else
        {
            alert('This is not a valid date.'); 
        }
    }
    else if ((Month == 2) && (Day == 31)) 
    {
        if(culture == 'fr-CA')
        {
            alert("Cette date n'est pas valide."); 
        }else
        {
            alert('This is not a valid date.'); 
        }
    }
    else if
    ((Month == 4) && (Day == 31)) 
    {
         if(culture == 'fr-CA')
        {
            alert("Cette date n'est pas valide."); 
        }else
        {
            alert('This is not a valid date.'); 
        }
    }
    else if
    ((Month == 6) && (Day == 31)) 
    {
         if(culture == 'fr-CA')
        {
            alert("Cette date n'est pas valide."); 
        }else
        {
            alert('This is not a valid date.'); 
        }
    }
    else if
    ((Month == 9) && (Day == 31)) 
    {
     if(culture == 'fr-CA')
        {
            alert("Cette date n'est pas valide."); 
        }else
        {
            alert('This is not a valid date.'); 
        }
    }
    else if
    ((Month == 11) && (Day == 31)) 
    {
     if(culture == 'fr-CA')
        {
            alert("Cette date n'est pas valide."); 
        }else
        {
            alert('This is not a valid date.'); 
        }
    }
    else 
    {
    } 
}

function f_open_window_max( url ){
    
   var wOpen;
   var sOptions;
    
   sOptions = 'status=yes,menubar=yes,scrollbars=no,resizable=yes,toolbar=yes,titlebar=yes,location = yes';   
   sOptions = sOptions + ',width=' + (screen.availWidth).toString();
   sOptions = sOptions + ',height=' + (screen.availHeight).toString();
   sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';

   wOpen = window.open( '', '', sOptions );
   wOpen.location = url;
   wOpen.focus(); 
   wOpen.moveTo(0,0);   
   wOpen.resizeTo( screen.availWidth, screen.availHeight ); 
   return false;      
}


function validateNumberOfChars(clientId, numberOfCharsToBeChecked)
{
    var control;
    control = document.getElementById(clientId);
    
    if (control.value.length > numberOfCharsToBeChecked)
    {
        control.value = control.value.substr(0, numberOfCharsToBeChecked);
    }
}
    
function showToolTip(ddlCtrlId)
{
	var ddlControl = document.getElementById(ddlCtrlId);
	ddlControl.setAttribute('title', ddlControl.options[ddlControl.selectedIndex].text);
}
    //-->