// 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
			//alert(url);
			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)
	{
		//alert ("URL   " + url);
	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 + "\n&" + document.getElementById(form_name1).elements[i].name + "=" + document.getElementById(form_name1).elements[i].value;
					}
					i++;
				}
			url=url + value;
			//alert("GENEARETURL  "  +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;
			//alert ("dddd"+check);
			
			var check1 = check.split("~~~~~~~~~~");
		/*	alert ("1"+check1[0]);
			alert ("2"+check1[1]);
			alert ("3"+check1[2]);*/
			
			var strVal = rmWhiteSpace(check)
			
			
			if (check1[0]=="IMAGEGENERATESUCESSFULLY")
				{
				document.getElementById('divImageResize').style.display = "none";
				document.getElementById('divImageDisplay').style.display = "block";
				document.getElementById('divImageDisplay').innerHTML = "<img src=uploadedfiles/thumbs/"+check1[1]+" border=1 />";
				}
			
			if (check1[0]=="IMAGEGENERATESUCESSFULLYADMIN")
				document.getElementById('divImageResize').style.display = "none";
				
	  		 if(strVal=="<b>SucessfullyverifyingyourAddress</b>")
			{
			 window.location.href = "https://www.stateofyourart.com/order_confirm.php";
			//  window.location.href = "order_confirm.php";
			}
			if(strVal=="<b>SucessfullyupdatingyourRecords</b>")
			{
			  window.location.href = "https://www.stateofyourart.com/order_confirm.php";
			// window.location.href = "order_confirm.php";
			}
			
		
			if(check=="Sucessfully Login&nbsp;&nbsp;&nbsp;")
				{
				 window.location.href = "https://www.stateofyourart.com/checkout_step1.php";
				//  window.location.href = "checkout_step1.php";
				}
			
			
/*			if(check1[0]=="Approved")
			{
			  window.location.href = "cart_thanks.php?sessId="+check1[1];
			}*/
			
			
			if(check=="Handling Type Inserted Sucessfully") {
				var conVal = confirm("Do you want to enter more Size");
				if (conVal==true)
					document.getElementById('divResult').innerHTML = "<b>Handling Type Inserted Sucessfully</b>";
				else
			  		window.location.href = "handling-detail.php";	
		     }
			
			if(check=="Handling Type Updated Sucessfully") {
			  		window.location.href = "handling-detail.php";	
		     }	
			
			if(check1[1]=="SIZE_SUCESSFULLY_INSERTED") {
				var conVal = confirm("Do you want to enter more Size");
				if (conVal==true)
					document.getElementById('divMessage').innerHTML = "<b>Record Sucessfully Inserted</b>";
				else
			  		window.location.href = "price.php";	
		     }
			 
			 if(check1[1]=="SIZE_SUCESSFULLY_UPDATED")
			  		window.location.href = "price.php";	
			
			if(check1[1]=="CATEGORY_SUCESSFULLY_INSERTED") {
				var conVal = confirm("Do you want to enter more category");
				if (conVal==true)
					document.getElementById('divMessage').innerHTML = "<b>Record Sucessfully Inserted</b>";
				else
			  		window.location.href = "category.php";	
		     }
			 if(check1[1]=="CATEGORY_SUCESSFULLY_UPDATED") {
			  window.location.href = "category.php?msg=Category Sucessfully Updated";	
		     }
			
			if(check1[0]=='UPDATE_DATA')
				{
				/*document.getElementById('addCategory').value='';
				document.getElementById('status').value='';
				document.getElementById('hidEditId').value='';
				alert("DIV NAME  " + check1[1]);
				var divName = check1[1];
				document.getElementById(divName).innerHTML= check1[2]; */
				
				window.location.href = "category.php";
			}
		
		  if(check1[0]=='UPDATE_DATA_DESIGN') {
			  window.location.href = "designer.php";	
		   }
		   
		  
			
			if (check1[1]=="PRODUCT_SIZE_ASSIGN_SUCESS")
				{
				window.setTimeout("window.close()", 1);
				//opener.location.reload(true);
				opener.document.getElementById('productDivWindow').innerHTML = check1[2];
				}
			
			var check2=check.split("~~~");
			if(check2[1]=='Record Added')
			{
			 document.getElementById('editSizeId').value='';
			 document.getElementById('editId').value='';	
			 document.getElementById('size').value='';	
			 document.getElementById('printingPrice').value='';	
			 document.getElementById('price').value='';	
			 document.getElementById('shippingWeight').value='';	
			 document.getElementById('galleryWeight').value='';	
			 document.getElementById('status').value='';	
			 document.getElementById('size').focus();	
			}
			
			if(check2[1]=='Record Edit')
			{
			 document.getElementById('editSizeId').value='';
			 document.getElementById('editId').value='';	
			 document.getElementById('size').value='';	
			 document.getElementById('printingPrice').value='';	
			 document.getElementById('price').value='';
			 document.getElementById('shippingWeight').value='';	
			 document.getElementById('galleryWeight').value='';	
			 document.getElementById('status').value='';	
			}
			var check3=check.split("~~~~");
		
			if(check3[1]=='REMOVE_CART')
			{
				window.location.reload(true);
			 document.getElementById('DivTotal').innerHTML=check3[2];	
			 document.getElementById('cartDiv').innerHTML="<span class='cartItem'>"+check3[0]+"</span>items";
			}
			
			if (check=='Sucessfully Login')
				{
				  var items=document.getElementById('totalCartData').value;
				  if(items==0)
				  {
				   window.location.href = "https://www.stateofyourart.com/myaccount.php";
				//  window.location.href = "myaccount.php";
				  }
				  else
				  {
				  window.location.href = "https://www.stateofyourart.com/checkout_step1.php";
				  // window.location.href = "checkout_step1.php";
				  }
				}
				
			if (check=='Sucessfully Logout')
				{
				window.location.href = "http://www.stateofyourart.com/index.php";
				// window.location.href = "index.php";
				}
				
			
			if(check1[0]!='UPDATE_DATA' && check3[1]!='REMOVE_CART')
				{
									
				document.getElementById(div_name_content).innerHTML= check; 
				}
			var check4 = check.split("~~~~~");
			if (check4[1]=='CARTADD')
				{
				var prodId=check4[2];
				var gallary=check4[3];
				window.location.href = "cart.php?imageId="+prodId;
				}
				var check5 = check.split("~~~~~");
			//alert(check4[1]);
			if (check5[1]=='CARTUPDATE')
				{
				var prodId=check5[2];
				window.location.href = "cart.php?imageId="+prodId;
				}	
			var check6 = check.split("~~~~~~");
				if (check6[1]=='CARTADD')
				{
				window.location.href = "cart.php";
				}
				var check7 = check.split("~~~~~~");
			//alert(check4[1]);
			if (check7[1]=='CARTUPDATE')
				{
				window.location.href = "cart.php";
				}
			var check8 = check.split("~~~");
				if (check8[1]=='CURRADD')
				{
				var defaultcurr=check8[2];
				window.location.href = "order_options.php?defaultcurr="+defaultcurr;
				}
			var check9 = check.split("~~~");
			if(check9[1]=='COUPONDISCOUNT')
			{
				document.getElementById('disDiv').innerHTML="Discount"+" "+"-"+check9[2];
				document.getElementById('netAmountDiv').innerHTML="Net Amount"+" "+check9[3];
				document.getElementById('hiddenRemainder').value=check9[5];
				//document.getElementById('hiddenDiscount').value=check9[4];
				if(check9[4]==0)
				document.getElementById('couponDiv').innerHTML="Invalid coupon code";
				if(check9[4]==1)
				document.getElementById('couponDiv').innerHTML="";
			}
		
		} 
	}	
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;
	}
	
