﻿var alertList = new Array();


function checkIE()
{
	var isIE=false;

	if(!window.XMLHttpRequest)  
	{  
		isIE=true;
	}
	if((window.navigator.appName).toLowerCase()=='microsoft internet explorer') //checking for Ie7
	{
	    var version = window.navigator.appVersion;
	    var version1 ;
	    if(version.indexOf("MSIE")!=-1)
	    {
		    version1 = version.substring((version.indexOf("MSIE")+4),version.length);
		    version1 = version1.substring(0,2);
		    if (parseInt(version1) == 7 || parseInt(version1) == 6)
		    {
			    isIE=true;
    			
		    }
	    } 
	}    
	
	return isIE;
}
 
function Trim(sString) 
{
			
	while (sString.substring(0,1) == ' ')
	{
	sString = sString.substring(1, sString.length)
	}
	while(sString.substring(sString.length-1, sString.length) == ' ')
	{
	sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function ChkValidEmail(object)
{
    var myRegxp = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/

    return myRegxp.test(object);
}


function addComma(object)
{
    if(object != "")
    {
        object += ", ";
    }
    
    return object;
}

function getScrollTop()
{
    var sTop = 0;
    
    if(parseInt(document.body.scrollTop) > 0)
    {
        sTop = parseInt(document.body.scrollTop);
    }
    else if(parseInt(document.documentElement.scrollTop) > 0)
    {
        sTop = parseInt(document.documentElement.scrollTop);
    }
    
    return sTop;
}

function displayDisability(bolValue)
{
    try
    {
        //showHideSelectControls(bolValue);
       // showHideObjectElements(bolValue);
        
        if(bolValue)
        {
            $get('divDisable').style.width = document.body.scrollWidth - 20 + "px";
           
            var objHeight;
            objHeight=parseInt(document.documentElement.clientHeight) + parseInt(document.documentElement.scrollTop);
           
            if(objHeight<600)
            {
				objHeight=600;
            }
          
            $get('divDisable').style.height = objHeight + "px";
            
			var newHeight;
			newHeight=parseInt(document.documentElement.scrollHeight);
			if(parseInt($get('divDisable').style.height)<newHeight)
			{
				$get('divDisable').style.height=newHeight + "px";
			}
            $get('divDisable').style.display = ""; 
        }
        else
        {
            $get('divDisable').style.display = "none";
            $get('divDisable').style.zIndex = "700";
        }
    }
    catch(err)
    {}
}

function showHideSelectControls(obj)
{
    var len=document.getElementsByTagName("select").length;
    var intLoop=0;
    
    if(obj==false)
    {
        for(intLoop=0; intLoop<len; intLoop++)
        {
            document.getElementsByTagName("select")[intLoop].style.visibility="visible";
        }
    }
    else
    {
        for(intLoop=0; intLoop<len; intLoop++)
        {
            document.getElementsByTagName("select")[intLoop].style.visibility="hidden";
        }
    }
}

function showHideObjectElements(obj)
{
    var len=document.getElementsByTagName("object").length;
    var intLoop=0;
    
    if(obj==false)
    {
        for(intLoop=0; intLoop<len; intLoop++)
        {
            document.getElementsByTagName("object")[intLoop].style.visibility="visible";
        }
    }
    else
    {
        for(intLoop=0; intLoop<len; intLoop++)
        {
            document.getElementsByTagName("object")[intLoop].style.visibility="hidden";
        }
    }
}

function setPopUpPoistion(popUpId)
{
   var divHeight = 300;
   var divWidth = 200;
  
   if(parseInt(document.getElementById(popUpId).style.height) > 0)
   {
        divHeight = parseInt(document.getElementById(popUpId).style.height);
   }
   else if(parseInt(document.getElementById(popUpId).offsetHeight) > 0)
   {
        divHeight = parseInt(document.getElementById(popUpId).offsetHeight);
   }
        
   if(parseInt(document.getElementById(popUpId).style.width) > 0)
   {
        divWidth = parseInt(document.getElementById(popUpId).style.width);
   }
   else if(parseInt(document.getElementById(popUpId).offsetWidth) > 0)
   {
        divWidth = parseInt(document.getElementById(popUpId).offsetWidth);
   }

   divHeight = (divHeight > 300)? divHeight: 300;
   
   document.getElementById(popUpId).style.top = ((getClientHeight() - divHeight)/2 + getScrollTop() - 70) + "px";
   
   document.getElementById(popUpId).style.left = ((getClientWidth() - divWidth)/2 + document.documentElement.scrollLeft) + "px";
}


function getScrollTop()
{
	var scrollTop;
	

	if(document.body.scrollTop == 0)
	{
	    scrollTop=document.documentElement.scrollTop;
	}
	else
	{
	    scrollTop=document.body.scrollTop;
	}
	return scrollTop;
}

if(checkIE() == true)
{
}
else
{

}

function getClientHeight()
{
    var sTop = 0;
    
    if(parseInt(document.documentElement.clientHeight) > 0)
    {
        sTop = parseInt(document.documentElement.clientHeight);
    }
    else if(parseInt(document.body.clientHeight) > 0)
    {
        sTop = parseInt(document.body.clientHeight);
    } 
    
    return sTop;
}

function displayProgress(bolValue)
{
	try
	{
		if(bolValue)
		{
		    displayDisability(true);
		    $get('divProgress').getElementsByTagName("IMG")[0].src="";
		   //        $get('divProgress').style.visibility='hidden';
		    $get('divProgress').getElementsByTagName("IMG")[0].src="../images/loader.gif";
			$get('divProgress').style.display='';
			setPopUpPoistion('divProgress');
			//$get('divProgress').style.visibility='visible';
		}
		else
		{
			$get('divProgress').style.display='none';
			displayDisability(false);
		}
	}
	catch(err)
	{}
} 


function displayLinkbutton(bolValue)
{
    displayProgress(false);
	try
	{
		if(bolValue)
		{
		      document.getElementById('innerdivViewDetails').style.display=''; 
		      document.getElementById('innerdivViewDetails').style.visibility='hidden'; 
		      setPopUpPoistion('innerdivViewDetails');
		      document.getElementById('innerdivViewDetails').style.visibility='visible'; 
		      setTimeout(function(){displayDisability(true);}, 5);
		}
		else
		{
		    $get('innerdivViewDetails').style.display='none';
			displayDisability(false);
		}
	}
	catch(err)
	{}
} 
function displayupdateevent(bolValue)
{
	try
	{
		if(bolValue)
		{
		    document.getElementById('spnheading').innerHTML = 'Update Event';
			$get('divupdate').style.display='';
			document.getElementById('divupdate').style.visibility='hidden'; 
		    setPopUpPoistion('divupdate');
		    document.getElementById('divupdate').style.visibility='visible'; 
		    setTimeout(function(){displayDisability(true);}, 5);
		}
		else
		{
			$get('divupdate').style.display='none';
			displayDisability(false);
			document.getElementById('spnMessage').innerHTML = 'Event Updated Successfully';
		}
	}
	catch(err)
	{}
}
function displaycreateevent(bolValue)
{
	try
	{
		if(bolValue)
		{ 
		    document.getElementById('ctl00_cphContent_hdneventid').value="";
		    document.getElementById('spnheading').innerHTML = 'Add Event';
			$get('divupdate').style.display='';
			$get('divupdate').style.visibility='hidden';
			setPopUpPoistion('divupdate');
			$get('divupdate').style.visibility='visible';
			setTimeout(function(){displayDisability(true);}, 5);
		}
		else
		{
			$get('divupdate').style.display='none';
			displayDisability(false);
			 document.getElementById('spnMessage').innerHTML = '';
			 document.getElementById('spnMessage').innerHTML = 'Event Created  Successfully';
		}
	}
	catch(err)
	{}
}

 function  GetCheckboxes()
  {
           var blvalue=false; 
          for(var i=0;i<=6;i++)
          {
             var chk=document.getElementById('ctl00_cphContent_chkRepeatOnDay_'+i);
            
             chk.checked=false;
          
          }
          return blvalue; 
  
  }

 



function pageLoad()
{
    //setFooterPosition();
} 

function setFooterPosition()
{
    if($get('divFooter') != null)
    {
        var footer = $get('divFooter');
        var scrollHeight = parseInt($get('divMain').offsetHeight);
        var clientHeight = getClientHeight();
        var _minHeight = 550;
        var _offset = 200;

        clientHeight = clientHeight > parseInt(screen.availHeight)? clientHeight: parseInt(screen.availHeight) - _offset;
        var docBottom =  scrollHeight > clientHeight? scrollHeight: (((clientHeight > _minHeight) && (scrollHeight < _minHeight))? clientHeight: clientHeight);

        $get('divMain').style.height = docBottom - parseFloat(footer.offsetHeight) - 25 + "px"
        footer.style.display ="";
        footer.style.top = docBottom + "px";
    }
}

function CommaFormatted(amount)
{
    var delimiter = ","; // replace comma if desired
    amount = Replace(amount,",","");
    amount = amount + "";
    if(amount.indexOf("0") == 0)
    {
        amount = amount.substr(1, amount.length - 1);
    }
    var a = amount.split('.',2)
    var d = a[1];
    var i = parseInt(a[0]);
    if(isNaN(i)) { return ''; }
    var minus = '';
    if(i < 0) { minus = '-'; }
    i = Math.abs(i);
    var n = new String(i);
    var a = [];
    var len = 3;

    while(n.length > len)
    {
	    var nn = n.substr(n.length-len);
	    a.unshift(nn);
	    n = n.substr(0,n.length-len);
        
	    //len = 2;
    }
    if(n.length > 0) { a.unshift(n); }
    n = a.join(delimiter);
    if(typeof(d) != "undefined")
    {
    if(d.length < 1) { amount = n; }
    else { amount = n + '.' + d; }
    }
    else
    {
    amount = n; 
    }
    amount = minus + amount;
    return amount;
}

function Replace(Text, OldChar, NewChar)
{
	while(Text.indexOf(OldChar) > -1)
	{
		Text = Text.replace(OldChar, NewChar);
	}
	
	return Text;
}

function IsNumeric(inputData)
{
    var NumFilter = /^([0-9])+$/;
     if (NumFilter.test(inputData)) 
      { // nothing 
         return true;
      }
   else 
   return false;
}

function GetRowIndex(Index)
{
    if(Index <= 9)
        Index = "0" + Index;
    return Index;
}

function CheckAll(GridClientId, ControlId, rowCount)
{  
    var intLoop;
    var intIndex=2;

    for(intLoop=0;intLoop<rowCount;intLoop++)
    {
        if($get(GridClientId + "_ctl" + GetRowIndex(intIndex) + "_" + ControlId) != null)
        {
            if($get(GridClientId + "_ctl" + GetRowIndex(intIndex) + "_" + ControlId).disabled != true)
                $get(GridClientId + "_ctl" + GetRowIndex(intIndex) + "_" + ControlId).checked = true;				    
    	}	
	    intIndex=intIndex+1;
    }
  
    return false;
}
     
function ClearAll(GridClientId, ControlId, rowCount)
{
    var intLoop;
    var intIndex=2;

    for(intLoop=0;intLoop<rowCount;intLoop++)
    {
       if($get(GridClientId + "_ctl" + GetRowIndex(intIndex) + "_" + ControlId) != null)
        {
            $get(GridClientId + "_ctl" + GetRowIndex(intIndex) + "_" + ControlId).checked = false;				    
    	}
    	
        intIndex=intIndex+1;
    }
    return false;
}
     
function Check_Delete(GridClientId, ControlId, rowCount)
{			
    var intLoop;
    var intCount = 0;

    for (intLoop = 2;intLoop < rowCount+2; intLoop++)
    {
       if($get(GridClientId + "_ctl" + GetRowIndex(intLoop) + "_" + ControlId).checked == true)
    	    intCount++;		
    }  
	
	if (intCount == 0)
	{
	    alert("Select atleast one record to Delete");
	    return false;
	}
	else
	{
	    return confirm("Are you sure to delete Checked item(s)");
	}					
}

function Check_ChangeStatus(GridClientId, ControlId, rowCount)
{			
    var intLoop;
    var intCount = 0;

    for (intLoop = 2;intLoop < rowCount+2; intLoop++)
    {
        if($get(GridClientId + "_ctl" + GetRowIndex(intLoop) + "_" + ControlId).checked == true)
        intCount++;					
    }  
    
    if (intCount == 0)
    {
        alert("Select atleast one record to change status");
        return false;
    }
    else
    {
        return confirm("Are you sure to change the status of Checked item(s)");
    }					
}
	   
	   
	   
function setDropdownValue(Ddl,setValue)
{
    var length = Ddl.length;
    var intIndex=0;			
    try
    {					
	    for( intIndex=0;intIndex<= length-1; intIndex++)
	    {
			
		    if ( ( Ddl.options[intIndex].value == setValue)  || ( Ddl.options[intIndex].innerHTML == setValue )  )
		    {												
			    Ddl.options[intIndex].selected = true;
			    return true;
		    }						
	    }
	    
	    return false;
    }
    catch(err)
    {
		return false;
    }			
}

function setDropdownText(Ddl,setText)
{
    var length = Ddl.length;
    var intIndex=0;			
    try
    {					
	    for( intIndex=0;intIndex<= length-1; intIndex++)
	    {
			
		    if ( ( Ddl.options[intIndex].text == setText)  || ( Ddl.options[intIndex].innerHTML == setText )  )
		    {												
			    Ddl.options[intIndex].selected = true;
			    return true;
		    }						
	    }
	    
	    return false;
    }
    catch(err)
    {
		return false;
    }			
}

function getDropdownValue(Ddl)
{
    var intIndex=Ddl.selectedIndex;			
    try
    {					
	    return Ddl.options[intIndex].value;
    }
    catch(err)
    {
		return "";
    }			
}

function getDropdownText(Ddl)
{
    var intIndex=Ddl.selectedIndex;			
    try
    {					
	    return Ddl.options[intIndex].text;
    }
    catch(err)
    {
		return "";
    }			
} 
	

function getElementsByClassName(placeHolder, cl)
 {
    var retnode = [];
    var myclass = new RegExp('\\b'+cl+'\\b');
    var elem = placeHolder.getElementsByTagName('*');
    for (var i = 0; i < elem.length; i++) {
    var classes = elem[i].className;
    if (myclass.test(classes)) retnode.push(elem[i]);
    }
    
    return retnode;
}

function displayConfirmation(bolValue)
{
        try
        {
                if(bolValue)
                {
                    $get('divConfirmation').style.display='';
                    $get('divConfirmation').style.visibility='hidden';
                    setPopUpPoistion('divConfirmation');
                    $get('divConfirmation').style.visibility='visible';
                    setTimeout(function(){displayDisability(true);}, 5);
                }
                else
                {
                    $get('divConfirmation').style.display='none';
                    displayDisability(false);
                }
        }
        catch(err)
        {}
} 

function DepartmentStatus(message)
{
    document.getElementById('ctl00_cphContent_lblErrorMessage').innerHTML=message;
    return false;
}


function getClientHeight()
{
    var sTop = 0;
    
    if(parseInt(document.documentElement.clientHeight) > 0)
    {
        sTop = parseInt(document.documentElement.clientHeight);
    }
    else if(parseInt(document.body.clientHeight) > 0)
    {
        sTop = parseInt(document.body.clientHeight);
    } 
    
    return sTop;
}


function getClientWidth()
{
    var sTop = 0;
    
    if(parseInt(document.documentElement.clientWidth) > 0)
    {
        sTop = parseInt(document.documentElement.clientWidth);
    }
    else if(parseInt(document.body.clientWidth) > 0)
    {
        sTop = parseInt(document.body.clientWidth);
    } 
    
    return sTop;
}
function getScrollTop()
{
	var scrollTop;
	

	if(document.body.scrollTop == 0)
	{
	    scrollTop=document.documentElement.scrollTop;
	}
	else
	{
	    scrollTop=document.body.scrollTop;
	}
	return scrollTop;
}

if(checkIE() == true)
{
}
else
{

}
function getScrollHeight()
{
	var scrollHeight;
	

	if(document.body.scrollHeight == 0)
	{
	    scrollHeight=document.documentElement.scrollHeight;
	}
	else
	{
	    scrollHeight=document.body.scrollHeight;
	}
	return scrollHeight;
}




function URLEncode(strString)
{
	if(!window.XMLHttpRequest)
	{
		strString = Replace(strString, "\r\n", "ampltr;" + "BR" + "ampgtr;");
	}
	else
	{
		strString = Replace(strString, "\n", "ampltr;" + "BR" + "ampgtr;");
	}
	strString = Replace(strString, "&", "amp;");
	strString = Replace(strString, "<", "ampltr;");
	strString = Replace(strString, ">", "ampgtr;");
	return strString;
}

function URLDecode(strString)
{
	if(checkIE()==true)
	{
		strString = Replace(strString,"<BR>","\r\n");
	}
	else
	{
		strString = Replace(strString, "<BR>","\n");
	}
	
	return strString;
}


function displayconfirmation(bolValue)
{
	try
	{
	
		if(bolValue)
		{   
		    document.getElementById('spnheading').innerHTML = 'Ask Question';
			$get('divupdate').style.display='';
			$get('divupdate').style.visibility='hidden';
            setPopUpPoistion('divupdate');
            $get('divupdate').style.visibility='visible';
		}
		else
		{
			document.getElementById('spnMessage').innerHTML = 'Your Question has been sent to the admin.';
			document.getElementById('ctl00_cphContent_divConfirmation').style.display ='';
			setPopUpPoistion('ctl00_cphContent_divConfirmation');
			document.getElementById('divupdate').style.display='none';
		    document.getElementById('spnheading').innerHTML = 'Confirmation';
			
		}
	}
	catch(err)
	{}
	finally
	{
		    displayDisability(true);		   
	}
}
function displaycreateevent(bolValue)
{
	try
	{
		if(bolValue)
		{ 
		    document.getElementById('ctl00_cphContent_hdneventid').value="";
		    document.getElementById('spnheading').innerHTML = 'Add Event';
		    displayDisability(true);
			$get('divupdate').style.display='';
			setPopUpPoistion('divupdate');
			$get('divupdate').style.visibility='visible';
		}
		else
		{
			$get('divupdate').style.display='none';
			displayDisability(false);
			 document.getElementById('spnMessage').innerHTML = '';
			 document.getElementById('spnMessage').innerHTML = 'Event Created  Successfully';
		}
	}
	catch(err)
	{}
}



function URLEncode(strString)
{
	if(!window.XMLHttpRequest)
	{
		strString = Replace(strString, "\r\n", "ampltr;" + "BR" + "ampgtr;");
	}
	else
	{
		strString = Replace(strString, "\n", "ampltr;" + "BR" + "ampgtr;");
	}
	strString = Replace(strString, "&", "amp;");
	strString = Replace(strString, "<", "ampltr;");
	strString = Replace(strString, ">", "ampgtr;");
	return strString;
}

function URLDecode(strString)
{
	if(checkIE()==true)
	{
		strString = Replace(strString,"<BR>","\r\n");
	}
	else
	{
		strString = Replace(strString, "<BR>","\n");
	}
	
	return strString;
}

function getFormmatedDate(objDate)
{
    var date = new Date(objDate);
    var retValue = "";
    
    retValue = (date.getMonth() + 1) >  9? (date.getMonth() + 1): "0" + (date.getMonth() + 1);
    retValue += "/" + (date.getDate() >  9? date.getDate(): "0" + date.getDate());
    retValue += "/" + date.getFullYear();
        
    return retValue.toString();
}



function displayConfirmationMessage(bolValue, message, bttext, backURL)
{
        try
        {
                if(bolValue)
                {
                    $get("spnMessage").innerHTML = message;
                    $get('divConfirmation').style.display='';
                    $get('divConfirmation').style.visibility='hidden';
                    setPopUpPoistion('divConfirmation');
                    $get('divConfirmation').style.visibility='visible';
                    setTimeout(function(){displayDisability(true);}, 5);
                    
                    if(bttext != "")
                    {
                        $get("btnClose").value = bttext;
                        $get("btnClose").onclick = function(){location.href = backURL};
                    }
                }
                else
                {
                    $get('divConfirmation').style.display='none';
                    displayDisability(false);
                }
        }
        catch(err)
        {}
} 


function UnSelectOtherRadiosInGroup(radio)
{
    var dlRadioContainer = radio.parentNode.parentNode.parentNode.parentNode.parentNode;
    var intLoop;
    var arrRadios = dlRadioContainer.getElementsByTagName("INPUT");

    for(intLoop=0; intLoop<arrRadios.length; intLoop++)
    {
        if(arrRadios[intLoop].type.toLowerCase() == "radio")
        {
            if(arrRadios[intLoop] != radio)
            {
                arrRadios[intLoop].checked = false;
            }
        }
    }
}