var xmlHttp;
var count;
var prodId;
var tabName;
var type;
//Fetching the XmlHttpObject.
function GetXmlHttpObject() {
    var xmlHttp=null;
	try {
		xmlHttp=new XMLHttpRequest();
	} catch (e) {
		try {
		 xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e){
		 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
  return xmlHttp;
}
//Method is used to add the product to virtual pack.
function onclickList(pContextPath, pProductId,tabValue, pCount, pURL,pType,pIsSecureUrl){
	count = pCount;
	prodId = pProductId;
	tabName = tabValue;
	type = pType;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
	alert ("Your browser does not support AJAX!");
		return;
	}
	if(pIsSecureUrl =="false"){
		var url=pContextPath+"/catalog/product/common/addProductToListAjaxForm.jsp?productId="+pProductId+"&count="+count+"&URL="+pURL;
	}else{
		var url=pContextPath+"/catalog/product/common/addProductToListAjaxFormForSecuredPages.jsp?productId="+pProductId+"&count="+count+"&URL="+pURL;
	}
	xmlHttp.onreadystatechange=getResposeObject;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
//Method is used to add the product to virtual pack.
function addProductToThisList(pContextPath, pProductId, pAction, pCount,pIsSecureUrl) {
	count = pCount;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
	 alert ("Your browser does not support AJAX!");
		return;
	}
	var listname = document.getElementById("listname"+pCount).value;
	if(pIsSecureUrl =="false"){
		var url=pContextPath+"/catalog/product/common/addProductToListAjaxForm.jsp";
		
	}else{
		var url=pContextPath+"/catalog/product/common/addProductToListAjaxFormForSecuredPages.jsp";
	}
	url=url+"?productId="+pProductId+"&action="+pAction+"&listName="+listname+"&count="+count;
	xmlHttp.onreadystatechange=getResposeObject;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
//Method is used to add the product to virtual pack.
function removeProductFromThisList(pContextPath, pListId, pProductId, pAction, pCount,pIsSecureUrl) {
	count = pCount;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
	alert ("Your browser does not support AJAX!");
		return;
	}
	var listname = document.getElementById("listname"+pCount).value;
	if(pIsSecureUrl =="false"){
    	var url=pContextPath+"/catalog/product/common/addProductToListAjaxForm.jsp";
    }else{
		var url=pContextPath+"/catalog/product/common/addProductToListAjaxFormForSecuredPages.jsp";
	}
	url=url+"?productId="+pProductId+"&action="+pAction+"&listName="+listname+"&listId="+pListId+"&count="+count;
	xmlHttp.onreadystatechange=getResposeObject;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
//Method is used to add the product to virtual pack.
function addProductToSelectedList(pContextPath, pProductId, pAction, pCount,pIsSecureUrl) {
	count = pCount;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
	alert ("Your browser does not support AJAX!");
		return;
	}
	var listIdInput = document.getElementById("listId"+pCount).value;
	var listIdInputTokens = listIdInput.split( "," );
    var listId = listIdInputTokens[0];
    var listname = listIdInputTokens[1];
    if(pIsSecureUrl =="false"){
    	var url=pContextPath+"/catalog/product/common/addProductToListAjaxForm.jsp";
    }else{
		var url=pContextPath+"/catalog/product/common/addProductToListAjaxFormForSecuredPages.jsp";
	}
    url=url+"?productId="+pProductId+"&action="+pAction+"&listId="+listId+"&count="+count+"&listName="+listname;
    xmlHttp.onreadystatechange=getResposeObject;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
//Fetches the ResponseObject.
function getResposeObject() {
	if (xmlHttp.readyState==4) {
		var responseObject = xmlHttp.responseText;
		if(responseObject != null) {
			showTheListResults(responseObject);
		}		
	}	
}
//Extension of showTheListResults() method,Displays the product info.
function showTheListResults(responseObject) {
	if(tabName == "null" ||tabName == "") {
		if(type != "null" && type != ""){
			document.getElementById(prodId+""+type+""+count).innerHTML = responseObject;
		}else{
			document.getElementById(prodId+""+count).innerHTML = responseObject;
		}
	}else{
		document.getElementById(prodId+""+tabName+""+count).innerHTML = responseObject;
	}
}
//Extension of showTheListResults() method,Displays the product info.
function hideToolTip() {
	$(".tool-tip-product").hide();
}
//Extension of hideText() method, hides the Text at list creation.
function hideText(param) {
 document.getElementById(param).value = '';	
}

//Extension of hideText() method, hides the Text at list creation.
function showMakeList(param) {
 document.getElementById(param).style.display = 'block';
 document.getElementById("make_list").style.display = 'none'; 
}
//This function is used for displaying the tool-tip for the products in the product-detail page.
function onclickListForAUser(pToolTip1,pToolTip2){
	if(document.getElementById(pToolTip1) != null){
		document.getElementById(pToolTip1).style.display = 'block';
	}
	if(document.getElementById(pToolTip2) != null){
		document.getElementById(pToolTip2).style.display = 'none';
	}
}

