var xmlHttp
	var xmlHttp1
	
	 function ajaxFunction(){
		
	
			var ajaxRequest;
	
	
	
			try{
	
			// Opera 8.0+, Firefox, Safari
	
			ajaxRequest = new XMLHttpRequest();
	
			} catch (e){// --- 1
	
			// Internet Explorer Browsers
	
			try{
	
				ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
	
			} catch (e) { // ---- 2
	
				try{
	
					ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
	
				} catch (e){
	
					//browsers all not support, rare case
	
					alert("Your browser broke!");
	
					return false;
	
				}
	
			}
	
	
	
		}
	
		return ajaxRequest;
	
	}
	
	function ajax_check_email(str,DivId,loadImg,user_id)
	{ 
		
		if(trim(str)!="" && checkEmail(str)=="success")
		{
			document.getElementById(DivId).innerHTML ='<img src='+loadImg+'>'; 
			var url =root_www+"_ajax_check_email.php?sid=" + Math.random();
			 url +="&email="+str+"&div_id="+DivId;
			if(user_id!=undefined) {
				url +="&user_id="+user_id;
			}			
			xmlHttp=GetXmlHttpObject(stateChanged);
			xmlHttp.onreadystatechange = stateChanged;
			xmlHttp.open("GET", url , true);
			xmlHttp.send(null);
		}else{
			document.getElementById(DivId).innerHTML="Invalid email-id";
				
		}
	   
	}
	

	
	//------------------Captcha Relaod-------------------------------------------------------//
	function ajax_captcha(DivId,loadImg)
	{
	
		document.getElementById(DivId).innerHTML ='<img src='+loadImg+'>';
	
		var url="_ajax_captcha_reload.php?sid=" + Math.random() + "&div_id="+DivId;
		xmlHttp=GetXmlHttpObject(stateChanged);
		xmlHttp.onreadystatechange = stateChanged;
		xmlHttp.open("GET", url , true);
		xmlHttp.send(null);
		
	   
	}
	//---------------------------------------------------------------------------------------//
	
	
	//-----------------Update Event Question Type-------------------------------------------------------//
	function _ajax_update_question_type(eid, type, openId, DivId, styleType)
	{
		
		document.getElementById(DivId).innerHTML ='<img src="images/ajax-loader.gif">';
		document.getElementById(openId).style.display = styleType;
		
		if(styleType == 'none' && openId=='show_att_det')
		{
			document.getElementById('attendee_det_option').checked = true;
			document.getElementById('showTable').style.display ='none';
			document.getElementById('showAddQuestion').style.display ='none';
		}
		var url="_ajax_update_question_type.php?sid=" + Math.random() + "&eid="+eid+"&type="+type+"&div_id="+DivId;
		//location.href = url;
		
		xmlHttp=GetXmlHttpObject(stateChanged);
		xmlHttp.onreadystatechange = stateChanged;
		xmlHttp.open("GET", url , true);

		xmlHttp.send(null);
	}
	//-------------------------------------------------------------------------------------------------//
	
	
	
	//------------------Populate University/Colleges-------------------------------------------------------//
	function showUniversity(val,DivId)
	{
	 
		document.getElementById(DivId).innerHTML ='<img src="images/ajax-loader.gif">';
		var url="_ajax_populate_university.php?sid=" + Math.random() + "&id="+val+"&div_id="+DivId;
		
		xmlHttp=GetXmlHttpObject(stateChanged);
		xmlHttp.onreadystatechange = stateChanged;
		xmlHttp.open("GET", url , true);

		xmlHttp.send(null);
		
	   
	}
	//---------------------------------------------------------------------------------------//
	
	
	//------------------Populate Event Action Tool-------------------------------------------------------//
	function showActionTool(val,DivId)
	{
	 
		document.getElementById(DivId).innerHTML ='<div class="rpanel2"><img src="images/ajax-loader.gif"></div>';
		document.getElementById(DivId).style.opacity = 1;
		var url="_ajax_populate_event_action_tool.php?sid=" + Math.random() + "&id="+val+"&div_id="+DivId;
		
		
		xmlHttp=GetXmlHttpObject(stateChanged);
		xmlHttp.onreadystatechange = stateChanged;
		xmlHttp.open("GET", url , true);

		xmlHttp.send(null);
		
	   
	}
	//---------------------------------------------------------------------------------------//
	
	
	//------------------Send Forget Email-------------------------------------------------------//
	function ajax_forget_mail(email,DivId)
	{
		
		//document.getElementById(DivId).className = 'ajax_forgot_password_cont';
		
		var url="_ajax_send_forget_mail.php?sid=" + Math.random() + "&div_id="+DivId+"&email="+email;
		
		xmlHttp=GetXmlHttpObject(stateChanged);
		xmlHttp.onreadystatechange = stateChanged;
		xmlHttp.open("GET", url , true);

		xmlHttp.send(null);
	
	}
	//---------------------------------------------------------------------------------------//
	
	
	//------------------Edit Contact List-------------------------------------------------------//
	function ajax_editContact(id, eid, DivId)
	{
		
		document.getElementById(DivId).innerHTML ="<img src='images/ajax-loader2.gif'><br><b>Please wait</b>";
	
		
		var url="_ajax_edit_contact_list.php?sid=" + Math.random() + "&div_id="+DivId+"&id="+id+"&eid="+eid;
		
		
		xmlHttp=GetXmlHttpObject(stateChanged);
		xmlHttp.onreadystatechange = stateChanged;
		xmlHttp.open("GET", url , true);

		xmlHttp.send(null);
	
	}
	//---------------------------------------------------------------------------------------//
	
	
	//------------------Edit Annoucements-------------------------------------------------------//
	function ajax_editAnnouncement(id, eid, DivId)
	{
		
		document.getElementById(DivId).innerHTML ="<img src='images/ajax-loader2.gif'><br><b>Please wait</b>";
	
		
		var url="_ajax_edit_annoucements.php?sid=" + Math.random() + "&div_id="+DivId+"&id="+id+"&eid="+eid;
		
		
		xmlHttp=GetXmlHttpObject(stateChanged);
		xmlHttp.onreadystatechange = stateChanged;
		xmlHttp.open("GET", url , true);

		xmlHttp.send(null);
	
	}
	//---------------------------------------------------------------------------------------//
	
	
	//------------------Choose Invitation Template-------------------------------------------------------//
	function ajax_template_choose(id, DivId)
	{
		
		document.getElementById(DivId).innerHTML ="<img src='images/ajax-loader.gif'>";
	
		
		var url="_ajax_choose_template.php?sid=" + Math.random() + "&div_id="+DivId+"&id="+id;
		
		
		xmlHttp=GetXmlHttpObject(stateChanged);
		xmlHttp.onreadystatechange = stateChanged;
		xmlHttp.open("GET", url , true);

		xmlHttp.send(null);
	
	}
	//---------------------------------------------------------------------------------------//
	
	//------------------Update Ticket Qnt-------------------------------------------------------//
	function ajax_ticket_qnt(rootPath,id, qnt, DivId)
	{
		
		var url=rootPath+"/_ajax_ticket_qnt.php?sid=" + Math.random() + "&div_id="+DivId+"&tid="+id+"&qnt="+qnt;
	
	
		
		xmlHttp=GetXmlHttpObject(stateChanged);
		xmlHttp.onreadystatechange = stateChanged;
		xmlHttp.open("GET", url , true);

		xmlHttp.send(null);
	
	}
	//---------------------------------------------------------------------------------------//
	
	//------------------Reset Event Hits-------------------------------------------------------//
	function ajax_reset_hits(id, field, DivId)
	{
	
		if(confirm('Are you sure to reset to zero?'))
		{
			document.getElementById(DivId).innerHTML ="<img src='images/ajax-loader.gif'>";
			
			var url = root_www+"_ajax_reset_hits.php?sid=" + Math.random() + "&div_id="+DivId+"&eid="+id+"&field="+field;
			//location.href = url;
			
			xmlHttp=GetXmlHttpObject(stateChanged);
			xmlHttp.onreadystatechange = stateChanged;
			xmlHttp.open("GET", url , true);
	
			xmlHttp.send(null);
		}
		else
		{
			return false;
		}
	
	}
	//---------------------------------------------------------------------------------------//
	
	function ajax_check_affiliate(str,DivId,loadImg)
	{ 

		var str = trim(str);
		if(str!="" && str.length<6){
			document.getElementById(DivId).innerHTML='Please enter an affiliate name';
			document.getElementById('refid').focus();	
		}
		if(str!="")
		{
			if(str.length<6){
				document.getElementById(DivId).innerHTML='Affiliate Name must be atleast 6 characters';
				document.getElementById('refid').focus();	
			}else{
			
				if(/^[a-z0-9\-]+$/.test(str)==false) {
					document.getElementById(DivId).innerHTML='No special characters allowed in affiliate name';
					document.getElementById('refid').focus();	
				}else{
			
					document.getElementById(DivId).innerHTML ='<img src='+loadImg+'>'; 
					document.getElementById('btnSubmitId').disabled = true;
					var url =root_www+"_ajax_check_affiliate.php?sid=" + Math.random();
					 url +="&aff="+str+"&div_id="+DivId;
					
					xmlHttp=GetXmlHttpObject(stateChanged);
					xmlHttp.onreadystatechange = stateChanged;
					xmlHttp.open("GET", url , true);
					xmlHttp.send(null);
				
				}
			}
		}else{
					document.getElementById(DivId).innerHTML='Please enter an affiliate name';
					document.getElementById('refid').focus();
			}
	   
	}
	
	
	//==============================  CHECK EDit Affiliates ON  EDIT AFFILIATE PAGE =======================================//
	function ajax_check_edit_affiliate(str,DivId,loadImg,email)
	{ 
		var str = trim(str);
		if(str!="" && str.length<6){
			document.getElementById(DivId).innerHTML='Please enter an affiliate name';
			document.getElementById('refid').focus();	
		}
		if(str!="")
		{
			if(str.length<6){
				document.getElementById(DivId).innerHTML='Affiliate Name must be atleast 6 characters';
				document.getElementById('refid').focus();	
			}else{
			
				if(/^[a-z0-9\-]+$/.test(str)==false) {
					document.getElementById(DivId).innerHTML='No special characters allowed in affiliate name';
					document.getElementById('refid').focus();	
				}else{
			
					document.getElementById(DivId).innerHTML ='<img src='+loadImg+'>'; 
					document.getElementById('btnforSubmit').style.display="none";
					var url =root_www+"_ajax_edit_affiliate_name.php?sid=" + Math.random();
					 url +="&aff="+str+"&div_id="+DivId;
					if(email!='' && email!=undefined) {
					 url +="&email="+email;	
					}
			
			
					xmlHttp=GetXmlHttpObject(stateChanged);
					xmlHttp.onreadystatechange = stateChanged;
					xmlHttp.open("GET", url , true);
					xmlHttp.send(null);
				
				}
			}
		}else{
					document.getElementById(DivId).innerHTML='Please enter an affiliate name';
					document.getElementById('refid').focus();
			}
	   
	}
	
	
	
	//==============================  CHECK EMAIL ON AFFILIATE PAGE =======================================//
	function ajax_check_email_on_affiliate(str,DivId,loadImg,user_id)
	{ 
		
		if(trim(str)!="" && checkEmail(str)=="success")
		{
			document.getElementById(DivId).innerHTML ='<img src='+loadImg+'>'; 
			document.getElementById('btnSubmitId').disabled=true;
			var url =root_www+"_ajax_check_affiliate_record.php?sid=" + Math.random();
			 url +="&email="+str+"&div_id="+DivId;
		
			xmlHttp=GetXmlHttpObject(stateChanged);
			xmlHttp.onreadystatechange = stateChanged;
			xmlHttp.open("GET", url , true);
			xmlHttp.send(null);
		}else{
				document.getElementById(DivId).innerHTML="Invalid email-id";
				
		}
	   
	}
	
	
	
	//===================== CHECK AFFILIATE ON EVENT ADD PAGE ======================//
	
	function ajax_check_affiliate_on_event(str,DivId,loadImg)
	{ 
		
		
		if(trim(str)!="")
		{
			document.getElementById(DivId).innerHTML ='<img src='+loadImg+'>'; 
			var url =root_www+"_ajax_check_affiliate_eventpage.php?sid=" + Math.random();
			 url +="&aff="+str+"&div_id="+DivId;			
			
			xmlHttp=GetXmlHttpObject(stateChangedEventADD);
			xmlHttp.onreadystatechange = stateChangedEventADD;
			xmlHttp.open("GET", url , true);
			xmlHttp.send(null);
		}else{
			document.getElementById(DivId).innerHTML="";
				
		}
	   
	}
	
	
	function stateChangedEventADD() 
	{ 
     
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
			var raw_response = xmlHttp.responseText;
			var str = raw_response.split('^');
		
			var divID = str[1];
			if(divID=='err_aff_name' && str[0]== 0){			   
				document.getElementById('parent_affiliate').value='';
				document.getElementById('parent_affiliate').focus();
				document.getElementById('aff_hidden').value=0;
				document.getElementById('aff_user').value =0;
				document.getElementById(divID).innerHTML = "<span style='color:#ff0000;'>This affiliate is not present in our records</span>";
			}else if(divID=='err_aff_name' && str[0]== 1){
				document.getElementById('aff_hidden').value=1;
				document.getElementById('aff_user').value=str[2];
				document.getElementById(divID).innerHTML = "<span style='color:#009900;'>Affiliate verified successfully</span>";	
			}
			
	
	}
	
	}
	
	function stateChanged() 
	{ 
     
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
			
			var raw_response = xmlHttp.responseText;
			
			var str = raw_response.split('^');
			var divID = str[1];	
			
			document.getElementById(divID).innerHTML=str[0];
			
			if(divID=='shwoAction')
			{
				setTimeout('xyz()',3000);
			}
		
			if(divID=='err_email' && str[0]=='Email already exists'){				
				document.getElementById('username').value='';
				document.getElementById('username').focus();
			}
			
			if(str[2]!= null && str[2]=='mainsignup'){
					
				if(divID=='err_aff'){
					if(str[0]==0){	
						document.getElementById(divID).innerHTML = "<span style='color:#009900;'>Affiliate code verified successfully</span>";
					}
					if(str[0]==1){
						document.getElementById('parent_aff').value='';
						document.getElementById(divID).innerHTML = "There is no affiliate with this name";
					}
					document.getElementById('btnSubmitId').disabled=false;
				}
					
			}else if(str[2]!= null && str[2]=='Editaffiliate'){
				if(divID=='err_aff'){
						if(str[0]==0){
							document.getElementById('refid').value='';
							document.getElementById(divID).innerHTML = "This affiliate name is not register with UticketIt.";
						}
						if(str[0]==1){							
							document.getElementById('affiliate_approved').value=str[3];
							document.getElementById('affiliate_id').value=str[4];
							document.getElementById(divID).innerHTML = "<span style='color:#009900;'>Affiliate name verify successfully.</span>";
						}
						if(str[0]==2){
							document.getElementById(divID).innerHTML = "This affiliate name is registered with another email. Do you still want to continue.";
						}
						document.getElementById('btnforSubmit').disabled = false;;
					}	
			}else{
			
				if(divID=='err_aff'){
					if(str[0]==0){	
						document.getElementById('refid').value='';
						document.getElementById('refid').focus();
						document.getElementById(divID).innerHTML = "This affiliate name is not available";
					}
					if(str[0]==1){	
						document.getElementById(divID).innerHTML = "<span style='color:#009900;'>This affiliate name is available</span>";
					}
					document.getElementById('btnSubmitId').disabled=false;
				}
			}
			
			if(divID=='err_email_aff'){
			var responseStr =str[0].split('-');
			
				if(responseStr[0]==0){	
					document.getElementById('affStatus').value = responseStr[0];
					document.getElementById('pp_email').value = responseStr[1];
					document.getElementById('username').value='';
					document.getElementById('username').focus();
					document.getElementById(divID).innerHTML = "This email is already used";
				}
				if(responseStr[0]==1){
					//document.getElementById('affStatus').value = str[0];
					//document.getElementById(divID).innerHTML = "This email is registered to UTicketIt but not an affiliate, you can continue";	
					document.getElementById('affStatus').value = responseStr[0];
					document.getElementById('pp_email').value = responseStr[1];
					document.getElementById('username').value='';
					document.getElementById('username').focus();
					document.getElementById(divID).innerHTML = "This email is already used";
				}
				if(responseStr[0]==2){
					document.getElementById('affStatus').value = responseStr[0];
					document.getElementById('pp_email').value = responseStr[1];
					document.getElementById('username').value='';
					document.getElementById('username').focus();
					document.getElementById(divID).innerHTML = "This email is already used";
					//	document.getElementById(divID).innerHTML = "This email is already an affiliate to UTicketIt";
				}
				
				if(responseStr[0]==3){
					document.getElementById('affStatus').value = responseStr[0];
					document.getElementById('pp_email').value = responseStr[1];
					document.getElementById(divID).innerHTML = "<span style='color:#009900;'>You can register with this email</span>";
				}
				document.getElementById('btnSubmitId').disabled=false;
			}
		} 
	
	}
	
	
	/*====================================  AJAX CHECK AFFILIATE ON SIGN UP ========================================= */
	
	function ajax_check_affiliate_main(str,DivId,loadImg)
	{ 
		
		var str = trim(str);
		
		if(str!="")
		{
			document.getElementById(DivId).innerHTML ='<img src='+loadImg+'>'; 
			document.getElementById('btnSubmitId').disabled=true;
			var url =root_www+"_ajax_check_affiliate.php?sid=" + Math.random();
			url +="&aff="+str+"&div_id="+DivId+"&mainsignup=1";
		
			xmlHttp=GetXmlHttpObject(stateChanged);
			xmlHttp.onreadystatechange = stateChanged;
			xmlHttp.open("GET", url , true);
			xmlHttp.send(null);
				
		}
	   
	}
	
	function xyz()
	{
		document.getElementById('shwoAction').style.opacity = 100;
	}
	 
	/*function GetXmlHttpObject(handler)
	{ 
		var objXmlHttp=null
		
		if (navigator.userAgent.indexOf("Opera")>=0)
		{
			alert("This example doesn't work in Opera") 
			return 
		}
		if (navigator.userAgent.indexOf("MSIE")>=0)
		{ 
			var strName="Msxml2.XMLHTTP"
			if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
			{
				strName="Microsoft.XMLHTTP"
			} 
			try
			{ 
				
				objXmlHttp=new ActiveXObject(strName)
				objXmlHttp.onreadystatechange=handler 
				return objXmlHttp
			} 
			catch(e)
			{ 
				alert("Error. Scripting for ActiveX might be disabled") 
				return 
			} 
		} 
		if (navigator.userAgent.indexOf("Mozilla")>=0)
		{
			
			objXmlHttp=new XMLHttpRequest()
			objXmlHttp.onload=handler
			objXmlHttp.onerror=handler 
			return objXmlHttp
		}
	}*/ // JavaScript Document
	
	function GetXmlHttpObject(handler)
	{ 
		if (window.XMLHttpRequest)
			  {// code for IE7+, Firefox, Chrome, Opera, Safari
			  
			  return new XMLHttpRequest();
			  }
			else
			  {// code for IE6, IE5
			  return new ActiveXObject("Microsoft.XMLHTTP");
			  }
			  return null;
	} 
	
	
	
