// 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)
{ 
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];
		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 strVal = rmWhiteSpace(check);
			var check1 = strVal.split("~~~~~~~~~~");
			
			if (check1[0]=="PDFSUCESSFULLYGENERATED")
				{
				document.getElementById("pdfDivProcess").style.display = "none";
				document.getElementById(check1[1]).innerHTML="<a title=\"Order Detail\" href=\"download.php?fileName="+check1[2]+">Download PDF</a>";
				}
			
			if (strVal=="PAYMENTAPPROVED")
				{
				var sessId = document.getElementById('sessionId').value;
				window.location.href="cart-thanks.php?sessId="+sessId;
				}	
			
			if (strVal=="PAYMENTNOTAPPROVED")
				{
				var sessId = document.getElementById('sessionId').value;
				window.location.href="cart-thanks.php?sessId="+sessId;
				}		
			if (strVal=="THANKSCART")
				{
				var sessId = document.getElementById('sessionId').value;
				window.location.href="cart-thanks-bulk.php?sessId="+sessId;
				}			
			if (strVal=="SuccessfullyBulkLogin")
				{
				var sessId = document.getElementById('sessionId').value;
				window.location.href="cart-thanks-bulk.php?sessId="+sessId;
				}				
			if (strVal=="CREDITCARDUPDATE")
				{
				window.location.href="confirm-order.php";
				}	
			if (strVal=="USERNOTAVAILABLE")
				{
				window.location.href="login.php";
				}	
			if (check1[0]=="CustomizeSuccessfully")
				{
				window.location.href='designyourtshirt.php?designId='+check1[1];	
				}
				
			var newvar=strVal.split('#');

			if (strVal=="<fontcolor=#FF0000>SuccessfullyLogin</font>")
				{
				window.location.href='cartuserinfo.php';
				}	
			
			if (strVal=="Recordinsertedsuccessfully" || strVal=="Recordupdatedsuccessfully")
				{
				window.location.href='payment.php';
				//window.location.href='https://www.customshirts.com/sparx/payment.php';
				}
				
			if(strVal=="SizeSuccessfullyInserted") 
				{	
				document.getElementById(div_name_content).innerHTML= check;
				var conVal = confirm("Do you want to enter more Size");
				if (conVal==false)
					window.location.href = "product_size.php";	
			     }
			
			if (strVal=="ProductViewInsertedSuccessfully")
				{
				document.getElementById(div_name_content).innerHTML= check;
				var conVal = confirm("Do you want to enter more Product Views");
				if (conVal==false)
					window.location.href = "prod_view.php";	
				}
			
			if (strVal=="ProductViewUpdatedSuccessfully")
				{
				document.getElementById(div_name_content).innerHTML= check;
				window.location.href = "prod_view.php";	
				}
			
			if(strVal=="SizeSuccessfullyUpdated") 
				{	
				document.getElementById(div_name_content).innerHTML= check;
				window.location.href = "product_size.php";	
			    }
			
			if (strVal=="ProductSuccessfullyAssignInCategory")
				{
				window.setTimeout("window.close()", 1);
				opener.location.reload(true);
				}
				
			if (strVal=="DesignSuccessfullyAssign")
				{
				window.setTimeout("window.close()", 1);
				//opener.location.reload(true);
				}	

			if (strVal=="ColorInsertedSuccessfully")
				{
				document.getElementById(div_name_content).innerHTML= check;
				var conVal = confirm("Do you want to add another color?");
				if (conVal==false)
			  		window.location.href = "color-detail.php";	
				}
			if (strVal=="ColorUpdatedSuccessfully")
				{
			  	window.location.href = "color-detail.php";	
				}
			
			if(check=="USER_SUCESSFULLY_INSERTED") 
			{	
				document.getElementById(div_name_content).innerHTML= check;
				var conVal = confirm("Do you want to enter more user");
				if (conVal==true)
					document.getElementById('divMessage').innerHTML = "<b>Record Successfully Inserted</b>";
				else
			  		window.location.href = "user_detail.php";	
		     }
			
			if(strVal=="CategorieSuccessfullyinserted") 
			{	
				document.getElementById(div_name_content).innerHTML= check;
				var conVal = confirm("Do you want to Add more Categories");
				if (conVal==true)
					document.getElementById('divMessage').innerHTML = "<b>Record Successfully Inserted</b>";
				else
			  		window.location.href = "category.php";	
		     }
		if(strVal=="CategoryUpdatedSuccessfully") 
			{	
			window.location.href = "category.php";
		    }
			
		if(strVal=="SubCategorySuccessfullyInserted") 
			{	
			document.getElementById(div_name_content).innerHTML= check;
			var conVal = confirm("Do you want to Add more Sub Categories");
			if (conVal==true)
				document.getElementById('divMessage').innerHTML = "<b>Record Successfully Inserted</b>";
			else
				window.location.href = "des_sub_cat.php";	
			}
		
		if(strVal=="SubCategoryUpdatedSuccessfully") 
			{	
			document.getElementById(div_name_content).innerHTML= check;
			window.location.href = "des_sub_cat.php";	
			}

		if(strVal=="MenuInserted") 
			{	
				document.getElementById(div_name_content).innerHTML= check;
				var conVal = confirm("Do you want to Add more Menus");
				if (conVal==true)
					document.getElementById('divMessage').innerHTML = "<b>Record Successfully Inserted</b>";
				else
			  		window.location.href = "view-front-menu.php";	
		     }
		if(strVal=="FebrucInserted") 
			{	
			document.getElementById(div_name_content).innerHTML= check;
			var conVal = confirm("Do you want to Add more Febric");
			if (conVal==true)
				document.getElementById('divMessage').innerHTML = "<b>Record Successfully Inserted</b>";
			else
				window.location.href = "manage-febric.php";	
		     }

		if(strVal=="BrandSuccessfullyinserted ") 
			{	
			document.getElementById(div_name_content).innerHTML= check;
			var conVal = confirm("Do you want to Add more Brand");
			if (conVal==true)
				document.getElementById('divMessage').innerHTML = "<b>Record Successfully Inserted</b>";
			else
				window.location.href = "view-front-menu.php";	
		     }
			 
		if(strVal=="OrderStatusInserted") 
			{	
			document.getElementById(div_name_content).innerHTML= check;
			var conVal = confirm("Do you want to Add more Order Status");
			if (conVal==true)
				document.getElementById('divMessage').innerHTML = "<b>Record Successfully Inserted</b>";
			else
				window.location.href = "order-status-detail.php";	
		     }
			 
		 if (strVal=='SuccessfullyLogin')
			{
			var cartTotalItem = document.getElementById('totalItemCart').value;
			
			if (cartTotalItem==0 || cartTotalItem==null || cartTotalItem=='')
				window.location.href = "myaccount.php";
			else
				window.location.href = "cartuserinfo.php";
			}
				
			if (strVal=="PAYMENTUPDATE")
				{
				window.location.href='payment-process.php';
				}

			if (strVal=='YourImageisstoredsuccessfully')
				{
				window.location.href = "login.php";
				}
			if (strVal=='photouploadlogin')
				{
				var session = document.getElementById('sessionId').value;
				
				window.location.href = "customer-photo.php?sessId="+session;
				}
			if (strVal=='SuccessfullyLogout')
				{
				window.location.href = "index.php";
				}
				
			if (strVal=='OldOrderSuccessfullyBuy')
				{
				window.location.href = "display-cart.php";
				}
			if (strVal=='RecordUpdated')
				{
				window.location.href = "display-cart.php";
				}	
			if (strVal=='<b>Yourpasswordupdatedsuccessfully,Itwillreflectwhenyoulogoutandagainlogin.</b>')
				{
				window.location.href = "changepassword.php";
				}	
			
			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;
	}

function checkNumber(data , checkType)
	{
	if (checkType=='PRICE')
		var iChars = "!@#$%^&*()+=-[]\\\';,/{}|\":<>?~_A-Zaz"; 
	else
		var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?~_A-Zaz"; 
		
	var retVal = 0;
	for (var i = 0; i < data.length; i++) {
			if (iChars.indexOf(data.charAt(i)) != -1) {
				retVal = 1;
				break;
			}
		}
	return retVal;	
	}