// JScript File
var objPatternName;
var objCheckPattern;
function ValidShiftPatternName(patternName,AutoID,PatternNameExist)
{
var PName;
PName=PatternNameExist;
   if(window.ActiveXObject)
    {    
        try
        {
            objPatternName = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
            try
            {
                objPatternName = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e1)
            {
                objPatternName = null;
            }
        }
    }  
     else if(window.XMLHttpRequest)
     {
        try
        {
            objPatternName = new XMLHttpRequest("Msxml2.XMLHTTP");
        }
        catch(e)
        {
            try
            {
                objPatternName = new XMLHttpRequest("Microsoft.XMLHTTP");
            }
            catch(e1)
            {
                objPatternName = null;
            }
        }
     }    
//	try
//	{
//		objPatternName = new XmlHttpRequest();
//	}
//	catch(e)
//	{
//		try
//		{
//			objPatternName = new ActiveXObject("Microsoft.XMLHTTP");
//		}
//		catch(e1)
//		{
//			objPatternName = new ActiveXObject("Msxml2.XMLHTTP");
//		}
//	}
	if(objPatternName != null)
	{
		if(patternName != "")
		{
		    if(AutoID=='XYZ')
		    {
		       if(window.ActiveXObject)
                {
		            objPatternName.onreadystatechange = ProcessTheResponsePatternNameValid;		
		            objPatternName.open("GET","AjaxPatternNameValid.aspx?PatternName=" + patternName ,true)
		            objPatternName.send(null);
		        }
		        else if(window.XMLHttpRequest)
                {
                    objPatternName.open("GET","AjaxPatternNameValid.aspx?PatternName=" + patternName ,false)
                    objPatternName.send(null);
                    objPatternName.onreadystatechange = ProcessTheResponsePatternNameValid();		
                }
    		}
    		else
    		{    		    
    		    if(window.ActiveXObject)
                {
    		        objPatternName.onreadystatechange = ProcessTheResponsePatternNameValid;		
		            objPatternName.open("POST","AjaxPatternNameValid.aspx?PatternName=" + patternName +"&AutoID="+AutoID+"" ,true);
		            objPatternName.send(null);
		        }
		        else if(window.XMLHttpRequest)
                {
		            objPatternName.open("POST","AjaxPatternNameValid.aspx?PatternName=" + patternName +"&AutoID="+AutoID+"" ,false);
		            objPatternName.send(null);
		            objPatternName.onreadystatechange = ProcessTheResponsePatternNameValid();		
                }
    		}    
		} 
	}
	return false;
}
function ProcessTheResponsePatternNameValid()
{ 
	if (objPatternName.readyState == 4)
	{	           
		if(objPatternName.status == 200)
		{            
            var response=objPatternName.responseText;            
            if (response=="Success")
             {
             }
            if (response=="Fail")
             {              
                //alert("Pattern Name Already Exists !");
alert(PatternNameExist);
                document.getElementById('ctl00_BodyContentPH_lblPattern_Name').focus();
             }
         }
	}
}
function CheckShiftPatternTime2(totCtrl)
{
   if(window.ActiveXObject)
    {    
        try
        {
            objCheckPattern = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
            try
            {
                objCheckPattern = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e1)
            {
                objCheckPattern = null;
            }
        }
    }  
     else if(window.XMLHttpRequest)
     {
        try
        {
            objCheckPattern = new XMLHttpRequest("Msxml2.XMLHTTP");
        }
        catch(e)
        {
            try
            {
                objCheckPattern = new XMLHttpRequest("Microsoft.XMLHTTP");
            }
            catch(e1)
            {
                objCheckPattern = null;
            }
        }
     }    
//    try
//	{
//		objCheckPattern = new XmlHttpRequest();
//	}
//	catch(e)
//	{
//		try
//		{
//			objCheckPattern = new ActiveXObject("Microsoft.XMLHTTP");
//		}
//		catch(e1)
//		{
//			objCheckPattern = new ActiveXObject("Msxml2.XMLHTTP");
//		}
//	}
    if(objCheckPattern!=null)
	{
	    for(i=1;i<=totCtrl;i++)
	    {
	        shift1ID = document.getElementById("ctl00_BodyContentPH_ddl_Pattern" + i ).value;
	        if (i==totCtrl)
	        {
	            shift2ID = document.getElementById("ctl00_BodyContentPH_ddl_Pattern" + 1 ).value;
	        }
	        else
	        {
	            shift2ID = document.getElementById("ctl00_BodyContentPH_ddl_Pattern" + (parseInt(i) + parseInt(1)) ).value;
	        }
	        if (shift1ID=='-Select-')
	            shift1ID=0;
	        if (shift2ID=='-Select-')
	         shift2ID=0;
	        if(window.ActiveXObject)
            {
	            objCheckPattern.onreadystatechange = ResponseCheckShiftTime;
	            objCheckPattern.open("POST", "../Masters/ShiftPatternRemote.aspx?shift1ID="+ shift1ID + "&shift2ID="+ shift2ID,  false);
		        objCheckPattern.send(null);
		    }
		    else if(window.XMLHttpRequest)
            {
                objCheckPattern.open("POST", "../Masters/ShiftPatternRemote.aspx?shift1ID="+ shift1ID + "&shift2ID="+ shift2ID,  false);
                objCheckPattern.send(null);
                objCheckPattern.onreadystatechange = ResponseCheckShiftTime();
            }
		}
	}
}
function CheckShiftPatternTime1(shift1ID,shift2ID)
{
    if(window.ActiveXObject)
    {    
        try
        {
            objCheckPattern = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
            try
            {
                objCheckPattern = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e1)
            {
                objCheckPattern = null;
            }
        }
    }  
     else if(window.XMLHttpRequest)
     {
        try
        {
            objCheckPattern = new XMLHttpRequest("Msxml2.XMLHTTP");
        }
        catch(e)
        {
            try
            {
                objCheckPattern = new XMLHttpRequest("Microsoft.XMLHTTP");
            }
            catch(e1)
            {
                objCheckPattern = null;
            }
        }
     }    
//    try
//	{
//		objCheckPattern = new XmlHttpRequest();
//	}
//	catch(e)
//	{
//		try
//		{
//			objCheckPattern = new ActiveXObject("Microsoft.XMLHTTP");
//		}
//		catch(e1)
//		{
//			objCheckPattern = new ActiveXObject("Msxml2.XMLHTTP");
//		}
//	}
    if(objCheckPattern!=null)
	{
//	    for(i=1;i<=totCtrl;i++)
//	    {
//	       
//	        shift1ID = document.getElementById("ctl00_BodyContentPH_ddl_Pattern" + i ).value;
//	       
//	        if (i==totCtrl)
//	        {
//	            shift2ID = document.getElementById("ctl00_BodyContentPH_ddl_Pattern" + 1 ).value;
//	        }
//	        else
//	        {
//	       
//	            shift2ID = document.getElementById("ctl00_BodyContentPH_ddl_Pattern" + (parseInt(i) + parseInt(1)) ).value;
//	        }
//	        if (shift1ID=='-Select-')
//	            shift1ID=0;
//	            
//	        if (shift2ID=='-Select-')
//	            shift2ID=0;
            var rndValue=Math.floor(Math.random()*111);
            if(window.ActiveXObject)
            {
	            objCheckPattern.onreadystatechange = ResponseCheckShiftTime;
	            objCheckPattern.open("POST", "../Masters/ShiftPatternRemote.aspx?shift1ID="+ shift1ID + "&shift2ID="+ shift2ID +"&rndValue="+rndValue,  false);
		        objCheckPattern.send(null);
		    }
		    else if(window.XMLHttpRequest)
            {
	            objCheckPattern.open("POST", "../Masters/ShiftPatternRemote.aspx?shift1ID="+ shift1ID + "&shift2ID="+ shift2ID +"&rndValue="+rndValue,  false);
		        objCheckPattern.send(null);
		        objCheckPattern.onreadystatechange = ResponseCheckShiftTime();
            }
//		}
	}
}
function CheckShiftPatternTime(shiftValue)
{
    if(window.ActiveXObject)
    {    
        try
        {
            objCheckPattern = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
            try
            {
                objCheckPattern = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e1)
            {
                objCheckPattern = null;
            }
        }
    }  
     else if(window.XMLHttpRequest)
     {
        try
        {
            objCheckPattern = new XMLHttpRequest("Msxml2.XMLHTTP");
        }
        catch(e)
        {
            try
            {
                objCheckPattern = new XMLHttpRequest("Microsoft.XMLHTTP");
            }
            catch(e1)
            {
                objCheckPattern = null;
            }
        }
     }    
//    try
//	{
//		objCheckPattern = new XmlHttpRequest();
//	}
//	catch(e)
//	{
//		try
//		{
//			objCheckPattern = new ActiveXObject("Microsoft.XMLHTTP");
//		}
//		catch(e1)
//		{
//			objCheckPattern = new ActiveXObject("Msxml2.XMLHTTP");
//		}
//	}
    if(objCheckPattern!=null)
	{
        var rndValue=Math.floor(Math.random()*111);
        if(window.ActiveXObject)
        {
            objCheckPattern.onreadystatechange = ResponseCheckShiftTime;
            objCheckPattern.open("POST", "../Masters/ShiftPatternRemote.aspx?shiftValue="+ shiftValue +"&rndValue="+rndValue,  false);
	        objCheckPattern.send(null);
	    }
	    else if(window.XMLHttpRequest)
        {
            objCheckPattern.open("POST", "../Masters/ShiftPatternRemote.aspx?shiftValue="+ shiftValue +"&rndValue="+rndValue,  false);
	        objCheckPattern.send(null);
	        objCheckPattern.onreadystatechange = ResponseCheckShiftTime();
        }
	}
}
function ResponseCheckShiftTime()
{
    if (objCheckPattern.readyState == 4)
	{	           	
		if(objCheckPattern.status == 200)
		{    
		 var response=objCheckPattern.responseText;                        
            if (response=="Success")
             {
                    // no overlapping of shift time   
                    document.getElementById("hidFlag").value=0;
                    return 1;
             }
           else
           {
              // over laps of the shift time
               document.getElementById("hidFlag").value=response;
               alert(response);
               return 0;
           }          
		}
	}
}
