// 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];
		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("~~~~~~~~~~");
			//alert(strVal);
			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 (check1[0]=="BULKORDERGENERATEDSUCESFULLY")
				{
				document.getElementById("pdfDivProcess").style.display = "none";
				document.getElementById(check1[1]).innerHTML="<a title=\"Order Detail\" href=\"download-bulkorderpdf.php?fileName="+check1[2]+">Download PDF</a>";
				}
			
			if (strVal=="PAYMENTAPPROVED")
				{
				var sessId = document.getElementById('sessionId').value;
				var secUrl = document.getElementById('secUrl').value;
				window.location.href = secUrl+"cart-thanks.php?sessId="+sessId;
				}	
			
			if (strVal=="PAYMENTNOTAPPROVED")
				{
				var sessId = document.getElementById('sessionId').value;
				var secUrl = document.getElementById('secUrl').value;
				window.location.href = secUrl+"cartunable.php";
				}
				
			if (strVal=="THANKSCART")
				{
				var sessId = document.getElementById('sessionId').value;
				window.location.href="cart-thanks-bulk.php?sessId="+sessId;
				}			
			if (strVal=="SucessfullyBulkLogin")
				{
				var sessId = document.getElementById('sessionId').value;
				window.location.href="cart-thanks-bulk.php?sessId="+sessId;
				}				
			if (strVal=="CREDITCARDUPDATE")
				{
				var secUrl = document.getElementById('secUrl').value;
				window.location.href = secUrl+"confirm-order.php";
				}	
			if (strVal=="CREDITCARDUPDATEGIFT")
				{
				var secUrl = document.getElementById('secUrl').value;
				window.location.href = secUrl+"thanks.php";
				}									
			if (strVal=="USERNOTAVAILABLE")
				{
				window.location.href = "login.php";
				}	
			if (check1[0]=="CustomizeSucessfully")
				{
				window.location.href='designyourtshirt.php?designId='+check1[1];	
				}
				
			var newvar=strVal.split('#');
			/*if (newvar[0]=="SucessfullyLogin")
				{
				window.location.href='cartuserinfo.php?userHash='+newvar[1];
				}*/	
			if (strVal=="<fontcolor=#FF0000>SucessfullyLogin</font>")
				{
				var secUrl = document.getElementById('secUrl').value;
				window.location.href = secUrl+'cartuserinfo.php';
				}	
				
			if (strVal=="<fontcolor=#FF0000>SucessfullyLoginGift</font>")
				{
				var secUrl = document.getElementById('secUrl').value;
				window.location.href = secUrl+'cartgiftuserinfo.php';
				}		
			
			if (strVal=="Recordinsertedsucessfully" || strVal=="Recordupdatedsucessfully")
				{
				var secUrl = document.getElementById('secUrl').value;
				window.location.href = secUrl+'payment.php';
				}
			if (strVal=="Recordinsertedsucessfullygift" || strVal=="Recordupdatedsucessfullygift")
			{
				var secUrl = document.getElementById('secUrl').value;
				window.location.href = secUrl+'paymentgift.php';
			}	
			
			if (strVal=="SHIPZIPCODEERROR")
				{
				document.getElementById('divProcess1').style.display = 'none';
				document.getElementById('divProcess2').style.display = 'block';
				document.getElementById('shipZipPostCode').style.border = '1px solid #FF0000';
				document.getElementById('billZipPostCode').style.border = '1px solid #A7A6AA';
				document.getElementById('shipZipPostCode').focus();
				document.getElementById('shipZipPostCode').select();
				document.getElementById('divProcess2').innerHTML = "<div class='messageError'>Please specify correct Shipping zip/postal code</div>";
				}
			
			if (strVal=="BILLZIPCODEERROR")
				{
				document.getElementById('divProcess1').style.display = 'none';
				document.getElementById('divProcess2').style.display = 'block';
				document.getElementById('billZipPostCode').style.border = '1px solid #FF0000';
				document.getElementById('shipZipPostCode').style.border = '1px solid #A7A6AA';
				document.getElementById('billZipPostCode').focus();
				document.getElementById('billZipPostCode').select();
				document.getElementById('divProcess2').innerHTML = "<div class='messageError'>Please specify correct Billing zip/postal code</div>";
				}
			
			if (strVal=="SHIPBILLZIPCODEERROR")
				{
				document.getElementById('divProcess1').style.display = 'none';
				document.getElementById('divProcess2').style.display = 'block';
				document.getElementById('billZipPostCode').style.border = '1px solid #FF0000';
				document.getElementById('billZipPostCode').focus();
				document.getElementById('billZipPostCode').select();
				document.getElementById('shipZipPostCode').style.border = '1px solid #FF0000';
				document.getElementById('divProcess2').innerHTML = "<div class='messageError'>Please specify correct Billing zip/postal code<br>Please specify  Shipping zip/postal code</div>";
				}
					
			if (strVal=="<divclass='messageError'>Pleasespecifycorrectzip/postalcode</div>")
				{
				document.getElementById('postCode').style.border = '1px solid #FF0000';
				document.getElementById('postCode').focus();
				document.getElementById('postCode').select();
				document.getElementById('divImageVarification').innerHTML = "<div class='messageError'>Please specify correct zip / postal code</div>";
				}
			
			if (strVal=="REGISTRATIONSUCESS")
				{
				document.getElementById('divImageVarification').style.display = 'none';
				//document.getElementById('sign-up-hd').style.display 		  = 'none';
				document.getElementById('signup1').style.display 			  = 'none';
				document.getElementById('divMainRegistration').innerHTML = "<div class='messageSucess' style='margin-top:30px;'><b>THANK YOU </b>for registering with us!<br><br>We would like to WELCOME you to Custom Shirts! Your password  has been sent to your emailId You are the newest member to our fun filled and creative family! We hope you enjoy the site and please do not hesitate to ask us if you need anything! <b>Please check your registered email and click the provided link to activate your membership!</b></div>";
				}
			
				
			if(strVal=="SizeSucessfullyInserted") 
				{	
				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=="ProductViewInsertedSucessfully")
				{
				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=="ProductViewUpdatedSucessfully")
				{
				document.getElementById(div_name_content).innerHTML= check;
				window.location.href = "prod_view.php";	
				}
			
			if(strVal=="SizeSucessfullyUpdated") 
				{	
				document.getElementById(div_name_content).innerHTML= check;
				window.location.href = "product_size.php";	
			    }
			
			if (strVal=="ProductSucessfullyAssignInCategory")
				{
				window.setTimeout("window.close()", 1);
				opener.location.reload(true);
				}
				
			if (strVal=="DesignSucessfullyAssign")
				{
				window.setTimeout("window.close()", 1);
				//opener.location.reload(true);
				}	

			if (strVal=="ColorInsertedSucessfully")
				{
				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=="ColorUpdatedSucessfully")
				{
			  	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 Sucessfully Inserted</b>";
				else
			  		window.location.href = "user_detail.php";	
		     }
			
			if(strVal=="CategorieSucessfullyinserted") 
			{	
				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 Sucessfully Inserted</b>";
				else
			  		window.location.href = "category.php";	
		     }
		if(strVal=="CategoryUpdatedSucessfully") 
			{	
			window.location.href = "category.php";
		    }
			
		if(strVal=="SubCategorySucessfullyInserted") 
			{	
			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 Sucessfully Inserted</b>";
			else
				window.location.href = "des_sub_cat.php";	
			}
		
		if(strVal=="SubCategoryUpdatedSucessfully") 
			{	
			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 Sucessfully 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 Sucessfully Inserted</b>";
			else
				window.location.href = "manage-febric.php";	
		     }

		if(strVal=="BrandSucessfullyinserted ") 
			{	
			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 Sucessfully 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 Sucessfully Inserted</b>";
			else
				window.location.href = "order-status-detail.php";	
		     }
			 
			 if (strVal=='SucessfullyLogin')
				{
				var secUrl = document.getElementById('secUrl').value;
				var cartTotalItem = document.getElementById('totalItemCart').value;
			
				if (cartTotalItem==0 || cartTotalItem==null || cartTotalItem=='')
					window.location.href = secUrl+"designyourtshirt.php";
				else
					window.location.href = secUrl+"cartuserinfo.php";
				}
			
			if (strVal=='YourImageisstoredsuccessfully')
				{
				var secUrl = document.getElementById('secUrl').value;
				window.location.href = secUrl+"login.php";
				}
			if (strVal=='photouploadlogin')
				{
				var session = document.getElementById('sessionId').value;
				window.location.href = "customer-photo.php?sessId="+session;
				}
				
			if (strVal=='SucessfullyLogout')
				{
				var secUrl = document.getElementById('secUrl').value;
				window.location.href = secUrl.replace('https' , 'http')+"index.php";
				}
				
			if (strVal=='OldOrderSucessfullyBuy')
				{
				var secUrl = document.getElementById('secUrl').value;
				window.location.href = secUrl+"display-cart.php";
				}
				
			if (strVal=='RecordUpdated')
				{
				var secUrl = document.getElementById('secUrl').value;
				window.location.href = secUrl+"display-cart.php";
				}
			
			if (strVal=='CouponUpdatedSucessfully')
				{
				window.location.href = "manage-coupon.php";
				}
			
			if(strVal=="CouponInsertedSucessfully") 
				{	
				document.getElementById(div_name_content).innerHTML= check;
				var conVal = confirm("Do you want to enter more coupon");
				if (conVal==false)
					window.location.href = "manage-coupon.php";	
				 }
				 
			if(strVal=="DiscountInsertedSucessfully") 
				{	
				document.getElementById(div_name_content).innerHTML= check;
				var conVal = confirm("Do you want to enter more discount detail");
				if (conVal==false)
					window.location.href = "discount-detail.php";
				 }
				 
			if (strVal=='DiscountUpdatedSucessfully')
				{
				window.location.href = "discount-detail.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;	
	}


