// JavaScript Document
/****************************************************************************************************

Module Name		: Indopia Home Page ( News)
Args			: None
Module Type		: Procedure
Created By		: Sushma Akarnia
Created On		: Feb 22, 2007
Modified By		: 
Modified On		: 
Remarks			:
Description		: 

*****************************************************************************************************/
function XMLHTTPObject()
{
	var xmlhttp; 

	if (window.ActiveXObject) 
	{
		// Instantiate the latest Microsoft ActiveX Objects
		if (_XML_ActiveX)
		{
			xmlhttp = new ActiveXObject(_XML_ActiveX);
		
		}
		else
		{ 
			// loops through the various versions of XMLHTTP to ensure we're using the latest
			var versions = ["MSXML2.XMLHTTP", "Microsoft.XMLHTTP", "Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0"];			

			for (var i = 0; i < versions.length ; i++) 
			{ 
				try
				{
					// Try and create the ActiveXObject for Internet Explorer, if it doesn't work, try again.
					xmlhttp = new ActiveXObject(versions[i]); 
						
					if (xmlhttp) 
					{ 
						var _XML_ActiveX = versions[i];
						break;
					}
				}
				catch (e)
				{
					// TRAP
				};
			}
			;
		}			
	}// Well if there is no ActiveXObject available it must be firefox, opera, or something else

	if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
	{
		try 
		{ 
			xmlhttp = new XMLHttpRequest(); 
		} 
		catch (e) 
		{
			xmlhttp = false; 
		}
	}
	
	return xmlhttp;
}

function processRequest(contentId,httpRequest,refreshContentOnFunction,parameterForRefresh)
{ 
	
	if (httpRequest.readyState == 4) 
	{ 
		if(httpRequest.status == 200)
		{ 
			results = httpRequest.responseText; // http.responseXML; which will lead to an XML based response, if we were to have some XML output from a server file
			var para = document.getElementById(contentId); //or whatever ID you gave your element. 			
			para.innerHTML = results; 		
			if (refreshContentOnFunction != "null")
			{		
				refreshContent(refreshContentOnFunction,parameterForRefresh);	
							
			}
			
		}
		else 
		{ 
			var results = "Sorry, there was an error finding the server-side file. Please contact support."; 
			var para = document.getElementById(contentId); 
			para.innerHTML = results; 
		}
		
	}	

	
}


function processRequestForStateCity(contentId,httpRequest)
{ 
	
	if (httpRequest.readyState == 4) 
	{ 
		if(httpRequest.status == 200)
		{ 
			results = httpRequest.responseText; // http.responseXML; which will lead to an XML based response, if we were to have some XML output from a server file
			var para = window.opener.document.getElementById(contentId); //or whatever ID you gave your element. 			
			para.innerHTML = results; 	
			//opener.location.reload();
			self.close();		
			
		}
		else 
		{ 
			var results = "Sorry, there was an error finding the server-side file. Please contact support."; 
			var para = window.opener.document.getElementById(contentId); 
			para.innerHTML = results; 
		}
		
	}	

	
}

function setCustomizeStateCity()
{
	var varContentUrl =  "resources/classes/home/homeprocessajax.php?processfunction=populateStateCity";					
	dataitem = window.open(varContentUrl,"dataitem","dependent=yes,height=219,width=366,left=300,top=300");	
}


function populateCity()
{
	var httpRequest=null;
	//alert("populateCity");
	var refreshContent = "null";
	var result = true;
	
	// Javascript validation block (if any)
	
	// End
	
	// If there is no javascript error then go thru the processing/request response cycle	
	
	objState=document.getElementById('state');
	objCity=document.getElementById('city');
	objCity.options.length = 1;
	stateValue = objState.value;		
	
	if (stateValue != "InValid")
	{
		httpRequest = XMLHTTPObject();	
		
		var varContentUrl =  "homeprocessajax.php?processfunction=populateCity&stateId="+encodeURIComponent(stateValue);	
		//var varContentUrl =  "homeprocessajax.php?processfunction=populateCity&stateId="+stateValue;	

		//alert(varContentUrl);

		var contentId = "CitySelectBox";				
		
		var para = document.getElementById(contentId);
		para.innerHTML = "<b style='color:red;'>Loading Cities<img src='../../images/loading.gif'/></b>"; 
		
		httpRequest.open("GET", varContentUrl, true); 
		httpRequest.onreadystatechange = function () {processRequest(contentId,httpRequest,refreshContent,""); } ;
		httpRequest.setRequestHeader('Cache-Control', 'no-cache');
		httpRequest.setRequestHeader('Cache-Control', 'no-store');
		httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');		
		httpRequest.send(null);	
	}	
}

/*
function SetStateCityCookies()
{
	var httpRequest=null;

	var refreshContent = "null";
	var result = true;
	
	// Javascript validation block (if any)
	{
		;	
	}
	// End
	
	// If there is no javascript error then go thru the processing/request response cycle	
	
	objState=document.getElementById('state');
	stateValue = objState.value;	
	objCity=document.getElementById('city');
	cityValue = objCity.value;		
	
	if (stateValue != "InValid")
	{
		httpRequest = XMLHTTPObject();	
		
		var varContentUrl =  "homeprocessajax.php?processfunction=setStateCityCookie&stateId="+stateValue+"&cityId="+cityValue;				
			
		httpRequest.open("GET", varContentUrl, true); 
		httpRequest.onreadystatechange = function () {processRequestCustom(httpRequest); } ;
		httpRequest.setRequestHeader('Cache-Control', 'no-cache');
		httpRequest.setRequestHeader('Cache-Control', 'no-store');
		httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');		
		httpRequest.send(null);	
	}	
}

*/

function setCookie(name, value, expires, path, domain, secure) 
{ 
	document.cookie= name + "=" + escape(value) + 
	((expires)? "; expires=" + expires.toGMTString() : "") + 
	((path)? "; path=" + path : "") + 
	((domain)? "; domain=" + domain : "") + 
	((secure)? "; secure" : ""); 
} 

function checkStateCity()
{	
	stateCheck = false;
	cityCheck = false;
	//alert(document.citypriorityselectform.city);
	
	if (document.citypriorityselectform.state.value == "InValid")
	{
		alert("Please select the state");
		return false;
	}
	else
	{
		stateCheck = true;
	}
	
	//alert(document.getElementByName('city'));
	if (stateCheck == true)
	{
		if (document.citypriorityselectform.city.value == "InValid" )
		{
			alert("Please select the city");
			return false;
		}
	}	
	
	
	return true;
}

function setSelectedStateCityValue(){
	//alert(getCookie('set_state'));
	//alert("hello");
	objState=document.getElementById('state');
	objCity=document.getElementById('city');
	
	var date = new Date();
	date.setTime(date.getTime()+(1*24*60*60*1000));
	//var expires = "; expires="+date.toGMTString();
	
	var path="/";
	//var path="/test/indopia/indopia/";
	
	setCookie('set_state',objState.value,date,path);
	setCookie('set_city',objCity.value,date,path);
	
	objLabelState = window.opener.document.getElementById("TabHeading_C");
	objLabelCity = window.opener.document.getElementById("TabHeading_D");
	
	objInput1 = window.opener.document.getElementById("categoryId_C");
	objInput2 = window.opener.document.getElementById("categoryId_D");
	objInputStateId = window.opener.document.getElementById("stateid");
	
	objInput1.value = objState.value; //will be replace by actual Id that is require for news category specification*/
	objInput2.value = objCity.value; //will be replace by actual Id	that is require for news category specification */
	
	objSelectedTab = window.opener.document.getElementById("selectedTabTop");
	
	categoryTab = objSelectedTab.value;
	
	var strLength = categoryTab.length;
	
	var tabIdentityChar = categoryTab.substring(strLength-1,strLength);	
	objInputStateId.value=objState.value;
	if (objSelectedTab.value == "categoryId_C" )
	{
		refreshNewsContent(objSelectedTab.value,'centernewsdisplaydivtop','top',tabIdentityChar,objState.value);
		objLabelState.innerHTML = objState.value;
	    objLabelCity.innerHTML = objCity.value;
		
	}
	else if(objSelectedTab.value == "categoryId_D" )
	{

		refreshNewsContent(objSelectedTab.value,'centernewsdisplaydivtop','top',tabIdentityChar,objCity.value);
		objLabelState.innerHTML = objState.value;
	    objLabelCity.innerHTML = objCity.value;	
	
	}
	else
	{
		objLabelState.innerHTML = objState.value;
	    objLabelCity.innerHTML = objCity.value;
		self.close();
	}
	//opener.location.reload();
	//self.close();
	
}

function refreshNewsContent(categoryId,divId,frame,tabIdentityChar,head) 
{

//alert("value"+value);
//alert(document.getElementById(id).value);
//if(category==null)
    //category=id;

 //alert("category="+category+"value="+value);
	var httpRequest=null;

	var refreshContent = "null";
	var result = true;
	var fields = new Array();
	
	// If there is no javascript error then go thru the processing/request response cycle	
	
	//objInputTabId = window.opener.document.getElementById('selectedTabId'); 
	//objInputTabId.value = categoryId;
	
	/*
	objLink = window.opener.document.getElementById('stateCityLink');	
	
	if (categoryId == "categoryId_C" || categoryId == "categoryId_D")
	{
		
		objLink.innerHTML = "Customize State/City";
		
	}
	else
	{
		objLink.innerHTML = " ";
		
	}
	
	*/
	
	objInputCategory = window.opener.document.getElementById(categoryId);
	
	value = objInputCategory.value;
//alert(value);
	httpRequest = XMLHTTPObject();	
	
	var varContentUrl = "../../../show_news.php?id="+value+"&frame="+frame+"&identityId="+tabIdentityChar+"&head="+head;				
	var contentId = divId;				
//	alert(varContentUrl);
	var para = window.opener.document.getElementById(contentId);
	
	para.innerHTML = "<span class=LabelHeading align=center>&nbsp;&nbsp;&nbsp;&nbsp;</span>"; 

	httpRequest.open("GET", varContentUrl, true); 
	httpRequest.onreadystatechange = function () {processRequestForStateCity(contentId,httpRequest,refreshContent,""); } ;
	httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	httpRequest.send(null);	

}

/*
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

*/
function changeLogo()
{
	try
	{
		objLabel=document.getElementById("stateid");
		//alert("No is "+objLabel.value);
		var httpRequest=null;
		var refreshContent = "null";
		var result = true;
		httpRequest = XMLHTTPObject();	
		//alert(objLabel.value);
		value=objLabel.value;
		var objCategoryId=document.getElementById("selectedTabTop");
		var CategoryId=objCategoryId.value;
		var varContentUrl = "changelogo.php?value="+value+"&categoryid="+CategoryId;				
		//alert(varContentUrl);
		var para = document.getElementById("ads");
		para.innerHTML = ""; 
		httpRequest.open("GET", varContentUrl, true); 
		httpRequest.onreadystatechange = function () {processRequest("ads",httpRequest,refreshContent,""); } ;
		httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		httpRequest.send(null);	
	}
	catch(e)
	{
	}

}
function changeLogoDetail()
{
	try
	{
		objLabel=document.getElementById("stateValue");
		var httpRequest=null;
		var refreshContent = "null";
		var result = true;
		httpRequest = XMLHTTPObject();	
		var value=objLabel.value;
		var varContentUrl = "../changelogo.php?value="+value+"&categoryid=categoryId_C";				
		var para = document.getElementById("ads");
		para.innerHTML = ""; 
		httpRequest.open("GET", varContentUrl, true); 
		httpRequest.onreadystatechange = function () {processRequest("ads",httpRequest,refreshContent,""); } ;
		httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		httpRequest.send(null);
	}
	catch(e)
	{
	}
}