objDateAndTime = new String();
objDate = new String();
objTime = new String();
objAtt = new String();
function convertTime(time)
{
	time=time.replace(' ','');
	if(time.indexOf('AM') == 4 || time.indexOf('AM') == 5 || time.indexOf('AM') == 6)
	{
		time = time.replace('AM','')
		if(time.indexOf('12') == 0)
		{
			time=time.replace(':','')
			newtime=time.replace('12','00')

		}
		else
		{
		  	newtime= parseFloat(time.replace(':','.'))*100
		}
	}
	if(time.indexOf('PM') == 4 || time.indexOf('PM') == 5 || time.indexOf('PM') == 6)
	{
		time = time.replace('PM','')
		time=time.replace(':','.')
		if(time.indexOf('12') != 0)
		{
			newtime= (parseFloat(time)*100)+1200
		}
		else
		{
			newtime= parseFloat(time)*100
		}
	}
	return newtime;
}
function CompareTime(PrevStartTime,PrevEndTime,CurrStartTime,CurrEndTime)
{
	if((CurrStartTime == PrevStartTime  && CurrEndTime == PrevEndTime) || (CurrStartTime == PrevStartTime) || (CurrEndTime == PrevEndTime))
	{
		return false;
	}
	else if(CurrStartTime > PrevStartTime && CurrStartTime < PrevEndTime)
	{
		return false;
	}
	else if (CurrEndTime > PrevStartTime && CurrEndTime < PrevEndTime)
	{
		return false;
	}
	else if (PrevStartTime > CurrStartTime && PrevEndTime < CurrEndTime)
	{
		return false;
	}
	else
	{
		return true;
	}
}
function DisplaySelectedSeminars(SeminarID,SeminarDate,SeminarTime,SeminarAttendee,Break,attID)
{
	var summitid = document.getElementById("ctl00_CPHPageContent_HdnSummitID").value
	var strSemAtt=SeminarAttendee;
	var Att_Sem_arr=strSemAtt.split(',');
	for(x=0; x<Att_Sem_arr.length; x++)
	{
		res = Select.GetBreak(summitid,SeminarDate,SeminarTime)
		if(res.value != "false")
		{
			if(res.value != "false")
			{
				if(document.getElementById("Break_"+res.value+"_"+attID)!= null)
				{
					document.getElementById("Break_"+res.value+"_"+attID).style.display="block";
				}
			}
		}
		if(Break == "Y")
		{
			document.getElementById("Break_"+Att_Sem_arr[x]).style.display="block";
		}
		document.getElementById("imgBtnRedSeminar_"+Att_Sem_arr[x]).style.display="none";
		document.getElementById("imgBtnGreenSeminar_"+Att_Sem_arr[x]).style.display="block";
		var attID=Att_Sem_arr[x].split('_')
		var dattime=SeminarDate+"@"+SeminarTime;

		if(document.getElementById("selecteddate_"+attID[1])!= null && document.getElementById("selecteddate_"+attID[1]).value!="")
		{
			document.getElementById("selecteddate_"+attID[1]).value = document.getElementById("selecteddate_"+attID[1]).value+','+dattime;
		}
		else
		{
			document.getElementById("selecteddate_"+attID[1]).value = dattime;
		}
		document.getElementById("selectedtime_"+attID[1]).value = document.getElementById("selectedtime_"+attID[1]).value+','+SeminarTime;

		if(document.getElementById("selectedseminar_"+attID[1]).value != "")
		{
			document.getElementById("selectedseminar_"+attID[1]).value=document.getElementById("selectedseminar_"+attID[1]).value+","+SeminarID;
		}
		else
		{
			document.getElementById("selectedseminar_"+attID[1]).value=SeminarID;
		}
		document.getElementById("ctl00_CPHPageContent_HdnShowSelectedSeminars").value="";
	}
}
 function SplitDate(datey) { 
	 var Str = new Array();
	 
	 Str = datey.split('/'); 
	 return Str[0]+"/" + Str[1]+ "/" + Str[2];
	 
	 }
function RedSelectedSeminar(chkVal,valSeminarTime,valSeminarDate,chkattval,valbreak)
{
	var cd = new Date(); 
	var curr_date = cd.getDate();
	
	var curr_month = cd.getMonth(); 
	curr_month++;
	
	var curr_year = cd.getFullYear(); 
	var CurrentDate = curr_month + "/" + curr_date + "/" + curr_year;
	
	var todayDate =  SplitDate(CurrentDate);
	var valSeminarDate =  SplitDate(valSeminarDate);
	 var currentdate=Date.parse(todayDate);
	var semdate=Date.parse(valSeminarDate);
	
if(semdate<currentdate)
{

var answer = confirm ("This seminar already took place. Do you still want to select it?")
	if (answer)
	{
	objSeminarID= new String();
		var strBeginDateAndTime = "";
		var strSearchDateAndTime = "";
		var setFlagDateAndTime = "";
		var strseminarid="";
		setFlagDateAndTime=false;
		var eventType=document.getElementById("ctl00_CPHPageContent_HdnEventType").value;
		if(objDateAndTime !="")
		{
			strBeginDateAndTime = objDateAndTime;
		}
		strSearchDateAndTime = "'"+valSeminarDate+"~"+valSeminarTime+"'"+chkattval;
		//alert(valSeminarDate);
		var temDate = new Array();
		temDate = document.getElementById("selecteddate_"+chkattval).value.split(',');
		var temTime = new Array();
		var temdattime = new Array();
		var temAttID = new Array();
		temAttID = objAtt.split(',');
		for(var z=0;z<temDate.length;z++)
		{
			temdattime=temDate[z].split('@')
			//alert(temdattime[0] )
			if(temdattime[0] == valSeminarDate)
			{
			    //alert("Equal")
				var prevseltime= temdattime[1].replace(' ','')
				var tempprevTime = new Array();
				tempprevTime=prevseltime.split('-');
				var seltime= valSeminarTime.replace(' ','');
				var tempTime = new Array();
				tempTime=seltime.split('-');
				if(!CompareTime(convertTime(tempprevTime[0]),convertTime(tempprevTime[1]),convertTime(tempTime[0]),convertTime(tempTime[1])))
				{
					setFlagDateAndTime = true;
				}
				//alert(setFlagDateAndTime)
			}
		}
		if(setFlagDateAndTime)
		{
			if(eventType.trim()=="W")
		         {
		          alert(" You are trying to register for two videos taking place at the same time.\n Please select only one video for each time slot");
			  return false;
		         }
		         else
		          {
		           alert(" You are trying to register for two seminars taking place at the same time.\n Please select only one seminar for each time slot");
			   return false;
		          }
		}
		else
		{
			objDateAndTime = objDateAndTime+",'"+valSeminarDate+"~"+valSeminarTime+"'"+chkattval;
			objDate=objDate+","+valSeminarDate;
			var dattime =valSeminarDate+"@"+valSeminarTime
			document.getElementById("selecteddate_"+chkattval).value=document.getElementById("selecteddate_"+chkattval).value+","+dattime;
			objTime=objTime+","+valSeminarTime;
			document.getElementById("selectedtime_"+chkattval).value=document.getElementById("selectedtime_"+chkattval).value+","+valSeminarTime;
			objAtt=objAtt+","+chkattval;
	
		}
	
		if(document.getElementById("selectedseminar_"+chkattval).value != "")
		{
			document.getElementById("selectedseminar_"+chkattval).value=document.getElementById("selectedseminar_"+chkattval).value+","+chkVal;
		}
		else
		{
			document.getElementById("selectedseminar_"+chkattval).value=chkVal;
		}
		document.getElementById("imgBtnGreenSeminar_"+chkVal+"_"+chkattval).style.display="block";
		document.getElementById("imgBtnRedSeminar_"+chkVal+"_"+chkattval).style.display="none";
		if(document.getElementById("selectedseminar_"+chkattval).value != null)
		{
		    //alert("Select Value"+SelectBreak(chkattval,valSeminarDate,valSeminarTime))
			if(SelectBreak(chkattval,valSeminarDate,valSeminarTime))
			{
				Select.UpdateSeminartoAttendee(chkattval,document.getElementById("selectedseminar_"+chkattval).value,callbackdesc)
			}
		}
	
	  return true
	  }
	else
	{
	return false;
	}
	
}	
else
{
	

	
	objSeminarID= new String();
	var strBeginDateAndTime = "";
	var strSearchDateAndTime = "";
	var setFlagDateAndTime = "";
	var strseminarid="";
	setFlagDateAndTime=false;
	var eventType=document.getElementById("ctl00_CPHPageContent_HdnEventType").value;
	if(objDateAndTime !="")
	{
		strBeginDateAndTime = objDateAndTime;
	}
	strSearchDateAndTime = "'"+valSeminarDate+"~"+valSeminarTime+"'"+chkattval;
	//alert(valSeminarDate);
	var temDate = new Array();
	temDate = document.getElementById("selecteddate_"+chkattval).value.split(',');
	var temTime = new Array();
	var temdattime = new Array();
	var temAttID = new Array();
	temAttID = objAtt.split(',');
	for(var z=0;z<temDate.length;z++)
	{
		temdattime=temDate[z].split('@')
		//alert(temdattime[0] )
		if(temdattime[0] == valSeminarDate)
		{
		    //alert("Equal")
			var prevseltime= temdattime[1].replace(' ','')
			var tempprevTime = new Array();
			tempprevTime=prevseltime.split('-');
			var seltime= valSeminarTime.replace(' ','');
			var tempTime = new Array();
			tempTime=seltime.split('-');
			if(!CompareTime(convertTime(tempprevTime[0]),convertTime(tempprevTime[1]),convertTime(tempTime[0]),convertTime(tempTime[1])))
			{
				setFlagDateAndTime = true;
			}
			//alert(setFlagDateAndTime)
		}
	}
	if(setFlagDateAndTime)
	{
		if(eventType.trim()=="W")
	         {
	          alert(" You are trying to register for two videos taking place at the same time.\n Please select only one video for each time slot");
		  return false;
	         }
	         else
	          {
	           alert(" You are trying to register for two seminars taking place at the same time.\n Please select only one seminar for each time slot");
		   return false;
	          }
	}
	else
	{
		objDateAndTime = objDateAndTime+",'"+valSeminarDate+"~"+valSeminarTime+"'"+chkattval;
		objDate=objDate+","+valSeminarDate;
		var dattime =valSeminarDate+"@"+valSeminarTime
		document.getElementById("selecteddate_"+chkattval).value=document.getElementById("selecteddate_"+chkattval).value+","+dattime;
		objTime=objTime+","+valSeminarTime;
		document.getElementById("selectedtime_"+chkattval).value=document.getElementById("selectedtime_"+chkattval).value+","+valSeminarTime;
		objAtt=objAtt+","+chkattval;

	}

	if(document.getElementById("selectedseminar_"+chkattval).value != "")
	{
		document.getElementById("selectedseminar_"+chkattval).value=document.getElementById("selectedseminar_"+chkattval).value+","+chkVal;
	}
	else
	{
		document.getElementById("selectedseminar_"+chkattval).value=chkVal;
	}
	document.getElementById("imgBtnGreenSeminar_"+chkVal+"_"+chkattval).style.display="block";
	document.getElementById("imgBtnRedSeminar_"+chkVal+"_"+chkattval).style.display="none";
	if(document.getElementById("selectedseminar_"+chkattval).value != null)
	{
	    //alert("Select Value"+SelectBreak(chkattval,valSeminarDate,valSeminarTime))
		if(SelectBreak(chkattval,valSeminarDate,valSeminarTime))
		{
			Select.UpdateSeminartoAttendee(chkattval,document.getElementById("selectedseminar_"+chkattval).value,callbackdesc)
		}
	}
	
	
	}
}
function GreenSelectedSeminar(chkVal,valSeminarTime,valSeminarDate,chkattval,valbreak)
{
	//alert("2"+valSeminarDate)
	var valRepSemDateAndTime="";
	var RepSemDate="";
	var RepSemTime="";
	var dattime =valSeminarDate+"@"+valSeminarTime
	valRepSemDateAndTime =",'"+valSeminarDate+"~"+valSeminarTime+"'"+chkattval;
	RepSemDate =","+valSeminarDate;
	RepSemTime =","+valSeminarTime;
	RepAttID=","+chkattval;
	objDateAndTime = objDateAndTime.replace(valRepSemDateAndTime,'');
	objDate = objDate.replace(RepSemDate,'');
	document.getElementById("selecteddate_"+chkattval).value = document.getElementById("selecteddate_"+chkattval).value.replace(dattime,'');
	objTime = objTime.replace(RepSemTime,'');
	document.getElementById("selectedtime_"+chkattval).value = document.getElementById("selectedtime_"+chkattval).value.replace(RepSemTime,'');
	objAtt = objAtt.replace(RepAttID,'');

	document.getElementById("selectedseminar_"+chkattval).value=document.getElementById("selectedseminar_"+chkattval).value.replace(chkVal+",",'');
	document.getElementById("selectedseminar_"+chkattval).value=document.getElementById("selectedseminar_"+chkattval).value.replace(","+chkVal,'');
	document.getElementById("selectedseminar_"+chkattval).value=document.getElementById("selectedseminar_"+chkattval).value.replace(chkVal,'');
	if(document.getElementById("selectedseminar_"+chkattval).value != null)
	{
		if(DeSelectBreak(chkattval,valSeminarDate,valSeminarTime))
		{
			Select.UpdateSeminartoAttendee(chkattval,document.getElementById("selectedseminar_"+chkattval).value,callbackdesc)
		}
	}
	document.getElementById("imgBtnGreenSeminar_"+chkVal+"_"+chkattval).style.display="none";
	document.getElementById("imgBtnRedSeminar_"+chkVal+"_"+chkattval).style.display="block";
}
function SelectBreak(attID,semDate,semTime)
{
	var summitid = document.getElementById("ctl00_CPHPageContent_HdnSummitID").value
	var seltime= semTime.replace(' ','');
	var tempTime = new Array();
	tempTime=seltime.split('-');

	res = Select.GetBreak(summitid,semDate,semTime)
	//alert(summitid + "   "+  semDate  + "   "+ semTime);
	//alert(res.value)
	if(res.value != "false")
	{
		if(document.getElementById("Break_"+res.value+"_"+attID)!= null )
		{
			document.getElementById("Break_"+res.value+"_"+attID).style.display="block";
			document.getElementById("imgBtnRedSeminar_"+res.value+"_"+attID).style.display="none";
			document.getElementById("imgBtnGreenSeminar_"+res.value+"_"+attID).style.display="block";
			if(document.getElementById("selectedseminar_"+attID).value != "")
			{
				document.getElementById("selectedseminar_"+attID).value=document.getElementById("selectedseminar_"+attID).value+","+res.value;
			}
			else
			{
				document.getElementById("selectedseminar_"+attID).value=res.value;
			}
		}
	}
	return true;
}
function DeSelectBreak(attID,semDate,semTime)
{
	var summitid = document.getElementById("ctl00_CPHPageContent_HdnSummitID").value
	var seltime= semTime.replace(' ','');
	var tempTime = new Array();
	tempTime=seltime.split('-');
	res = Select.GetBreak(summitid,semDate,semTime)
	if(res.value != "false")
	{
		if(document.getElementById("Break_"+res.value+"_"+attID)!= null && document.getElementById("Break_"+res.value+"_"+attID).style.display == "block")
		{
			document.getElementById("Break_"+res.value+"_"+attID).style.display="none";
			document.getElementById("imgBtnRedSeminar_"+res.value+"_"+attID).style.display="none";
			document.getElementById("imgBtnGreenSeminar_"+res.value+"_"+attID).style.display="none";
			document.getElementById("selectedseminar_"+attID).value=document.getElementById("selectedseminar_"+attID).value.replace(res.value+",",'');
			document.getElementById("selectedseminar_"+attID).value=document.getElementById("selectedseminar_"+attID).value.replace(","+res.value,'');
			document.getElementById("selectedseminar_"+attID).value=document.getElementById("selectedseminar_"+attID).value.replace(res.value,'');
		}
	}
	return true;
}
function callbackdesc(res)
{
//if (isError(res)) return false;
//	alert(res.value);
}
function isError(res)
{
	if(res.error)
	{
		alert("Error: " + res.error.Message);
		return true;
	}
	return false;
}
function getalerts()
{
	alert("sfsdfsd")
	return false
}
function ClearValue()
{
if(validatecheckbox())
{
	var summitid = document.getElementById("ctl00_CPHPageContent_HdnSummitID").value
	var strSemid=document.getElementById("ctl00_CPHPageContent_HdnAttID").value;
	var Sem_array=strSemid.split(',');
	/*for(x=0; x<Sem_array.length; x++)
	{
		if(document.getElementById("ctl00_CPHPageContent_HdnStartDate")!= null && document.getElementById("ctl00_CPHPageContent_HdnStartDate").value!="")
		{
			var alt = Select.GetAlertMsg(parseInt(summitid),parseInt(Sem_array[x]),document.getElementById("ctl00_CPHPageContent_HdnStartDate").value)
			if(alt.value == 'Select Seminar')
			{
				alert("You must  select at least one seminar for each  attendee.")
				return false;
			}
		}
		if(document.getElementById("ctl00_CPHPageContent_HdnEndDate")!= null && document.getElementById("ctl00_CPHPageContent_HdnEndDate").value!="")
		{
			var alt = Select.GetAlertMsg(parseInt(summitid),parseInt(Sem_array[x]),document.getElementById("ctl00_CPHPageContent_HdnEndDate").value)
			if(alt.value == 'Select Seminar')
			{
				alert("You must  select at least one seminar for each  attendee.")
				return false;
			}
		}
	}
	for(x=0; x<Sem_array.length; x++)
	{
		if(document.getElementById("ctl00_CPHPageContent_HdnStartDate")!= null && document.getElementById("ctl00_CPHPageContent_HdnStartDate").value!="")
		{
			var alt = Select.GetAlertMsg(parseInt(summitid),parseInt(Sem_array[x]),document.getElementById("ctl00_CPHPageContent_HdnStartDate").value)
			if(alt.value == 'Select Break')
			{
				if (confirm("It is highly  recommended that you select at least one networking session.Proceed without networking session?"))
				{
					for(y=0; y<Sem_array.length; y++)
					{
						document.getElementById("selectedseminar_"+Sem_array[y]).value="";
						document.getElementById("selecteddate_"+Sem_array[y]).value="";
						document.getElementById("selectedtime_"+Sem_array[y]).value="";
					}
					return true
				}
				else
				{
					return false;
				}
			}
		}
		if(document.getElementById("ctl00_CPHPageContent_HdnEndDate")!= null && document.getElementById("ctl00_CPHPageContent_HdnEndDate").value!="")
		{
			var alt = Select.GetAlertMsg(parseInt(summitid),parseInt(Sem_array[x]),document.getElementById("ctl00_CPHPageContent_HdnEndDate").value)
			if(alt.value == 'Select Break')
			{
				if (confirm("It is highly  recommended that you select at least one networking session.Proceed without networking session?"))
				{
					for(y=0; y<Sem_array.length; y++)
					{
						document.getElementById("selectedseminar_"+Sem_array[y]).value="";
						document.getElementById("selecteddate_"+Sem_array[y]).value="";
						document.getElementById("selectedtime_"+Sem_array[y]).value="";
					}
					return true
				}
				else
				{
					return false;
				}
			}
		}
	}
	*/
	for(x=0; x<Sem_array.length; x++)
	{
		document.getElementById("selectedseminar_"+Sem_array[x]).value="";
		document.getElementById("selecteddate_"+Sem_array[x]).value="";
		document.getElementById("selectedtime_"+Sem_array[x]).value="";
	}
	return true
}
return false;
}
function validatecheckbox()
{
    var eventType=document.getElementById("ctl00_CPHPageContent_HdnEventType").value;
	var strSemid=document.getElementById("ctl00_CPHPageContent_HdnSemID").value;
	var Sem_array=strSemid.split(',');
	var strAttid=document.getElementById("ctl00_CPHPageContent_HdnAttID").value;
	var Att_array=strAttid.split(',');
	for(y=0; y<Att_array.length; y++)
	{
	    var flgChkStatus=false;
	    if(document.getElementById("ctl00_CPHPageContent_Chk2dayPass"+Att_array[y]) != null && !document.getElementById("ctl00_CPHPageContent_Chk2dayPass"+Att_array[y]).checked)
	    {
		        for(x=0; x<Sem_array.length; x++)
		        {
			        var frmValue = document.getElementsByTagName("img");
			        for(J=0; J<frmValue.length; J++)
			        {
				        var e = frmValue[J];
				        if(e.id.indexOf("imgBtnGreenSeminar_"+Sem_array[x]+"_"+Att_array[y])>=0)
				        {
				            //alert("hai"+e.style.display);
				           // alert(flgChkStatus);
					        if(e.style.display == "block")
					        {
						        flgChkStatus = true;
					        }
        //				    var Getid = e.id;
        //				    var GetIdAry = new Array();
        //				    GetIdAry = Getid.split('_');
        //				    if(GetIdAry.length>0)
        //				    {
        //				        if(document.getElementById("ctl00_CPHPageContent_Chk2dayPass"+GetIdAry[2]) !=null)
        //				        {
        //				            alert(document.getElementById("ctl00_CPHPageContent_Chk2dayPass"+GetIdAry[2]).checked)
        //				        }
        //				        //alert(GetIdAry[2]);
        //				    }
				        }
			        }
		        }
        }
        else if(document.getElementById("ctl00_CPHPageContent_Chk2dayPass"+Att_array[y]) == null)
        {
	        for(x=0; x<Sem_array.length; x++)
	        {
		        var frmValue = document.getElementsByTagName("img");
		        for(J=0; J<frmValue.length; J++)
		        {
			        var e = frmValue[J];
			        if(e.id.indexOf("imgBtnGreenSeminar_"+Sem_array[x]+"_"+Att_array[y])>=0)
			        {
				        if(e.style.display == "block")
				        {
					        flgChkStatus = true;
				        }
                    }
                }
            }
        }
        else
	{
	    flgChkStatus = true;
        }
	if(!flgChkStatus)
	{
	    var ChkAvailableMentor = Select.CheckAvailableMentors();
	    if(ChkAvailableMentor.value == "yes")
	    {
		    if(eventType.trim()=="W")
		     {
		            if(confirm("You have not selected any videos. Would you like to reserve mentoring sessions only? "))
		            {
		                document.getElementById("ctl00_CPHPageContent_HdnAvailableMentorStatus").value = "yes";
		                //alert(document.getElementById("ctl00_CPHPageContent_HdnAvailableMentorStatus").value);
		                return true;
		                //return false;
		            }
		            else
		            {
		                alert("You must select at least one video for each Attendee");
		                return false;
		            }
		     }
		     else
		      {
		         if(confirm("You have not selected any seminars. Would you like to reserve mentoring sessions only? "))
		        {
		            document.getElementById("ctl00_CPHPageContent_HdnAvailableMentorStatus").value = "yes";
		            //alert(document.getElementById("ctl00_CPHPageContent_HdnAvailableMentorStatus").value);
		            return true;
		            //return false;
		        }
		        else
		        {
		            alert("You must select at least one seminar for each Attendee");
		            return false;
		        }
		      }
	    }
	    else if(ChkAvailableMentor.value == "no")
	    {
	        if(eventType.trim()=="W")
	         {
	           //alert("There is no mentor available for this summit, so You must select at least one seminar for each Attendee");
			alert("You have not selected any vidoes. Please select at least one video for each attendee to proceed to the next step.");
		    //alert("You must select at least one seminar for each Attendee ");
		    return false;
	         }
	         else
	         {
	           //alert("There is no mentor available for this summit, so You must select at least one seminar for each Attendee");
			alert("You have not selected any seminars. Please select at least one seminar for each attendee to proceed to the next step.");
		    //alert("You must select at least one seminar for each Attendee ");
		    return false;
	         }
			
	    }
	    else
	    {
		alert("Refresh the page");
		return false;
	    }
	    return true;
	    //alert("You must select at least one seminar for each Attendee ");
	    //return false;
	}
	}
	return true
}

