function getHTTPObject() {
  var xmlhttp;
 
  if(window.XMLHttpRequest){
    xmlhttp = new XMLHttpRequest();
  }
  else if (window.ActiveXObject){
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    if (!xmlhttp){
        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
    } 
}
  return xmlhttp;
}

var http = getHTTPObject(); // We create the HTTP Object
/*
	Funtion Name=requestInfo 
	Param = url >> Url to call : id = Passing div id for multiple use ~ as a seprator for eg. div1~div2 :
	redirectPage >> if you like to redirect to other page once the event success then 
	the response text = 1 and the redirectPage not left empty
*/
    function requestInfo(url,id,redirectPage) {
		var temp=new Array();
		var url=url+"&sid="+Math.random()
			http.open("GET", url, true);
			//http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=iso-8859-1');		
			
			http.onreadystatechange = function() {
				if (http.readyState == 4) {
				  if(http.status==200) {
			  		var results=http.responseText;
					
					//alert(document.getElementById(id).innerHTML);
					//alert(http.responseText);
					if(redirectPage=="" || results!="2") {
						
						var temp=id.split("~"); // To display on multiple div 
						//alert(temp.length);
						var r=results.split("~"); // To display multiple data into the div 
						//alert(temp.length);
						if(temp.length>1) {
							for(i=0;i<temp.length;i++) {	
								//alert(temp[i]);
								document.getElementById(temp[i]).innerHTML=r[i];
							}
						} else {
							//document.getElementById(id).innerHTML = "";
							document.getElementById(id).innerHTML = results;
						}	
					} else {
						//alert(redirectPage);
						window.location.href=redirectPage;			
					}
				  } 
  				}
			};
			http.send(null);
			
       }

/*
	Function Name= emptyValidation
	Desc = This function is used to validation for the empty field 
	Param fieldList = This arguments set as a string varialble. you just need to supply the textbox name
	if the textbox is multiple then supply with ~ separator for eg. username~password
*/
function emptyValidation(fieldList) {
		var field=new Array();
		field=fieldList.split("~");
		var counter=0;
		for(i=0;i<field.length;i++) {
			if(document.getElementById(field[i]).value=="") {
				document.getElementById(field[i]).style.backgroundColor="#ff8800";
				counter++;
			} else {
				document.getElementById(field[i]).style.backgroundColor="#FFFFFF";	
			}
		}
		if(counter>0) {
				alert("La marque de champ comme rouge ne pourrait pas laissé vide");
				return false;
				
		}  else {
			return true;
		}
		
}
function confirmLink(theLink)
{
    var is_confirmed = confirm('Êtes-vous sûr de supprimer ce disque ? \n\n This supprimeront de manière permanente le disque!');
    if (is_confirmed) 
	{
        theLink.href += '';
    }
    return is_confirmed;
}

function back()
{
	window.location.href="contentmanagement.php";
}
function goback(redirect)
{
		window.location.href=redirect;
}

function autoFormSubmitFile(form,id1,id2)
{
	var a=document.getElementById(id2).value;	  	
  	var exten=a.substring(a.lastIndexOf('.')+1);
	 
	 if(document.getElementById(id1).value=="NULL")
	 {
		 alert("Choisir une catégorie !");
	 }
	 else if(document.getElementById(id2).value =="")
	 {
		 alert("Choisir un texte, un Doc., un Xls ou un dossier de pdf !");
	 }
	 else
	 {
		 if(exten=='txt'||exten=='doc'||exten=='pdf'||exten=='xls'||exten=='TXT'||exten=='DOC'||exten=='XLS'||exten=='PDF')
		 {

			 document.getElementById(form).submit();
			 
		 }
		 else
		 {
			 alert('On ne te permet pas de télécharger ce dossier ! Employer seulement le txt, le Doc., les xls ou les dossiers de pdf !');
		 }        
		 
	 }
}

function autoFormupdatepost(taskid,status,subject,message)
{
	 var status=document.getElementById('status').value;
	 var subject=document.getElementById('subject').value;
	 var message=document.getElementById('message').value;
	 
	 if(document.getElementById('status').value=="")
	 {
		 alert("Écrire l'username de receipents");
	 }
	 else if(document.getElementById('subject').value =="")
	 {
		 alert("Écrire un sujet pour le charger");
	 }
	 else if(document.getElementById('message').value =="")
	 {
		 alert("Vous n'en avez pas indiqué chargez");
	 }
	 else
	 {	 	 
		requestInfo('includes/ProfileAdmin.php?name='+'updatetaskdb'+'&status='+status+'&subject='+subject+'&message='+message+'&taskid='+taskid,'taskdisp','');	
	 }
	 
}

function autoFormSubmitpost(form,status,subject,message)
{
	 var status=document.getElementById('status').value;
	 var subject=document.getElementById('subject').value;
	 var message=document.getElementById('message').value;
	 
	 if(document.getElementById('status').value=="")
	 {
		 alert("Écrire l'username de receipents");
	 }
	 else if(document.getElementById('subject').value =="")
	 {
		 alert("Écrire un sujet pour le charger");
	 }
	 else if(document.getElementById('message').value =="")
	 {
		 alert("Vous n'en avez pas indiqué chargez");
	 }
	 else
	 {
		requestInfo('includes/ProfileAdmin.php?name='+'assigntaskdb'+'&status='+status+'&subject='+subject+'&message='+message,'taskdisp','');	
	 }
}

//Request to [profileview;profileupdate;changepassword]-USER FORM DISPLAYS;
function usermanager(input)
{
	document.getElementById('userdisp').innerHTML='<div id="load" style = "text-align:center; vertical-align:middle;" ><img src="images/loading.gif" border="0px" align="loading" /></div>';	
	requestInfo('includes/ProfileAdmin.php?name='+input,'userdisp','');
}

//Request from PROFILE EDIT FORM when the submit button click then check all the fields are valid or not;
function callprofile(reguser,name,address,phone,mail)
{	
	var name=document.getElementById(name).value;
	var address=document.getElementById(address).value;
	var phone=document.getElementById(phone).value;
	var mail=document.getElementById(mail).value;
	
	if(name=='')
	 {
		 alert("Écrire le nom");
	 }
	 else if(address=='')
	 {
		 alert("Écrire le Addresse");
	 }
	 else if(phone=='')
	 {
		 alert("Écrire le Téléphone");
	 }	
	 else if(mail=='')
	 {
		 alert("Écrire le MailID");
	 }	
	 else 
	 {
	requestInfo('includes/ProfileAdmin.php?name='+'profileupdatedb'+'&username='+name+'&address='+address+'&phone='+phone+'&mailid='+mail,'userdisp','');	
	 }
}

function artprof_list(id,start)
{
		for(i=01;i<=06;i++)
	{
		var j='0'+i;
		document.getElementById(j).innerHTML='';
	}
		document.getElementById(id).innerHTML='<div id="load" style = "text-align:center; vertical-align:middle;" ><img src="images/loading.gif" border="0px" align="loading" /></div>';
		requestInfo('includes/article_Ajax.php?gid='+id,id,'');
}

function showArticleprof(id,MODE,eid)
{
	var total = document.getElementById('total').value;
	var i;
	for(i=1;i<total;i++)
	{
		document.getElementById(i).innerHTML='';
	}
	document.getElementById(eid).innerHTML='<img src="images/loading.gif" width="100px" height="25px" />';
	requestInfo('includes/article_Ajax.php?mode='+MODE+'&ID='+id+'&EID='+eid,eid,'');	
}
//Function for closing the article view
function closArticleprof(eid)
{
	document.getElementById(eid).innerHTML='';
}


//Request from CHANGE PASSWORD FORM when the submit button click then check all the fields are valid or not;
function passcheck(pass,newpass,repass)
{	
	var pass=document.getElementById('pass').value;
	var newpass=document.getElementById('newpass').value;
	var repass=document.getElementById('repass').value;
	if(newpass!=repass)
	{
		alert('Dactylographier votre nouveau mot de passe correctement');
	}else if(pass==""||newpass==""||repass=="")
	{
		alert('Un du champ est vide !');		
	}else{
		
	requestInfo('includes/ProfileAdmin.php?name='+'passcheck'+'&pass='+pass+'&newpass='+newpass+'&repass='+repass,'userdisp','');
	}
}

//FIELD VALIDATIONS ONCHANGE; ONKEYUP EVENTS;
//MAIL ID VALIDATION WITH ITS EXPRESSION
function mailValidation()
{
	var email = document.getElementById('mailid').value;
	var emailRegxp = /^([\w]+)(.[\w]+)*@([\w]+)(.[\w]{2,3}){1,2}$/;
	
	if(emailRegxp.test(email))
	{
		document.getElementById('mail').innerHTML="<font color='#CC3300'><i></font>";		
	}
	else
	{
		document.getElementById('mail').innerHTML="<font color='#CC3300'><i>Écrire un E-mail valide</font>";
	}
}

//PHONE NUMBER VALIDATION WITH ITS EXPRESSION
function phoneValidation()
{
	var phone = document.getElementById('phone').value;
	var phoneRegxp = /^([0-9]){10}$/;
	
	if(phoneRegxp.test(phone))
	{
		document.getElementById('contact').innerHTML="<font color='#CC3300'><i></font>";		
	}
	else
	{
		document.getElementById('contact').innerHTML="<font color='#CC3300'><i>Écrire un téléphone valide.</font>";		
	}
}

//DATE VALIDATION WITH ITS EXPRESSION
function dateValidation()
{
	var date = document.getElementById('dob').value;
	var dateRegxp = /^([0-9]){1,2}(\/|-){1}([0-9]){1,2}(\/|-)([0-9]){4}$/;
	
	if(dateRegxp.test(date))
	{
		
		document.getElementById('date').innerHTML="<font color='#CC3300'><i></font>";		
	}
	else
	{
		document.getElementById('date').innerHTML="<font color='#CC3300'><i>Écrire une date valide.</font>";		
	}
}

//PASSWORD VALIDATION
function passValidation()
{
	var pass = document.getElementById('newpass').value;
	var passRegxp = /([a-zA-Z0-9]){6,10}$/;
	
	if(passRegxp.test(pass))
	{
		document.getElementById('passvalid').innerHTML="<font color='#CC3300'><i></font>";		
	}
	else
	{
		
		document.getElementById('passvalid').innerHTML="<font color='#CC3300'><i> Atleast six caractères. Seulement lettres et chiffres!</font>";		
	}
}

//COMPARE TWO PASSWORDS ARE EQUAL OR NOT
function passCompare()
{
	var pass = document.getElementById('newpass').value;
	var repass = document.getElementById('repass').value;
	
	if(pass==repass)
	{		
		document.getElementById('repassvalid').innerHTML="<font color='#CC3300'><i></font>";		
	}
	else
	{		
		document.getElementById('repassvalid').innerHTML="<font color='#CC3300'><i>Le nouveau mot de passe pas match.</font>";		
	}	
}

function resetlogin()
{
	document.getElementById('username').value="";
	document.getElementById('password').value="";
}

//Script for Consultation,Reunion,Events Professional starts here

function rep_reunionDisplay(input,start)//Function for displaying ajax result of consultation,events,reunion
{
	
	if(input=='consultation')
	{
		document.getElementById("consultationdisp").innerHTML='<img src="images/loading.gif" width="100px" height="25px" />';
		requestInfo('includes/rep_reunionAjax.php?input='+input+'&start='+start,'consultationdisp','');
	}
	else if(input=='event')	
	{
		document.getElementById("eventdisp").innerHTML='<img src="images/loading.gif" width="100px" height="25px" />';
		requestInfo('includes/rep_reunionAjax.php?input='+input+'&start='+start,'eventdisp','');	
	}
	else if(input=='reunion')	
	{
		document.getElementById("reuniondisp").innerHTML='<img src="images/loading.gif" width="100px" height="25px" />';
		requestInfo('includes/rep_reunionAjax.php?input='+input+'&start='+start,'reuniondisp','');
	}
	else
	{
	}
	
}

function reuniondetail(id)//Funtion for displaying reunion details
{
	
	
	document.getElementById("reuniondisp").innerHTML='<img src="images/loading.gif" width="100px" height="25px" />';
	requestInfo('includes/rep_reunionAjax.php?input='+'reuniondetails'+'&id='+id,'reuniondisp','');	
}



function accessdetail(id,accid)//Funtion for displaying reunion details
{
	
	
	document.getElementById("reuniondisp").innerHTML='<img src="images/loading.gif" width="100px" height="25px" />';
	requestInfo('includes/rep_reunionAjax.php?input='+'accessdetails'+'&aid='+accid+'&id='+id,'reuniondisp','');	
}

function eventDetail(id)//Funtion for displaying event details
{
	document.getElementById("eventdisp").innerHTML='<img src="images/loading.gif" width="100px" height="25px" />';
	requestInfo('includes/rep_reunionAjax.php?input='+'eventdetails'+'&id='+id,'eventdisp','');	
}


//function for consultation group to view from six categories [Created By: UDAY | 07-DEC-2007]
function show_consultants(id)
{
	for(i=1;i<=6;i++)
	{
		var j='0'+i;
		document.getElementById(j).innerHTML='';
	}
	document.getElementById(id).innerHTML='<div id="load" style = "text-align:center; vertical-align:middle;" ><img src="images/loading.gif" border="0px" align="loading" /></div>';
	requestInfo('includes/consultations_Ajax.php?gid='+id,id,'');
}

function consultationDetail(GID,ID,SHOW)//Funtion for displaying consultation details
{
	document.getElementById("consultationdisp").innerHTML='<img src="images/loading.gif" width="100px" height="25px" />';
	requestInfo('includes/rep_reunionAjax.php?gid='+GID+'&id='+ID+'&show='+SHOW+'&type=curr&input=view','consultationdisp','');
}

function nextrecord(GID,ID,SHOW)//Funtion for displaying next result of consultation details
{
	document.getElementById("consultationdisp").innerHTML='<img src="images/loading.gif" width="100px" height="25px" />';
	requestInfo('includes/rep_reunionAjax.php?gid='+GID+'&id='+ID+'&show='+SHOW+'&type=next&input='+'view','consultationdisp','');
}

function prevrecord(GID,ID,SHOW)//Funtion for displaying prev result of consultation details
{
	document.getElementById("consultationdisp").innerHTML='<img src="images/loading.gif" width="100px" height="25px" />';
	requestInfo('includes/rep_reunionAjax.php?gid='+GID+'&id='+ID+'&show='+SHOW+'&type=prev&input='+'view','consultationdisp','');
}

function accesspop()
{
  var generator=window.open('','name','height=400,width=500');
  
  generator.document.write('<html><head><title>Popup</title>');
  generator.document.write('<link rel="stylesheet" href="style.css">');
  generator.document.write('</head><body>');
  generator.document.write('<table width="650px" align="center" cellpadding="0" cellspacing="0" class="maintable"><tr><td colspan="4" class="pagetitle" height="5px" ></td></tr><tr> <td class="leftTD">Enter Access Code </td> <td class="leftTD"> :</td><td class="rightTD"><form  name="checkaccess" id="checkaccess" method="post" ><input type="text" name="access_code" id="access_code" class="formelement" value="" /><input type="submit" name="submit" id="submit" value="submit"  class="formelement" /></form></td></tr></table>');
 
  generator.document.write('</body></html>');
  generator.document.close();
}

/*function validatecodeaccess(id)
{
	//document.getElementById("reuniondisp").innerHTML='<img src="images/loading.gif" width="100px" height="25px" />';
	document.getElementById("reuniondisp").innerHTML='<img src="images/loading.gif" width="100px" height="25px" />';
	requestInfo('includes/rep_reunionAjax.php?input='+'reuniondetails'+'&id='+id,'reuniondisp','');	
	
}*/



//Script for Consultation,Reunion,Events Professional Ends here
