function fetchEvents(str,str2)
{
	
	var xmlHttp;
	
	
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();		
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject(" Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function ()	 {
		if(xmlHttp.readyState==4)	{
			document.getElementById(str2).innerHTML=xmlHttp.responseText
		}
	}
	
	var url=str;
	//alert(url);
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null);
}
function echeck(str) {		
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Invalid E-mail")
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Invalid E-mail")
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Invalid E-mail")
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Invalid E-mail")
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		alert("Invalid E-mail")
		return false
	 }

	 return true					
}

function validPhone(akey, sText, field) {	
   var ValidChars = "0123456789-";
   var IsNumber=true;
   var Char;
   var key = akey.keyCode;
   var myStr = sText;
 
  if(key==8){
	 return sText;
  }
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
			myStr = myStr.replace(Char,'');
			field.value = myStr;
        	IsNumber = false;
         }
      }
   return IsNumber;
}

function validNumber(akey, value, field) {
	
	//alert(akey.keyCode);
		if (akey.keyCode) {			
			key = akey.keyCode;
			
			if(key==9 || key==8 || key==37 || key==39 ||key==96 || key==97 || key==98 || key==99 || key==100 || key==101 
				|| key==102 || key==103 || key==104 || key==105 || key==109|| key==110 || key==188 ||key==189 
						|| key==190 || key==191 || key==111) {
				return true;
			} else if(key < 46 || key > 57) {				
				field.value = value;
				return false;
			}else
				return value;
		} 
}


function chk(){
	if(document.form1.name.value == "")
	{
		alert("Please enter your name");
		document.form1.name.focus();
		return false;
	}
	if(document.form1.email.value == "")
	{
		alert("Please enter your email");
		document.form1.email.focus();
		return false;
	}
	if (echeck(document.form1.email.value)==false){
		document.form1.email.value=""
		document.form1.email.focus()
		return false
	}
}

function loginCheck(){
	if(document.form1.userName.value == "")
	{
		alert("Please Enter User Name");
		document.form1.name.focus();
		return false;
	}
		
	if(document.form1.password.value == "")
	{
		alert("Please Enter the Password");
		document.form1.email.focus();
		return false;
	}
	if(document.form1.password.value !="" || document.form1.userName.value !="")
	{
		alert("User Name and Password does not match!");
		document.form1.name.focus();
		return false;
	}
}

/**********Checking Employee Insertion form**********/
function checkEmployeeForm() {
	
	var why = "";
	var why1 = "";
	var thisForm	= document.frm;	
	if(thisForm.loginId.value == "")
		why +="Login ID\n";

	if(thisForm.password.value == "")
		why +="Password \n";
		
	if(thisForm.confirmpass.value == "")
		why +="Confirm Password \n";
		
	if((thisForm.password.value != "")&&(thisForm.confirmpass.value != "")){
		
		if(thisForm.password.value != thisForm.confirmpass.value){
			
			why1 +=	"Password and Confirm Password not matching.\n";
			
		}		
	}	
	if(thisForm.staffname.value == "")
		why +="Staff Name \n";
		
	if(thisForm.designation.value== "")
		why +="Designation\n";
		
	if(thisForm.phone.value== "")
		why +="Phone\n";
		
	if(thisForm.email.value== "")	
		why +="Email\n";
	if(thisForm.email.value != ""){
		
		var strng	=	thisForm.email.value;
		var emailFilter=/^.+@.+\..{2,3}$/;
		if (!(emailFilter.test(strng))) { 
		   why1 += "Please enter a valid email address.\n";
		}
		else {
		//test email for illegal characters
		   var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
			 if (strng.match(illegalChars)) {
			 why1 += "The email address contains illegal characters.\n";
		   }
		}
	}
		
	if (why != "") {
		alert("Please enter the Following details\n" + why);
		return false;
	}
	if(why1 != ""){
		alert(why1);
		return false;
	}
	thisForm.submit();
	return true;
}

/********** Checking Client Insertion form **********/
function checkClientForm(){
	
	var why = "";
	var why1 = "";
	var thisForm	= document.frm;	
	if(thisForm.name.value == "")
		why +="Company Name\n";

	if(thisForm.address1.value == "")
		why +="Address1 \n";
	
	/*if(thisForm.address2.value == "")
		why +="Address2 \n";*/
		
	if(thisForm.city.value == "")
		why +="City \n";
		
	if(thisForm.state.value == "")
		why +="State \n";
		
	if(thisForm.country.value == "")
		why +="Country \n";
		
	if(thisForm.phone.value == "")
		why +="Phone \n";
		
	/*if(thisForm.email.value == "")
		why +="Email \n";	*/
		
	if(thisForm.PICname.value == "")
		why +="PIC Name \n";
	
	
	if(thisForm.email.value != ""){
		
		var strng	=	thisForm.email.value;
		var emailFilter=/^.+@.+\..{2,3}$/;
		if (!(emailFilter.test(strng))) { 
		   why1 += "Please enter a valid email address.\n";
		}
		else {
		//test email for illegal characters
		   var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
			 if (strng.match(illegalChars)) {
			 why1 += "The email address contains illegal characters.\n";
		   }
		}
	}
		
	if (why != "") {
		alert("Please enter the Following details\n" + why);
		return false;
	}
	if(why1 != ""){
		alert(why1);
		return false;
	}
	thisForm.submit();
	return true;
	
}

function checkProductsForm(){
	
		
	var why = "";
	var why1 = "";
	var thisForm	= document.form1;	
	if(thisForm.productname.value == "")
		why =" Enter Product Name\n";
	if (why != "") {
		alert(why);
		return false;
	}
	
	thisForm.submit();
	return true;
	
}

/********** Checking Contact Us form **********/
function checkContactUs(){
	var why = "";
	var why1 = "";
	
	var thisForm	= document.form1;	
	
	if((thisForm.mobile.value == "") && (thisForm.phone.value == "") && (thisForm.email.value == "") )
	{ why = "Please enter phone,e-mail ID or mobile number\n";}	
	
	else if((thisForm.email.value != "") || (thisForm.mobile.value != "")|| (thisForm.phone.value != "")) 
		{
			why ="";
			if(thisForm.email.value != "")
		{		
		  var strng	=	thisForm.email.value;
		  var emailFilter=/^.+@.+\..{2,3}$/;
		  if (!(emailFilter.test(strng))) { 
		   why1 += "Please enter a valid email address.\n";
		   }
		else {
	    	//test email for illegal characters
		     var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
			 if (strng.match(illegalChars)) {
			 why1 += "The email address contains illegal characters.\n";
		     }
		   }
	   }
	   if(thisForm.mobile.value != "")
	   {	
	   	   var mob	=	thisForm.mobile.value;
		   if(mob.length < 10)
		   why1 += "Enter minimum of 10 numbers for your mobile.\n";
	   }
	    if(thisForm.phone.value != "")
	   {	
	   	   var phone	=	thisForm.phone.value;
		   if(phone.length < 7)
		   why1 += "Enter minimum of 7 numbers for phone number.\n";
	   }
	
	}

	
		
	if(thisForm.name.value == "")
		why =" Enter Your Name\n";
		
	if (why != "") {
		alert(why);
		return false;
	}
	if(why1 != ""){
		alert(why1);
		return false;
	}
	
	thisForm.submit();
	return true;	
		
	
}

/********** Checking Enquiry form **********/
function checkEnquiry(){
	
		
	var why = "";
	var why1 = "";
	
	var thisForm	= document.form1;	
	
	if((thisForm.mobile.value == "") && (thisForm.phone.value == "") && (thisForm.email.value == "") )
	{ why = "Please enter phone,e-mail ID or mobile number\n";}	
	
	else if((thisForm.email.value != "") || (thisForm.mobile.value != "")|| (thisForm.phone.value != "")) 
		{
			why ="";
			if(thisForm.email.value != "")
		{		
		  var strng	=	thisForm.email.value;
		  var emailFilter=/^.+@.+\..{2,3}$/;
		  if (!(emailFilter.test(strng))) { 
		   why1 += "Please enter a valid email address.\n";
		   }
		else {
	    	//test email for illegal characters
		     var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
			 if (strng.match(illegalChars)) {
			 why1 += "The email address contains illegal characters.\n";
		     }
		   }
	   }
	   if(thisForm.mobile.value != "")
	   {	
	   	   var mob	=	thisForm.mobile.value;
		   if(mob.length < 10)
		   why1 += "Enter minimum of 10 numbers for your mobile .\n";
	   }
	    if(thisForm.phone.value != "")
	   {	
	   	   var phone	=	thisForm.phone.value;
		   if(phone.length < 7)
		   why1 += "Enter minimum of 7 numbers for your phone number.\n";
	   }
	
	}

	
		
	if(thisForm.name.value == "")
		why =" Enter Your Name\n";
		
	if (why != "") {
		alert(why);
		return false;
	}
	if(why1 != ""){
		alert(why1);
		return false;
	}
	
	thisForm.submit();
	return true;	
}

/********** Checking Job Application **********/
function checkApplication(){
	
		
	var why = "";
	
	var thisForm	= document.form1;	
	
	if(thisForm.name.value == "") 
	{ why = "Please enter your name \n";}	
	
			
	if (why != "") {
		alert(why);
		return false;
	}
		
	thisForm.submit();
	return true;	
}

//validating number
function validNumber(akey, value, field) {
	
	//alert(akey.keyCode);
		if (akey.keyCode) {			
			key = akey.keyCode;
			
			if(key==9 || key==8 || key==37 || key==39 ||key==96 || key==97 || key==98 || key==99 || key==100 || key==101 
				|| key==102 || key==103 || key==104 || key==105 || key==109|| key==110 || key==188 ||key==189 
						|| key==190 || key==191 || key==111) {
				return true;
			} else if(key < 46 || key > 57) {				
				field.value = value;
				return false;
			}else
				return value;
		} 
}

/**** Client /Prospect search*************/

function clientselect()
{	 
	
	var details		=	document.frm.prospectId.value;
	
	var arrclient	=	details.split(",");
	
	window.opener.document.frm.prospectId.value = arrclient[0];
	window.opener.document.frm.name.value = arrclient[1];
	 //opener.frm.submit();
	 
	 window.close();
}

/**** Leads search*************/

function leadselect()
{
	
	
	var details		=	document.frm.taskId.value;

	var arrclient	=	details.split(",");
	
	window.opener.document.frm.taskId.value = arrclient[0];
	window.opener.document.frm.taskname.value = arrclient[1];
	 //opener.frm.submit();
	
	 window.close();
	
}
function showValue(str){
	
	
var xmlHttp;
	
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();		
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject(" Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function ()	 {
		if(xmlHttp.readyState==4)	{
			document.getElementById('list').innerHTML=xmlHttp.responseText
		}
	}
	
	var url="ajaxDisplayvalue.php";
		url=url+"?str="+str;
		//alert(url);
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null);
	
	
}
function showgroupby(str){
	
var xmlHttp;
	
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();		
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject(" Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function ()	 {
		if(xmlHttp.readyState==4)	{
			document.getElementById('group').innerHTML=xmlHttp.responseText
		}
	}
	
	var url="ajaxDisplaygroup.php";
		url=url+"?str="+str;
		//alert(url);
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null);
	
	
}

/**** Cancellation Textbox ***********/
function showReschedule(str,str1,str2){
	
	if(str=='Yes')
		document.frm.Update.disabled=true;
	if(str=='No')
		document.frm.Update.disabled=false;
	var xmlHttp;
	
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();		
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject(" Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function ()	 {
		if(xmlHttp.readyState==4)	{
			document.getElementById('reschedule').innerHTML=xmlHttp.responseText
			document.frm.Update.disabled=false;
		}
	}
	
	var url="ajaxReschedule.php";
	url=url+"?str="+str+"&file="+str1+"&taskdetailId="+str2;
		//alert(url);
		xmlHttp.open("GET",url,true)
			
		xmlHttp.send(null);
		
	
}


function showReschedule1(str,str1,str2){
	
	
	var xmlHttp;
	
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();		
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject(" Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function ()	 {
		if(xmlHttp.readyState==4)	{
			document.getElementById('reschedule').innerHTML=xmlHttp.responseText
			
		}
	}
	
	var url="ajaxReschedule.php";
	url=url+"?str="+str+"&file="+str1+"&taskdetailId="+str2;
		//alert(url);
		xmlHttp.open("GET",url,true)
			
		xmlHttp.send(null);
		
	
}
/********** Display Update status part ****************/

function ajaxUpdatestatus(str,str1,str2)
{
	
	var xmlHttp;
	
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();		
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject(" Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function ()	 {
		if(xmlHttp.readyState==4)	{
			document.getElementById('updatestatus').innerHTML=xmlHttp.responseText
			document.frm.Update.disabled=false;
		}
	}
	
	var url="ajaxUpdatestatus.php";
		url=url+"?str="+str+"&str1="+str1+"&str2="+str2;
		//alert(url);
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null);
	
		
}
/////////////////////
/********** Display Update status part ****************/

function ajaxLeadFollowup(str2,str)
{
	var xmlHttp;
	
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();		
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject(" Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function ()	 {
		if(xmlHttp.readyState==4)	{
			document.getElementById('leadFollowup').innerHTML=xmlHttp.responseText;
			document.frm.Update.disabled=false;
		}
	}
	
	var url="ajaxLeadFollowUp.php";
		url=url+"?str2="+str2+"&str="+str;
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null);
	
		
}

/////////////////////
function showClear(curdate,furdate){
	
	
	len = document.form2.filteron.length;
	
	 for (var x = 0; x < len; x++) { 
	 
		if (document.form2.filteron.options[x].value == "") { 
		
				document.form2.filteron.options[x].selected = true; 
	    } 
	} 
	document.form2.staffId.value="";
	document.form2.date.value=curdate;
	document.form2.dateto.value=furdate;
	document.form2.days.value="";
		
	
}
/**** Checking Cancellation form ********/
function checkCancelform()
{
	
	var why = "";
	
	var thisForm	= document.form1;	
	if(thisForm.cancellationReason.value == "")
		why +="Please Enter Reason for Cancellation\n";
	if (why != "") {
		alert(why);
		return false;
	}
		
	
	thisForm.submit();
	return true;
	
}
function checkLeadForm()
{
	var why = "";
		
	var thisForm	= document.frm;
	if(thisForm.taskname.value == "")
		why += "Lead Name \n";
	
	if(thisForm.name.value == "")
		why +="Prospect Name \n";
	
	
	if(thisForm.expsellprice.value == "")
		why +="Expected Selling Price \n";
			
	if (why != "") {
		alert("Please enter the Following details\n" + why);
		return false;
	}
	
	thisForm.submit();
	return true;
}
function checkScheduleForm()
{
	
	var why = "";
		
	var thisForm	= document.frm;
	if(thisForm.taskname.value == "")
		why += "Taskname \n";
	if(thisForm.agenda.value == "")
		why += "Agenda \n";
	
	if(thisForm.date.value == "")
		why +="Date \n";
	if(thisForm.timeHour.value == "00")
		why +="Hour\n";	
		
	for(i=0; i<document.frm.elements.length; i++)
	{
			
		if(document.frm.elements[i].name == "rescheduleAgenda"){
		if(thisForm.rescheduleAgenda.value == "")
			why +="Reschedule Agenda\n";
		}
		if(document.frm.elements[i].name == "rescheduledate"){
		if(thisForm.rescheduledate.value == "")
			why +="Reschedule Date\n";
		}
		if(document.frm.elements[i].name == "rescheduleHour"){
		if(thisForm.rescheduleHour.value == "00")
			why +="Reschedule Hour\n";
		}
		if(document.frm.elements[i].name == "reschedulecontact"){
		if(thisForm.reschedulecontact.value == "")
			why +="Reschedule Contact Person\n";
		}
	
	}
	if (why != "") {
		alert("Please enter the Following details\n" + why);
		return false;
	}
	
	thisForm.submit();
	return true;
	
}

function checkReScheduleForm()
{
	
	var why = "";
		
	var thisForm	= document.frm;
	
		
	for(i=0; i<document.frm.elements.length; i++)
	{
			
		if(document.frm.elements[i].name == "rescheduleAgenda"){
		if(thisForm.rescheduleAgenda.value == "")
			why +="Reschedule Agenda\n";
		}
		if(document.frm.elements[i].name == "rescheduledate"){
		if(thisForm.rescheduledate.value == "")
			why +="Reschedule Date\n";
		}
		if(document.frm.elements[i].name == "rescheduleHour"){
		if(thisForm.rescheduleHour.value == "00")
			why +="Reschedule Hour\n";
		}
		if(document.frm.elements[i].name == "reschedulecontact"){
		if(thisForm.reschedulecontact.value == "")
			why +="Reschedule Contact Person\n";
		}
	
	}
	if (why != "") {
		alert("Please enter the Following details\n" + why);
		return false;
	}
	
	thisForm.submit();
	return true;
	
}

function submitform(){
	
	
	for(i=0; i<document.form2.elements.length; i++)
	{
		if(document.form2.elements[i].name == "Report"){
			document.form2.action	=	"reportxls.php";
			document.form2.submit();
		}
		else
		{
			document.form2.action	=	"home.php";
		}
	}
}

function showClientform(str){
	
	if(str=='lead'){
		//alert(str);
		var str='lead';
		document.form2.action	=	"clientgroup.php?groupby="+str;
		document.form2.submit();
	}
	else{
		
		
		document.form2.action	=	"home.php";
		document.form2.submit();
	}
	
}
function messageSucess(){
alert("File sucessfully Uploaded");
}