// JavaScript Document

/*---------------- Rajendra Vyas ---------------*/
/*---------------- 11-Sep-2009 -----------------*/

var stateName="-1";
var cityName="-1";
var storeTypeVal="RW";


function loadData(storeType)
{
	
	try
	{
		storeTypeVal=storeType;
		loadState();
		resetCity();
	}
	catch(e)
	{
		alert(e);
	}
}

/*    Added By mandal  */

function ajaxObject(url, callbackFunction) 
{  
	var that=this;        
	this.updating = false;  
	this.abort = function() 
	{    
		if (that.updating) 
		{      
			that.updating=false;      
			that.AJAX.abort();      
			that.AJAX=null;    
		}  
	}  
	this.update = function(passData,postMethod) 
	{    
		if (that.updating) 
		{ 
			return false; 
		}    
		that.AJAX = null;                              
		if (window.XMLHttpRequest) 
		{                    
			that.AJAX=new XMLHttpRequest();                  
		} 
		else 
		{                                        
			that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");    
		}                                                 
		if (that.AJAX==null) 
		{                                   
			return false;                                   
		}
		else 
		{      
			that.AJAX.onreadystatechange = function() 
			{          
				if (that.AJAX.readyState==4) 
				{                       
					that.updating=false;     
//					document.getElementById('stateNames').innerHTML=that.AJAX.responseXML;
					that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);                  
					that.AJAX=null;       
				}                                                           
			}                                                              
			that.updating = new Date();                                    
			if (/post/i.test(postMethod)) 
			{        
				var uri=urlCall+'?'+that.updating.getTime();   
				that.AJAX.open("POST", uri, true);        
				that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");        
				that.AJAX.setRequestHeader("Content-Length", passData.length);        
				that.AJAX.send(passData);      
			} 
			else 
			{        
				var uri=urlCall+'?'+passData+'&timestamp='+(that.updating.getTime());         
				that.AJAX.open("GET", uri, true);                                     
				that.AJAX.send(null);                                               
			}                    
	return true;                                                 
		}                                                                             
	}  
var urlCall = url;
this.callback = function(responseText, status, responseXML)
				{    
				// Do standard processing then pass execution to dedicated function    
				// to handle specific tasks    
					if(200 != status)
					{        
						alert("Problem");        
						return;    
					}      
				customHandler();
				}
}
function loadState()
{
	stateName="-1";
	cityName="-1";
	var xmlhttp="";
	var url="/rcom/StoreLocator/processData.jsp?cat=1&storeType="+storeTypeVal;
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
	  alert("Your browser does not support XMLHTTP!");
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
		  var divObj=document.getElementById("stateNames");
		  divObj.innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
//	var getStateList = new ajaxObject('stateNames', '/rcom/StoreLocator/processData.jsp');
//	getStateList.update('cat=1&storeType='+storeTypeVal,'POST');
//	var getCityList = new ajaxObject('cityNames', '/rcom/StoreLocator/processData.jsp');
//	getCityList.update('cat=2&stateName=-1');
	return true;
}

function getCity(obj)
{
	stateName=obj.value;
	//cityName="-1";
	var xmlhttp="";
	var url="/rcom/StoreLocator/processData.jsp?cat=2&stateName="+obj.value+"&storeType="+storeTypeVal;
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
	  alert("Your browser does not support XMLHTTP!");
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
		  var divObj=document.getElementById("cityNames");
		  divObj.innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
	//alert('cat=2&stateName='+obj.value+'&storeType='+storeTypeVal);
	//var getCityList = new ajaxObject('cityNames', '/rcom/StoreLocator/processData.jsp');
	//getCityList.update('cat=2&stateName='+obj.value+'&storeType='+storeTypeVal);

	return true;
}

function resetCity()
{
	if(document.getElementById('cityNames'))
	{
		document.getElementById('cityNames').innerHTML="<select name='rsselect' id='rsselect' class='dropstore'><option value='-1'>Select City</option></select>";
	}
	return true;
}


function setCity(obj)
{
	cityName=obj.value;
}


function getLocation()
{
	var Pincode="";
	try
	{	
		var strURL="";
		if(stateName=="-1")
		{
			alert("Please Select the State");
			return false;
		}
		else if(cityName=="-1")
		{
			alert("Please Select the City");
			return false;
		}
		if(storeTypeVal=='RW')
		{
			strURL="/rcom/StoreLocator/storelocator_relianceworld_list.jsp?firstmenu1="+stateName+"&menu2="+cityName;
		}
		else if(storeTypeVal=='RM')
		{
			strURL="/rcom/StoreLocator/storelocator_rms_list.jsp?firstmenu1="+stateName+"&menu2="+cityName+"&Pincode="+Pincode;
		}
		//alert(strURL);
		if(strURL!="")
		{
			document.location.href=strURL;
			return true;
		}
		else
			return false;
	}
	catch(e)
	{
		//alert(e);
	}
}




document.write('<table width="167" border="0" align="right" cellpadding="3" cellspacing="1" style="border:1px solid #E8F4FF">');
document.write('<form name="storeloc"><tr>');
document.write('<td height="55" valign="middle" bgcolor="#E8F4FF"><table width="94%" border="0" align="center" cellpadding="0" cellspacing="0">');
document.write('<tr>');
document.write('<td class="Grey16boldMainlink"><img src="/Rcom/personal/images/spacer.gif" alt="spacer" width="10" height="5" /></td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td class="Grey16boldMainlink">Store Locator</td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td height="15"><div align="right"><a href="#"></a></div></td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td height="15"><table width="100%" border="0" cellspacing="0" cellpadding="0">');
document.write('<tr>');
document.write('<td width="86%"><a href="http://www.relianceworld.in/locate_rw.asp" target="_blank">Reliance World Stores</td>');
document.write('</tr>');
document.write('<tr>');
document.write('<tr>');
document.write('<td height="15">&nbsp;</td>');
document.write('</tr>');
document.write('<td><b>Reliance Mobile Stores</b></td>');
document.write('</tr>');
document.write('</table></td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td height="5"></td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td><div id="stateNames"><select name="rworldselect" id="rworldselect" class="dropstore" >');
document.write('<option>Select Telecom Circle</option>');
document.write('</select></div></td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td><span class="Grey16boldMainlink"><img src="/Rcom/personal/images/spacer.gif" alt="spacer" width="10" height="10" /></span></td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td><div id="cityNames"><select name="cityName" id="cityName" class="dropstore">');
document.write('<option>Select City</option>');
document.write('</select></div></td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td><span class="Grey16boldMainlink"><img src="/Rcom/personal/images/spacer.gif" alt="spacer" width="10" height="7" /></span></td>');
document.write('</tr>');
document.write('<tr>');
//document.write('<td><a id="HrefChanged" href="#" class="ovalbutton2" onClick="changeHref();return hs.htmlExpand(this,{objectType:\'iframe\',outlineType:\'rounded-white\',width:760,height:520  },\'Store Locator\')"/><span>Locate</span></a></td>');
document.write('<td><a id="HrefChanged" href="#" class="ovalbutton2" onClick="getLocation();"/><span>Locate</span></a></td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td><span class="Grey16boldMainlink"><img src="/Rcom/personal/images/spacer.gif" alt="spacer" width="10" height="7" /></span></td>');
document.write('</tr>');
                        
document.write('</table><input type="hidden" name="flag1" id="flag1" value=""></td>');
document.write('</tr>');
document.write('</form></table>');
loadData("RM");
