/*
*  File           : global_ajax.js
*  Author(s)      : Naveen Kumar
*  Creation Date  : Dec 17, 2008
*  Functionality  : This function will  work as a class.  
*    		        we can get the XMLHttpRequest object (not variable). This object will work like java object.
*  Dependencies   :
*  Copyright      : P&G
*  Modifications  : <Author> <Date> <Description of Modification>
*/

var Ajax = function(){
            var _this = this;
            this.call = function(url, callback){
	           _this.request = null;
	           try {
	           	_this.request = new XMLHttpRequest();
	           } catch(e) {
	           try {
	               _this.request = new ActiveXObject("Microsoft.XMLHTTP");
	
	           } catch(e) {
	               return;  
	           }
	       }
	       this.request.onreadystatechange = function(){ callback(_this.request); };
	       this.request.open("GET",url,true);
	       this.request.send(null);
	}
}

/*************************************************************************************************************************************************/
											/* DOG PRODUCT METHODS STARTED*/
/*************************************************************************************************************************************************/

/**
 *	Function : filterIAMSProductForDog()
 *  Auther   : Naveen Kumar
 *	Purpose  : This function is used to filter the IAMS products for Dog.
*/
var detailFlag = false;
function filterIAMSProductForDog(dropdownValue,calledFrom){
	var lifeStage	=(document.getElementById("dog_life")).value;
	var dogSize		=(document.getElementById("dog_size")).value;
	var dogNeed		=(document.getElementById("dog_need")).value;
	var productId		="0";
	
	(document.getElementById("dog_life")).disabled=true;
	(document.getElementById("dog_size")).disabled=true;
	(document.getElementById("dog_need")).disabled=true;
	
		
	if (calledFrom =="body"){
		productId=(document.getElementById("productId")).value;
		
	}else if (lifeStage=='0' || dogSize=='0' || dogNeed=='0'){
		productId="1056"; //Default IAMS Dog Product to be selected - IamsŪ ProActive Health TM MiniChunks
	}
	
	if (calledFrom =="dog_life"){
		lifeStage=dropdownValue;
			
	}
	if (calledFrom =="dog_size"){
	    lifeStage=(document.getElementById("dog_life")).value;
	    if ((document.getElementById("dog_size")).value=='0'){
	    	dogNeed='0';	
	    }
		dogSize=dropdownValue;		
			
	}
	if (calledFrom =="dog_need"){
	
	    lifeStage=(document.getElementById("dog_life")).value;
	    dogSize=(document.getElementById("dog_size")).value;
		dogNeed=dropdownValue;
	}
	var url = "ComparisonDogProduct.do";
	url = url + "?method=filterIAMSProducts&lifeStage=" + lifeStage+"&dogSize="+dogSize+"&dogNeed="+dogNeed+"&productId="+productId;
	//alert(url);
	//document.location = url;
	var xmlHttpIAMSProduct = new Ajax();
    xmlHttpIAMSProduct.call(url,getIAMSProduct);
}

/**
 *	Function : getIAMSProduct()
 *  Auther   : Naveen Kumar
 *	Purpose  : This function is used to display the IAMS Products in IAMS Products Dropdown through Inner HTML for Dog.
*/

function getIAMSProduct(transport) {
	//document.getElementById("ImportHint1").innerHTML = "<img src=\"common/images/contactloading.gif\"><font size=\"2\">Please wait..";
	if (transport.readyState == 4 || transport.readyState == "complete") {
	 	var filterIAMSProduct = transport.responseText;
		(document.getElementById("IAMSFilterProduct")).innerHTML = filterIAMSProduct;
		(document.getElementById("iamsProduct")).disabled=true;
		callGlobalMethod('dog');
	}
} 

/**
 *	Function : callGlobalMethod()
 *  Auther   : Naveen Kumar
 *	Purpose  : This function is used to call other the Other Products method(s).
 */

function callGlobalMethod(calledFrom){
	if (calledFrom=='dog'){
	(document.getElementById("dog_life")).disabled=true;
	(document.getElementById("dog_size")).disabled=true;
	(document.getElementById("dog_need")).disabled=true;
		filterFirstOtherProducts();
		filterSecondOtherProducts();
	}else if (calledFrom=='cat'){
	(document.getElementById("cat_life")).disabled=true;
	(document.getElementById("cat_size")).disabled=true;
	(document.getElementById("cat_need")).disabled=true;
		filterFirstOtherCatProducts();
		filterSecondOtherCatProducts();
	}
}

/**
 *	Function : filterFirstOtherProducts()
 *  Auther   : Naveen Kumar
 *	Purpose  : This function is used to filter the Other Brand Products for Dog in the First Other Product Dropdown.
 */
function filterFirstOtherProducts(){
	var url;
	iamsProductId=(document.getElementById("iamsProduct")).value;
	url = "ComparisonDogProduct.do";
	url = url + "?method=filterFirstOtherProducts&iamsProductId=" + iamsProductId;
	var xmlHttpOtherProduct = new Ajax();
    xmlHttpOtherProduct.call(url,getFirstOtherProduct);
 }

/**
 *	Function : getFirstOtherProduct()
 *  Auther   : Naveen Kumar
 *	Purpose  : This function is used to display the Other Brand Products Dropdown through Inner HTML for Dog.
*/

function getFirstOtherProduct(transport) {
	//document.getElementById("ImportHint1").innerHTML = "<img src=\"common/images/contactloading.gif\"><font size=\"2\">Please wait..";
	if (transport.readyState == 4 || transport.readyState == "complete") {
		var filterFirstOtherProduct = transport.responseText;
		(document.getElementById("otherFilterProductFirst")).innerHTML = filterFirstOtherProduct;
		
		if (detailFlag==true){
			detailFlag = false;
				(document.getElementById("firstOtherProduct")).disabled=true;	
				(document.getElementById("secondOtherProduct")).disabled=true;	
			dogProductDetail();
		}else{
			detailFlag = true;
		}
	}
} 

/**
 *	Function : filterSecondOtherProducts()
 *  Auther   : Naveen Kumar
 *	Purpose  : This function is used to filter the Other Brand Products for Dog in the Second Other Product Dropdown.
 */
function filterSecondOtherProducts(){
	iamsProductId=(document.getElementById("iamsProduct")).value;
	var url = "ComparisonDogProduct.do";
	url = url + "?method=filterSecondOtherProducts&iamsProductId=" + iamsProductId;
	//alert(url);
	//document.location = url;
	var xmlHttpOtherProduct = new Ajax();
    xmlHttpOtherProduct.call(url,getSecondOtherProduct);
}

/**
 *	Function : getSecondOtherProduct()
 *  Auther   : Naveen Kumar
 *	Purpose  : This function is used to display the Other Brand Products Dropdown through Inner HTML for Dog.
*/

function getSecondOtherProduct(transport) {
	//document.getElementById("ImportHint1").innerHTML = "<img src=\"common/images/contactloading.gif\"><font size=\"2\">Please wait..";
	if (transport.readyState == 4 || transport.readyState == "complete") {
		var filterSecondOtherProduct = transport.responseText;
		(document.getElementById("otherFilterProductSecond")).innerHTML = filterSecondOtherProduct;
		
		if (detailFlag==true){
			detailFlag = false;
			(document.getElementById("firstOtherProduct")).disabled=true;	
			(document.getElementById("secondOtherProduct")).disabled=true;	
			dogProductDetail();
		}else{
			detailFlag = true;
		}
	}
} 

/**
 *	Function : dogProductDetail()
 *  Auther   : Naveen Kumar
 *	Purpose  : This function is used to get the details of all product in the Compare Results page section for Dog.
 */
function dogProductDetail(){
	(document.getElementById("dog_life")).disabled=true;
	(document.getElementById("dog_size")).disabled=true;
	(document.getElementById("dog_need")).disabled=true;
	(document.getElementById("iamsProduct")).disabled=true;	
	(document.getElementById("firstOtherProduct")).disabled=true;	
	(document.getElementById("secondOtherProduct")).disabled=true;	
	var iamsProductId="0";
	var firstOtherProductId="0";
	var secondOtherProductId="0";
	
	if((document.getElementById("iamsProduct"))){
	 iamsProductId=(document.getElementById("iamsProduct")).value;
	 }
	 if(firstOtherProductId=(document.getElementById("firstOtherProduct"))){
	 	firstOtherProductId=(document.getElementById("firstOtherProduct")).value;
	 }
	 if(secondOtherProductId=(document.getElementById("secondOtherProduct"))){
	 	secondOtherProductId=(document.getElementById("secondOtherProduct")).value;
	 }
	 //alert('Dog Product Details iamsProduct : '+iamsProductId + ' firstOtherProduct : ' + firstOtherProductId + '   secondOtherProduct: ' + secondOtherProductId);
	var url = "ComparisonDogProduct.do";
	url = url + "?method=dogProductDetail&iamsProductId=" + iamsProductId + "&firstOtherProductId=" + firstOtherProductId + "&secondOtherProductId=" + secondOtherProductId;
	//alert(url);
	//document.location = url;
	var xmlHttpDogProductDetail = new Ajax();
    xmlHttpDogProductDetail.call(url,getDogProductDetail);
}

/**
 *	Function : getDogProductDetail()
 *  Auther   : Naveen Kumar
 *	Purpose  : This function is used to display the details of all product in the Compare Results page section for Dog.
*/

function getDogProductDetail(transport) {
	//document.getElementById("ImportHint1").innerHTML = "<img src=\"common/images/contactloading.gif\"><font size=\"2\">Please wait..";
	if (transport.readyState == 4 || transport.readyState == "complete") {
		var dogProductDetail = transport.responseText;
		
		(document.getElementById("productDetail")).innerHTML = dogProductDetail;
	
	
	(document.getElementById("dog_life")).disabled=false;
	if((document.getElementById("dog_life")).value!='0'){
	
	(document.getElementById("dog_size")).disabled=false;
	}else{
	
	(document.getElementById("dog_size")).value='0';
	(document.getElementById("dog_size")).disabled=true;
	}
	if((document.getElementById("dog_size")).value!='0'){
	(document.getElementById("dog_need")).disabled=false;
	}else{
	(document.getElementById("dog_need")).value='0';
	(document.getElementById("dog_need")).disabled=true;
	
	}
	(document.getElementById("iamsProduct")).disabled=false;	
	(document.getElementById("firstOtherProduct")).disabled=false;	
	(document.getElementById("secondOtherProduct")).disabled=false;	
		
		
	}
} 
/*************************************************************************************************************************************************/
											/* DOG PRODUCT METHODS COMPLETED*/
/*************************************************************************************************************************************************/



/*************************************************************************************************************************************************/
											/* CAT PRODUCT METHODS STARTED*/
/*************************************************************************************************************************************************/


/**
 *	Function : filterIAMSProductForCat()
 *  Auther   : Amit Kumar Kar
 *	Purpose  : This function is used to filter the IAMS product.
 */
function filterIAMSProductForCat(dropdownValue,calledFrom){
	var lifeStage	=(document.getElementById("cat_life")).value;
	var catSize		=(document.getElementById("cat_size")).value;
	var catNeed		=(document.getElementById("cat_need")).value;
	var productId   ="0";
	(document.getElementById("cat_life")).disabled=true;
	(document.getElementById("cat_size")).disabled=true;
	(document.getElementById("cat_need")).disabled=true;
	
	if (calledFrom =="body"){
		productId=(document.getElementById("productId")).value;
		
	}else if (lifeStage=='0' || catSize=='0' || catNeed=='0'){
		productId="2003"; //Default IAMS Cat Product to be selected - IamsŪ ProActive Healt Original with Chicken
	}
	if (calledFrom =="cat_life"){
		lifeStage=dropdownValue;
			
	}
	
	if (calledFrom =="cat_size"){
	    lifeStage=(document.getElementById("cat_life")).value;
	    if ((document.getElementById("cat_size")).value=='0'){
	    	catNeed='0';	
	    }
		catSize=dropdownValue;		
			
	}
	
	if (calledFrom =="cat_need"){
	
	    lifeStage=(document.getElementById("cat_life")).value;
	    catSize=(document.getElementById("cat_size")).value;
		catNeed=dropdownValue;
	}
	
	var url = "ComparisonCatProduct.do";
	url = url + "?method=filterIAMSProducts&lifeStage=" + lifeStage+"&catSize="+catSize+"&catNeed="+catNeed+"&productId="+productId;
	//alert(url);
	//document.location = url;
	
	var xmlHttpIAMSProduct = new Ajax();
    xmlHttpIAMSProduct.call(url,getIAMSCatProduct);
}
 
/**
 *	Function : getIAMSCatProduct()
 *  Auther   : Amit Kumar Kar
 *	Purpose  : This function is used to display the IAMS Products in IAMS Products Dropdown through Inner HTML for Cat.
*/

function getIAMSCatProduct(transport) {
	//document.getElementById("ImportHint1").innerHTML = "<img src=\"common/images/contactloading.gif\"><font size=\"2\">Please wait..";
	if (transport.readyState == 4 || transport.readyState == "complete") {
	 	var filterIAMSProduct = transport.responseText;
		(document.getElementById("IAMSFilterProduct")).innerHTML = filterIAMSProduct;
		callGlobalMethod('cat');
	}
}  
 
/**
 *	Function : filterFirstOtherCatProducts()
 *  Auther   : Amit Kumar Kar
 *	Purpose  : This function is used to filter the others product.
 */
 
function filterFirstOtherCatProducts(iamsProductId,calledFrom){
	iamsProductId=(document.getElementById("iamsProduct")).value;
	
	var url = "ComparisonCatProduct.do";
	url = url + "?method=filterFirstOtherProducts&iamsProductId=" + iamsProductId;
	//alert(url);
	//document.location = url;
	
	var xmlHttpOtherProduct = new Ajax();
    xmlHttpOtherProduct.call(url,getFirstOtherCatProduct);
}

/**
 *	Function : getFirstOtherCatProduct()
 *  Auther   : Amit Kumar Kar
 *	Purpose  : This function is used to display the Other Brand Products Dropdown through Inner HTML for Cat.
*/

function getFirstOtherCatProduct(transport) {
	//document.getElementById("ImportHint1").innerHTML = "<img src=\"common/images/contactloading.gif\"><font size=\"2\">Please wait..";
	if (transport.readyState == 4 || transport.readyState == "complete") {
		var filterFirstOtherCatProduct = transport.responseText;
		(document.getElementById("otherFilterProductFirst")).innerHTML = filterFirstOtherCatProduct;
		if (detailFlag==true){
			(document.getElementById("firstOtherProduct")).disabled=true;	
			(document.getElementById("secondOtherProduct")).disabled=true;	
			detailFlag = false;
			catProductDetail();
		}else{
			detailFlag = true;
		}
	}
}
/**
 *	Function : filterSecondOtherCatProducts()
 *  Auther   : Amit Kumar Kar
 *	Purpose  : This function is used to filter the Other Brand Products for Cat in the Second Other Product Dropdown.
 */ 
function filterSecondOtherCatProducts(iamsProductId,calledFrom){
	iamsProductId=(document.getElementById("iamsProduct")).value;
	var url = "ComparisonCatProduct.do";
	url = url + "?method=filterSecondOtherProducts&iamsProductId=" + iamsProductId;
	//alert(url);
	//document.location = url;
	
	var xmlHttpOtherProduct = new Ajax();
    xmlHttpOtherProduct.call(url,getSecondOtherCatProduct);
}
/**
 *	Function : getSecondOtherCatProduct()
 *  Auther   : Amit Kumar Kar
 *	Purpose  : This function is used to display the Other Brand Products Dropdown through Inner HTML for Cat.
*/
function getSecondOtherCatProduct(transport) {
	//document.getElementById("ImportHint1").innerHTML = "<img src=\"common/images/contactloading.gif\"><font size=\"2\">Please wait..";
	if (transport.readyState == 4 || transport.readyState == "complete") {
		var filterSecondOtherProduct = transport.responseText;
		
		(document.getElementById("otherFilterProductSecond")).innerHTML = filterSecondOtherProduct;
		if (detailFlag==true){
			(document.getElementById("firstOtherProduct")).disabled=true;	
			(document.getElementById("secondOtherProduct")).disabled=true;	
			detailFlag = false;
			catProductDetail();
		}else{
			detailFlag = true;
		}
	}
} 
/**
 *	Function : catProductDetail()
 *  Auther   : Amit Kumar Kar
 *	Purpose  : This function is used to get the details of all product in the Compare Results page section for Cat.
 */
function catProductDetail(){
	(document.getElementById("cat_life")).disabled=true;
	(document.getElementById("cat_size")).disabled=true;
	(document.getElementById("cat_need")).disabled=true;
	(document.getElementById("iamsProduct")).disabled=true;	
	(document.getElementById("firstOtherProduct")).disabled=true;	
	(document.getElementById("secondOtherProduct")).disabled=true;	
	var iamsProductId="0";
	var firstOtherProductId="0";
	var secondOtherProductId="0";
	
	
	if((document.getElementById("iamsProduct"))){
	 iamsProductId=(document.getElementById("iamsProduct")).value;
	 }
	 if(firstOtherProductId=(document.getElementById("firstOtherProduct"))){
	 	firstOtherProductId=(document.getElementById("firstOtherProduct")).value;
	 }
	 if(secondOtherProductId=(document.getElementById("secondOtherProduct"))){
	 	secondOtherProductId=(document.getElementById("secondOtherProduct")).value;
	 }
	//alert('CAT Product Details iamsProduct : '+iamsProductId + ' firstOtherProduct : ' + firstOtherProductId + '   secondOtherProduct: ' + secondOtherProductId);
	var url = "ComparisonCatProduct.do";
	url = url + "?method=catProductDetail&iamsProductId=" + iamsProductId + "&firstOtherProductId=" + firstOtherProductId + "&secondOtherProductId=" + secondOtherProductId;
	//alert(url);
	//document.location = url;
	var xmlHttpCatProductDetail = new Ajax();
    xmlHttpCatProductDetail.call(url,getCatProductDetail);
}
/**
 *	Function : getCatProductDetail()
 *  Auther   : Amit Kumar Kar
 *	Purpose  : This function is used to display the details of all product in the Compare Results page section for Cat.
*/
function getCatProductDetail(transport) {
	//document.getElementById("ImportHint1").innerHTML = "<img src=\"common/images/contactloading.gif\"><font size=\"2\">Please wait..";
	if (transport.readyState == 4 || transport.readyState == "complete") {
		var catProductDetail = transport.responseText;
		(document.getElementById("productDetail")).innerHTML = catProductDetail;
		
		
	(document.getElementById("cat_life")).disabled=false;
	if((document.getElementById("cat_life")).value!='0'){
	
	(document.getElementById("cat_size")).disabled=false;
	}else{
	
	(document.getElementById("cat_size")).value='0';
	(document.getElementById("cat_size")).disabled=true;
	}
	if((document.getElementById("cat_size")).value!='0'){
	(document.getElementById("cat_need")).disabled=false;
	}else{
	(document.getElementById("cat_need")).value='0';
	(document.getElementById("cat_need")).disabled=true;
	
	}
	(document.getElementById("iamsProduct")).disabled=false;	
	(document.getElementById("firstOtherProduct")).disabled=false;	
	(document.getElementById("secondOtherProduct")).disabled=false;	
		
		
		
		
	}
} 
/*************************************************************************************************************************************************/
											/* CAT PRODUCT METHODS COMPLETED*/
/*************************************************************************************************************************************************/

function Get_Cookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}