// Get base url
	url = document.location.href;
	xend = url.lastIndexOf("/") + 1;
	var base_url = url.substring(0, xend);
	var div_name= new Array; 
	var form_name = new Array;
	var div_indicator = new Array; 
	var form_name1="";
	var no_of_divs = "";
	var div_name_content = "";
	var url_next = "";
	var empty_form = "";
	var gen_type='N'

function showUser(url)
{ 
	//	alert(url);
	var randNo = Math.random(1,50);
url = url+"~randNo="+randNo;

	var url1 = url.split('&');
	var url2 = url1[0].split('=');//
	if(url2[0] == 'no_of_divs')
		no_of_divs = url2[1];

	var i=1;
	var j=0;
  	var url_run = new	Array();
	while(i <= no_of_divs)
	{
		j=i-1;
		url_links = url1[i].split("##");
		url_run[j] = url_links[1].replace(/~/g, '&');
		i++;
	}

	 //alert("URLS=>>" + url_run);

	var url_values1 = "";
	var url_values = "";
	var j=0;
	var i =0;

	while(i < no_of_divs) 
	{
		url_values1 = url_run[i].split('?');	
		url_values = url_values1[1].split('&');	
		//alert(url_values);
		length1 = url_values.length;
		j = 0;
		while(j < length1) 
		{
			url_val = url_values[j].split('=');
			if(j == 0)
			{
				div_indicator[i] = 'Empty';	
				form_name[i] = 'Empty';	
						}
						if(url_val[0] == 'div')
							{
								div_name[i] = url_val[1];
							}
							
						if(url_val[0] == 'div_indicator')
							{
								div_indicator[i] = url_val[1];	
							}
						if(url_val[0] == 'form')
							{
							form_name[i] = url_val[1];	
							var form_name_gen = url_val[1];	
							}
						if(url_val[0] == 'url_next')
							url_next = url_val[1];	
						if(url_val[0] == 'empty_form')
							empty_form = url_val[1];
						if(url_val[0] == 'type')
							gen_type = url_val[1];	
						if(url_val[0] == 'abc_value')
							obj_charity = url_val[1];	
						j++;
					}
	
		//alert("Div Name == " + div_name[i]);
		//alert("Form Name == " + form_name[i]);
		//alert("Div Indicator== " + div_indicator[i]);
		if(div_indicator[i] != 'Empty')
			{
				document.getElementById(div_indicator[i]).innerHTML= "<img src='images/indicator.gif'>";
			}
		i++;
	}
	//alert("Processing  begins...........");
	var j=0;
	var i =0;
	//alert ("DDDDDD "  + document.frm_crafity.contName.value);
//alert ("DDDDDD "  + document.getElementById('contName').value);
while(i < no_of_divs) 
	{
		div_name_content= "";
		div_name_content = div_name[i];
		
		divTempContent = "";
		divTempContent = div_name[i];
		
		url = url_run[i];
		
		//alert ("div_name_content    " + div_name_content)
		
		if(gen_type=='Y')
			url = generate_url(url,form_name_gen);   // Comment By Rohit Chaudhary
			
			http_request(url);
		i++;
	}
  }

function GetXmlHttpObject()
		{
			var xmlHttp=null;
			try
			{
			 // Firefox, Opera 8.0+, Safari
			 xmlHttp=new XMLHttpRequest();
			}
			catch(e)
			 {
			 //Internet Explorer
				 try
				  {
				  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
				  }
				 catch (e)
				  {
				  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				  }
			  }
			 return xmlHttp;
		} 



function generate_url(url, form_name1)
	{
	var len = "";	
if(form_name1 != "Empty")
		  {
			len=document.getElementById(form_name1).elements.length;
			//alert ("LENGTH " + len);
			 var i=0;
			  var value="";
			  while(i!=len)
				{
					if(document.getElementById(form_name1).elements[i].type == "checkbox")
						{
							if(document.getElementById(form_name1).elements[i].checked == true)
								{
									value= value + "&" + document.getElementById(form_name1).elements[i].name + "=" + document.getElementById(form_name1).elements[i].value;
								}
						}
					else if(document.getElementById(form_name1).elements[i].type == "radio")
					{
					if(document.getElementById(form_name1).elements[i].checked == true)
						{
						value= value + "&" + document.getElementById(form_name1).elements[i].name + "=" + document.getElementById(form_name1).elements[i].value;
						}
					}
					else
					{
					value= value + "&" + document.getElementById(form_name1).elements[i].name + "=" + document.getElementById(form_name1).elements[i].value;
					}
					i++;
				}
			url=url + value;
			//alert("GENEARET "  +url);
		  }
	return url;
	}



function http_request(url)
	{
	xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null)
		 {
			 alert("Browser does not support HTTP Request")
			 return
		 }
		xmlHttp.onreadystatechange=stateChanged
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
	}



function stateChanged() 
	{ 
	 if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
			var check  = xmlHttp.responseText;
			var check1 = check.split("~~~");
			
			
			if(check1[1]=='DATESEARCH')
			{
				window.location.href="writting-report.php?fromDate="+check1[2]+"&toDate="+check1[3]+"&status="+check1[4];		  
			}
			if(check1[1]=='DATESEARCHTALENT')
			{
				window.location.href="talent-report.php?fromDate="+check1[2]+"&toDate="+check1[3]+"&status="+check1[4];		  
			}
			if(check1[1]=='DATESEARCHART')
			{
				window.location.href="art-report.php?fromDate="+check1[2]+"&toDate="+check1[3]+"&status="+check1[4];		  
			}
			if(check1[1]=='SEARCHQUESTION')
			{
				window.location.href="quest-display.php?classId="+check1[2]+"&subId="+check1[3]+"&setId="+check1[4];		  
			}
			if(check1[1]=='CHECKJOKELOGIN')
			{
				window.location.href="login.php?jokeId="+check1[2];		  
			}
			var check2 = check.split("~~~");
			if(check2[1]=='DICUPDATE')
			{
			  window.location.href="dictionary-eng-report.php?letter="+check1[2];		  
			}
			var check3 = check.split("~~~");
			if(check3[1]=='DICUPDATEHINDI')
			{
			  window.location.href="dictionary-hindi-report.php?letter="+check3[2];		  
			}
			var check4 = check.split("~~~");
			if(check4[1]=='DELETEPARENT')
			{
				var val=rmWhiteSpace(check4[3])
				document.getElementById('hiddenFlagPage'+check4[2]).value=val; 
			}
			var check5 = check.split("~~~");
			if(check5[1]=='NOOFHIT')
			{
				window.location.href=check5[2];		  
			}
			
			
			var strVal = rmWhiteSpace(check);
			
			if(strVal=="<center><b>SucessfullyLogin</b></center>"){
				window.location.href = "admin_area.php";}
			if(strVal=="Sucessfullyloginforjoke")
			   {
				window.location.href = "thanks.php?msg=Thanks for submitting your joke.";
				}
			
			if(strVal=="MAILSENTSUCESSFULLY")
				{
				document.getElementById('divComposeIndicator').style.display = 'none';
				document.getElementById('mailTo').value = '';
				document.getElementById('mailSubject').value = '';
				document.getElementById('mailTextArea').value = '';
			    }
			if(strVal=="DICTADD")
				{
				  var con = confirm("Do you want to enter more words");
				  var letter = document.getElementById('letterVal').value;
				  if (con==true)
					{
					window.location.href='add-eng-dictionary.php';
					}
					else
					window.location.href='dictionary-eng-report.php?letter='+letter;
			    }	 
				if(strVal=="DICADDHINDI")
				{
				  var con = confirm("Do you want to enter more words");
				  var letter = document.getElementById('letterValHindi').value;
				  if (con==true)
					{
					window.location.href='add-hindi-dictionary.php';
					}
					else
					window.location.href='dictionary-hindi-report.php?letter='+letter;
			    }	
			if(strVal=="INSERTBANNERPAGE")
				{
				  var con = confirm("Do you want to again save your records?");
				  if (con==true)
					{
					window.location.href='add-banner-assign-page.php';
					}
					else
					window.location.href='banner-assign-page-report.php';
			    }	 	
		
			if(strVal=="PollInsertedSucessfully") 
				{	
				document.getElementById(div_name_content).innerHTML= check;
				var conVal = confirm("Do you want to enter more");
				if (conVal==false)
					window.location.href = "polling.php";
			     }
			
			if(strVal=="ReplyInsertedSucessfully") 
				{	
				document.getElementById(div_name_content).innerHTML= check;
				var conVal = confirm("Do you want to enter more");
				if (conVal==false)
					window.location.href = "forum-report.php";
			     }
				
			
			if(strVal=="PollUpdatedSucessfully"){
				window.location.href = "polling.php";}
			
			
			if(strVal=="GreetingCategorySucessfullyInserted") 
				{	
				document.getElementById(div_name_content).innerHTML= check;
				var conVal = confirm("Do you want to enter more??");
				if (conVal==false)
					window.location.href = "greeting-category.php";
			     }
			
			if(strVal=="GreetingCategorySucessfullyUpdated"){
				window.location.href = "greeting-category.php";}
			
			if(strVal=="SucessfullyInserted") 
				{	
				document.getElementById(div_name_content).innerHTML= check;
				var conVal = confirm("Do you want to enter more");
				if (conVal==false)
					window.location.href = "view_front_menu.php";	
			     }
			
			if(strVal=="SucessfullyUpdated") 
				{	
				window.location.href = "view_front_menu.php";	
			    }

			if (strVal=="QuestionAdded")
				{
				window.location.href="polling.php";
				}	
			
			if(strVal=="RecordInsertedSucessfully") 
				{	
				document.getElementById('divTemp').innerHTML = "<b>Record Sucessfully Inserted</b>";
				var conVal = confirm("Do you want to Add more Record??");
				if (conVal==true)
					document.getElementById('jokeDescription').focus();
				else
					window.location.href = "jokes-report.php";
				}
			
			if(strVal=="RecordUpdatedSucessfully")
				{
				window.location.href = "jokes-report.php";
				}

			if(strVal=="ClassSucessfullyInserted") 
				{	
				document.getElementById('divMessage').innerHTML = "<b>Class Sucessfully Inserted</b>";
				var conVal = confirm("Do you want to Add more Record??");
				if (conVal==false)
					window.location.href = "class-display.php";
				}
			
			if(strVal=="ClassSucessfullyUpdated")
				{
				window.location.href = "class-display.php";
				}
			
			if(strVal=="SubjectSucessfullyInserted") 
				{	
				document.getElementById('divMessage').innerHTML = "<b>Subject Sucessfully Inserted</b>";
				var conVal = confirm("Do you want to Add more Record??");
				if (conVal==false)
					window.location.href = "subject-display.php";
				}
			
			if(strVal=="SubjectSucessfullyUpdated")
				{
				window.location.href = "subject-display.php";
				}
			
			
			if(strVal=="SetSucessfullyInserted") 
				{	
				document.getElementById('divMessage').innerHTML = "<b>Set Sucessfully Inserted</b>";
				var conVal = confirm("Do you want to Add more Record??");
				if (conVal==false)
					window.location.href = "sets-display.php";
				}
			
			if(strVal=="SetSucessfullyUpdated")
				{
				window.location.href = "sets-display.php";
				}
			if(strVal=="MemberInserted")
				{
				window.location.href = "membership-process.php";
				}
			
			if(strVal=="SectionSucessfullyInserted") 
				{	
				document.getElementById('divMessage').innerHTML = "<b>Section Sucessfully Inserted</b>";
				var conVal = confirm("Do you want to Add more Record??");
				if (conVal==false)
					window.location.href = "section-display.php";
				}
			
			if(strVal=="SectionSucessfullyUpdated")
				{
				window.location.href = "section-display.php";
				}
			if(strVal=="<fontcolor=#990000>SucessfullyLogin</font>")
				{
				var refPage = document.getElementById('refererPage').value;	
				window.location.href = refPage;
				}
			if(strVal=="MenuInserted") 
				{	
					document.getElementById('divMessage').innerHTML = "<b>Record Sucessfully Inserted</b>";
					var conVal = confirm("Do you want to Add more Menus");
					if (conVal==false)
						window.location.href = "view_front_menu.php";
				 }	
			if (strVal=='SucessfullyLogout')
				{
				window.location.href = "index.php";
				}
			if (strVal=='Password successfully changed')
				{
				alert("sfsdf");
				}
			
			if (strVal=='ProductAdded') //for shopping cart
				{
				window.location.href = "display-cart.php";
				}
			//if (strVal=="Update")//for shopping cart	
			if (strVal=="<fontcolor=#FFFFFF>Update</font>") 
				{
				window.location.href = "display-cart.php";
				}
			
			if (strVal=='Recordinsertedsucessfully') //for shopping cart
				{
				window.location.href = "payment.php";
				}
			if (strVal=="<fontcolor=#990000>SucessfullyLoginToCart</font>") 
				{
				window.location.href = "checkout.php";
				}
			if (strVal=="CREDITCARDUPDATE") 
				{
				window.location.href = "confirm-order.php";
				}	
			if (strVal=="confirm") 
				{
				window.location.href = "cart-thanks.php";
				}
			if (strVal=="SuccefullyLoginToQuiz") 
				{
				window.location.href = "quiz-rule.php";
				}
			if (strVal=="NotallowedtoplayQuizwithoutCopounNo") 
				{
				window.location.href = "quiz.php";
				}
			if(strVal=="QuestionInsertedSucessfully") 
				{	
				document.getElementById('divTemp').innerHTML = "<b>Question Sucessfully Inserted</b>";
				var conVal = confirm("Do you want to Add more Record??");
				if (conVal==true)
					document.getElementById('quesDescription').focus();
				else
					window.location.href = "forum-report.php";
				}
				if(strVal=='<fontcolor=#990000>SucessfullyLogin.</font>')
				  {
					 document.frmWriting.submit();
				  }
				  //<font color=#990003>Sucessfully Login.</font>
				 if(strVal=='<fontcolor=#990003>SucessfullyLogin.</font>')
				  {
					 document.frmGreen.submit();
				  }
				if(strVal=='<fontcolor=#990033>SucessfullyLogin.</font>')
				  {
					 document.frmTalent.submit();
				  }
				if(strVal=='<fontcolor=#990066>SucessfullyLogin.</font>')
				  {
	 					document.frmPeep.submit();
				  }
				if(strVal=='UserDetailInsertedsuccessfully')
				  {
					  add = confirm("Do you want to add more user.");
					  if(add==true)
					  window.location.href = "user.php";
					  else
					  window.location.href = "user_detail.php";   
				  }
				  if(strVal=='ResultTextInserted')
				  {
					var conVal = confirm("Do you want to Add more Result?");
					if (conVal==true)
						document.getElementById('titleId').focus();
					else
						window.location.href = "peep-hole-resultmanage.php";
				  }
				  
				  var checkres = check.split("~~~");
				  if(checkres[0]=='Question Inserted')
				  {
					  document.frmQuestion.reset();
					  var conVal = confirm("Do you want to Add more Question?");
					  if (conVal==true)
					  	document.getElementById('titleId').focus();
					  else
						window.location.href = "peep-hole-question.php?title="+checkres[1];
				  }
					 
				if(strVal=='DIRECTINBOX')
				   {
					window.location.href='peep-hole-result?title=Your message has been sent';
				   }
					document.getElementById(div_name_content).innerHTML= check;
		} 
	}	
	

function pause(millisecondi)
	{
		var now = new Date();
		var exitTime = now.getTime() + millisecondi;
		while(true)
		{
			now = new Date();
			if(now.getTime() > exitTime)
			return;
		}
	}

function urlGenerate(url)
	{
	//alert (url)
	var type='Y';
	var url = url+'~type='+type;
	showUser(url);
	return true;
	}
	
function logout_validation()
	{
	showUser('no_of_divs=1&link1##process_login.php?div=divLogout~action=logout');	
	}	


function is_email(email)
	{
		if(!email.match(/^[A-Za-z0-9\._\-+]+@[A-Za-z0-9_\-+]+(\.[A-Za-z0-9_\-+]+)+$/))
			return false;
		return true;
	}
	
function rmWhiteSpace(str)
	{
	str = str.replace(/\s+/g,'');
	return str;
	}
