﻿// JScript File
/**************************************************************************************/
//This is common javascript file used to check all kind of validations, returns etc.
//this file is include in all the masters file.
/**************************************************************************************/
//This fucntion is always return false inspite of browser is used
 function returnFalse()
 {
    if (navigator.appName.indexOf("Microsoft")>=0)
    {
        event.returnValue=false;
    }
    else
    {
        return false;
    }
 }

///This function is use to trim the input value
function Trim(TRIM_VALUE){
            if(TRIM_VALUE.length < 1){
            return"";
            }
            TRIM_VALUE = RTrim(TRIM_VALUE);
            TRIM_VALUE = LTrim(TRIM_VALUE);
            if(TRIM_VALUE==""){
            return "";
            }
            else{
            return TRIM_VALUE;
            }
            } //End Function

            function RTrim(VALUE){
            var w_space = String.fromCharCode(32);
            var v_length = VALUE.length;
            var strTemp = "";
            if(v_length < 0){
            return"";
            }
            var iTemp = v_length -1;

            while(iTemp > -1){
            if(VALUE.charAt(iTemp) == w_space){
            }
            else{
            strTemp = VALUE.substring(0,iTemp +1);
            break;
            }
            iTemp = iTemp-1;

            } //End While
            return strTemp;

            } //End Function

            function LTrim(VALUE){
            var w_space = String.fromCharCode(32);
            if(v_length < 1){
            return"";
            }
            var v_length = VALUE.length;
            var strTemp = "";

            var iTemp = 0;

            while(iTemp < v_length){
            if(VALUE.charAt(iTemp) == w_space){
            }
            else{
            strTemp = VALUE.substring(iTemp,v_length);
            break;
            }
            iTemp = iTemp + 1;
            } //End While
            return strTemp;
            } //End Function
            
    /**************/
    // This function is used to check all the checkboxes provided in the grid.
    /*****************/
    function Chkall(ctrlChk1)
    {   
        var selectChk=document.getElementById(ctrlChk1); 
        var chkBox=document.getElementsByName("chk");
        if (selectChk.checked)
        {
            for(var iCount=0;iCount<chkBox.length;iCount++)
            {
                document.getElementsByName("chk")[iCount].checked = true ;
            }
        }
        else
        {
            for(var iCount=0;iCount<chkBox.length;iCount++)
            {
                document.getElementsByName("chk")[iCount].checked = false ;
            }
        }
     }   
   
   function fnChangeColor(lcase,ctrl)
   {
        if(lcase=="Over")
        {
            ctrl.style.backgroundColor="#E1E1E1";
        }
        else if(lcase=="Out")
        {
            ctrl.style.backgroundColor="#c8c7c2";
        }
   }
   function fnChangeImg(lcase,ctrl,imgname)
   {
        if(lcase=="Over")
        {
            ctrl.src=appPath+"/Images/MenuImg/"+imgname ;
        }
        else if(lcase=="Out")
        {
            ctrl.src=appPath+"/Images/MenuImg/"+imgname ;
        }
   }
   
   
   function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}
// common AJAX code fro all Admin master pages
var ctrl;
var commonRequest;
var commonResponse;
    function xmlError(e) 
		{
		//if there was an error, show the user
			alert(e);
		}
		
	function CommonInitializeRequest()
	{
		try
		{
			commonRequest= new ActiveXObject("Microsoft.XMLHTTP");//Try creating an XMLHTTP Object
		}
		catch(Ex)
		{
			try
			{
				commonRequest = new ActiveXObject("Microsoft.XMLHTTP");//First failure, try again creating an XMLHTTP Object
			}
			catch(Ex)
			{
				commonRequest = null;//Else assign null to request
			}
		}
		if(!commonRequest && typeof XMLHttpRequest != 'undefined')
		{
			commonRequest = new XMLHttpRequest();
		}
	}
	
	function CommonSendRequest(loc)
	{
	    //ctrl=document.getElementById(id);
	    //var d =new Date();
	    CommonInitializeRequest();//Call InitializeRequest to set request object
	    var dt =new Date();
		var url = sPath+"/Admin/Services/"+loc+"&dt="+dt.getSeconds();//Create the url to send the request to
		//url=sPath+"/Test.aspx";
		//alert(url);
		commonRequest.onreadystatechange = CommonProcessRequestState;//Delegate ProcessRequest to onreadystatechange property so it gets called for every change in readyState value
		commonRequest.open("GET", url, true);//Open a GET request to the URL
		commonRequest.send(null);//Send the request with a null body.
		
	}
	function CommonProcessRequestState()
	{   
		if(commonRequest.readyState == 4)//If the readyState is in the "Ready" Country
		{  
			if(commonRequest.status == 200)//If the returned status code was 200. Everything was OK.
			{
				if(commonRequest.responseText != "")//If responseText is not blank
				{
				 //alert(commonRequest.responseText);
				}
				else
				{
				}
			}
		}
		return true;//return
	}

function chkForUnchk(ctrl,ctrlchk)
{
    if (ctrl.checked==false)
    {
        document.getElementById(ctrlchk).checked=false;
    }
}

/****************Calendar Function ************************/

function calendarPicker(strField, e)
{   
    if (!e) e=window.event;
    var top;
    var left;
    if (navigator.appName.toLowerCase().indexOf("microsoft")>=0)
    {
        top=e.clientY+70;
        left=e.clientX+15;
        if (left>=document.body.offsetWidth-260)
        {
            left=document.body.offsetWidth-260;
        }
        if (top>=document.body.offsetHeight-160)
        {
            top=document.body.offsetHeight-160;
        }

    }
    else
    {
        top=e.pageY+20;
        left=e.pageX+10;
    }
    window.open('<%=Application("sPath")%>/calender.aspx?field=' + strField, 'calendarPopup', 'width=250,height=190,resizable=yes,top='+ top +',left=' + left);
}


////Get Date Format Functions

function getCalendarDate()
{
   var months = new Array(13);
   months[0]  = "January";
   months[1]  = "February";
   months[2]  = "March";
   months[3]  = "April";
   months[4]  = "May";
   months[5]  = "June";
   months[6]  = "July";
   months[7]  = "August";
   months[8]  = "September";
   months[9]  = "October";
   months[10] = "November";
   months[11] = "December";
   var now         = new Date();
   var monthnumber = now.getMonth();
   var monthname   = months[monthnumber];
   var monthday    = now.getDate();
   var year        = now.getYear();
   if(year < 2000) { year = year + 1900; }
   var dateString = monthname +
                    ' ' +
                    monthday +
                    ', ' +
                    year;
   return dateString;
}  
 

function getClockTime()
{
   var now    = new Date();
   var hour   = now.getHours();
   var minute = now.getMinutes();
   var second = now.getSeconds();
   var ap = "AM";
   if (hour   > 11) { ap = "PM";             }
   if (hour   > 12) { hour = hour - 12;      }
   if (hour   == 0) { hour = 12;             }
   if (hour   < 10) { hour   = "0" + hour;   }
   if (minute < 10) { minute = "0" + minute; }
   if (second < 10) { second = "0" + second; }
   var timeString = hour +
                    ':' +
                    minute +
                    ':' +
                    second +
                    " " +
                    ap;
   return timeString;
} // function getClockTime()


//Master Page Scripting

    var Display;
    if(navigator.appName.indexOf("Microsoft")>=0)
        Display="block";
    else
        Display="";
function fnCheckSubmitMaster()
{  
   if(submitValid==1)
        {submitValid=0;return false;}
   else
        return true;
}
function Chkall()
{   
    var selectChk=document.getElementById("SelectChk"); 
    var selectChkDown=document.getElementById("SelectChkDown"); 
    var chkBox=document.getElementsByName("chk");
    if (selectChk.checked || selectChkDown.checked)
    {
    for(var iCount=0;iCount<chkBox.length;iCount++)
        {
            document.getElementsByName("chk")[iCount].checked = true ;
        }
    }
    else
    {
    for(var iCount=0;iCount<chkBox.length;iCount++)
        {
            document.getElementsByName("chk")[iCount].checked = false ;
        }
    }
 } 
      function fnDateOne(lsdateOne)
	{
		if (isDate(lsdateOne,"d/M/yyyy")==false)
		{
			alert("Invalid Date Selection");
			return false;
		}
	}
	function fnDateTwo(lsdateOne,lsdateTwo)
	{
		if (isDate(lsdateOne,"d/M/yyyy") && isDate(lsdateTwo,"d/M/yyyy"))
		{
			return true;
		}
		else
		{
			alert("Invalid Date Selection");
			return false;
		}
	}
	function fnChkDate(lsDate1,lsDate2)
	{	
		//Return 0 when d1==d2
		// Return 1 when d1>d2
		// Return -1 if d1=0 or d2=0
		
		if (compareDates(lsDate1,"d/M/yyyy",lsDate2,"d/M/yyyy")==1)
		{	
			alert("Date taken should be less than future date");
			return false;
		}
		else
			if (compareDates(lsDate1,"d/M/yyyy",lsDate2,"d/M/yyyy")==-1)
			{	
				alert("Date taken should be in proper format");
				return false;
			}
	}
function calendarPicker(strField, e)
{   
    if (!e) e=window.event;
    var top;
    var left;
    if (navigator.appName.toLowerCase().indexOf("microsoft")>=0)
    {
        top=e.clientY+70;
        left=e.clientX+15;
        if (left>=document.body.offsetWidth-260)
        {
            left=document.body.offsetWidth-260;
        }
        if (top>=document.body.offsetHeight-160)
        {
            top=document.body.offsetHeight-160;
        }
    }
    else
    {
        top=e.pageY+20;
        left=e.pageX+10;
    }
    window.open('<%=Application("sPath")%>/calender.aspx?field=' + strField, 'calendarPopup', 'width=250,height=190,resizable=yes,top='+ top +',left=' + left);
}
function fnCheckForChecked(ctrl,btnName)
{   var i;var chk=1;submitValid=1;
    //alert(submitValid=1);
    for(i=0;i<document.getElementsByName("chk").length;i++)
    {if(document.getElementsByName("chk")[i].checked==true) {chk=0;break;}}
    if (chk==1)
    {alert("Select any record to continue.");if(navigator.appName.indexOf("Microsoft")>=0) {event.returnvalue=false;} else {return false;}}
    else if(btnName=="Edit")
        {submitValid=0; return true;} //ctrl.click();}
    else if(window.confirm(btnName+" this record?")==true)
        {submitValid=0;ctrl.click();}
    else
        {submitValid=1;if(navigator.appName.indexOf("Microsoft")>=0) {event.returnvalue=false;} else {return false;}}
}    

     function chkRequiredKeyword()
     {
        if(document.getElementById("tbxSearch").value=="")
        {
            alert("Keyword is mandatory.");
            document.getElementById("tbxSearch").focus();
            submitValid=1;
            return false;
        }
        else
        {
            submitValid=0;return true;
        }

     }
  