﻿
        function AddToCart(frm,fact,pid,pqtyelm,pmfgName,pdesc,pprice,actprice,pminqty,affiliatecode)
        {
            var fElm = document.getElementById(frm);
            var pqty = pqtyelm.value;
            if(Number(pqty) < Number(pminqty))
            {
                alert('The minimum quantity for this product is ' + pminqty);
                pqtyelm.value = pminqty;
                return false;
            }
            fElm.action =fact;
            fElm.ProdID.value =pid;
            fElm.ProdQty.value =pqty;
            fElm.ProdMfgName.value =pmfgName;
            fElm.ProdDesc.value = pdesc;
            fElm.ProdPrice.value = pprice;
            fElm.ActProdPrice.value = actprice;
            fElm.MinQty.value = pminqty;
            fElm.Affiliate.value = affiliatecode;
            fElm.submit(); 
            return true;
        }

	 function TrackActivity(searchTerm,categoryFIlter,BrandFilter,PriceFilter, activityType,ItemId, ItemIdType,ItemPrice, desc, customerid, customerType, strurl,comments )
        {
            //GoECart.Core.Search.Analytics.ActivityTracker.SubmitActivity(searchTerm,'Search','234','GRP','Desc','1','Member',window.location.href,'something');
            GoECart.Core.Search.Analytics.ActivityTracker.SubmitActivity(searchTerm,categoryFIlter,BrandFilter,PriceFilter, activityType, ItemId,ItemIdType,ItemPrice, desc,customerid,customerType,strurl, comments);
            return true;
        }
        function TrackFirstSearch(searchTerm)
        {
            if(searchTerm != null)
                TrackActivity(searchTerm,'','','','SEARCH','','','','','','',window.location.href,'search button clicked');
            var strBaseUrl = document.aspnetForm.action;
            var tmpStr = strBaseUrl.split("?",2);
            var strQStr  = "";
            if(tmpStr.length > 1)
            {
                strBaseUrl = tmpStr[0];
                strQStr = tmpStr[1];
            }
            if(strQStr.length > 1)
            {
                var splitStr = strQStr.split("&");
                var isExists = false;
                for(var i=0;i < splitStr.length; i++)
                {
                    var strPair = splitStr[i].split("=",2);
                    if(strPair[0].toLowerCase() == "searchfor")
                    {
                        splitStr[i] = "searchfor=" + searchTerm;
                        isExists = true;
                        break;
                    }
                }
                if(isExists)
                {
                    document.aspnetForm.action= strBaseUrl +  "?" + splitStr.join("&");
                }
                else
                {
                    document.aspnetForm.action = document.aspnetForm.action  + "&searchfor=" + searchTerm;
                }
            }
            else
            {
                document.aspnetForm.action = document.aspnetForm.action + "?searchfor=" + searchTerm;
            }
            return true;
        }
        function TrackFilterSearch(searchTerm,categoryFilter,BrandFilter,priceFilter)
        {
            if(searchTerm != null)
                TrackActivity(searchTerm,categoryFilter,BrandFilter,priceFilter,'FILTER','','','','','','',window.location.href,'Filter applied');
            return true;
        }
        function ItemNavigate(searchTerm,categoryFIlter,BrandFilter,PriceFilter, activityType,ItemId, ItemIdType,ItemPrice, desc, customerid, customerType, strurl,comments )
        {
            try
            {
                TrackActivity(searchTerm,categoryFIlter,BrandFilter,PriceFilter, activityType, ItemId, ItemIdType, ItemPrice, desc, customerid, customerType, strurl, comments);
            }
            catch(e)
            {
            }
            window.location = strurl;
            return true;
        }

function ShowImage()
{ 
    document.getElementById('ctl00_ctl00_ContentPlaceHolder_SiteMaster_txtSearch').style.backgroundImage  = 'url(images/preloader.gif)';  
    document.getElementById('ctl00_ctl00_ContentPlaceHolder_SiteMaster_txtSearch').style.backgroundRepeat= 'no-repeat';
    document.getElementById('ctl00_ctl00_ContentPlaceHolder_SiteMaster_txtSearch').style.backgroundPosition = 'right';
}

function HideImage()
{ 
    document.getElementById('ctl00_ctl00_ContentPlaceHolder_SiteMaster_txtSearch').style.backgroundImage  = 'none';
}

function launchQuickLook()
{
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}

	var popUpWin = document.getElementById("popupContent");
	var leftpos = myWidth/2-250;
	var toppos = myHeight/2-275;

	if(parseInt(myWidth) < parseInt(leftpos))
		leftpos = 0;

	if(parseInt(myHeight) < parseInt(toppos))
		toppos = 0;

//	popUpWin.style.left = leftpos + 'px';
//	popUpWin.style.top = toppos + 'px';
//	popUpWin.style.position = "absolute";

	//Do an Ajaxcall and load the content in the div of quick view
	LoadQuickViewContent();
	
	popUpWin.style.visibility = "visible";
	popUpWin.style.display = "block";
	var divquickLook = document.getElementById("quickLookWindow");

	divquickLook.style.visibility = "hidden";
	divquickLook.style.display = "none";
}
function setImgSrc(obj, imageURL)
{
	var divquickLook = document.getElementById("quickLookWindow");
	divquickLook.style.visibility = "visible";
	divquickLook.style.display = "block";
	obj.src = imageURL;
}
function showQuickLookImg(obj, divId, ProdId, ProdType, SiteUrl)
{

	var divctrl = document.getElementById(divId);
	var divPos = findPos(divctrl);
	var divquickLook = document.getElementById("quickLookWindow");

	divquickLook.style.left = divPos[0] + 10 + 'px';
	divquickLook.style.top = divPos[1] + 10 + 'px';
	divquickLook.style.visibility = "visible";
	divquickLook.style.display = "block";

    document.getElementById("hidProdId").value = ProdId;
    document.getElementById("hidProdGroup").value = ProdType;
    document.getElementById("hidSiteUrl").value = SiteUrl;
}
function hideQuickLookImg(obj)
{
	var divquickLook = document.getElementById("quickLookWindow");
	divquickLook.style.visibility = "hidden";
	divquickLook.style.display = "none";
}


function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

function CloseQuickView()
{
	var divquickLook = document.getElementById("popupContent");
	divquickLook.style.visibility = "hidden";
	divquickLook.style.display = "none";
}



function CheckXMLHTTP()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();
    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        //xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
          
      }
      
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}

var doAJAXCall = function (PageURL, ReqType, PostStr, FunctionName) {

	// create the new object for doing the XMLHTTP Request
	var myConn = new CheckXMLHTTP();

	// check if the browser supports it
	if (myConn)	{
	    
	    // XMLHTTPRequest is supported by the browser, continue with the request
	    myConn.connect('' + PageURL + '', '' + ReqType + '', '' + PostStr + '', FunctionName);    
	} 
	else {
	    // Not support by this browser, alert the user
	    alert("XMLHTTP not available. Try a newer/better browser, this application will not work!");   
	}
}


var LoadQuickViewContent = function() {

	//get the productid and flag for product group from the hidden field and get the content from the GoECart site
	var prodId = document.getElementById("hidProdId").value;
	var prodGrp = document.getElementById("hidProdGroup").value;
	var siteUrl = document.getElementById("hidSiteUrl").value;
	
	// build up the post string when passing variables to the server side page
	var PostStr = "";
	var url = "QuickView.aspx"
	PostStr  = "ProdId="+escape(prodId);
	PostStr += "&ProdGrp="+escape(prodGrp);
	PostStr += "&SiteUrl="+escape(siteUrl + "QuickView.asp");
	
	document.getElementById("quickviewcontent").innerHTML = "";
	// use the generic function to make the request
	doAJAXCall(url, 'POST', PostStr, showNowResponse);
	
};

var showNowResponse = function (oXML) { 
    // get the response text, into a variable
    var response = oXML.responseText;
 
    // update the Div to show the result from the server
	document.getElementById("quickviewcontent").innerHTML = response;
};

function setImg(imageURL)
{
	document.getElementById("ProdViewImage").src = imageURL;
}

