﻿// CallWebServiceMethods.js

// This function calls the Web service method without 
// passing the callback function. 
function GetNoReturn()
{
    Samples.AspNet.WebService.GetServerTime();
    alert("This method does not return a value.");
    
}


// This function calls the Web service method and 
// passes the event callback function. 
function GetAjaxProduct(param, PageIndex, CallBackMethod, CallBackError)
{
    Exper.WebService2.GetProduct(param, PageIndex, CallBackMethod, CallBackError);
    //SucceededCallback);
    
}

function GetAjaxResellers(param, CallBackMethod, CallBackError)
{
    Exper.WebService2.GetResellers(param, CallBackMethod, CallBackError);
    //SucceededCallback);
    
}

function GetAjaxResellers2(param, param2, CallBackMethod, CallBackError)
{
    Exper.WebService2.GetResellers2(param, param2, CallBackMethod, CallBackError);
    //SucceededCallback);
    
}


// This function calls the Web service method 
// passing simple type parameters and the 
// callback function  
function Add(a,  b)
{
    Samples.AspNet.WebService.Add(a, b, 
    SucceededCallback);
}

// This function calls the Web service method 
// that returns an XmlDocument type.  
function GetXmlDocument() 
{
    Samples.AspNet.WebService.GetXmlDocument(
        SucceededCallbackWithContext, FailedCallback,
        "XmlDocument")
}

// This function calls a Web service method that uses
// GET to make the Web request.
function MakeGetRequest() 
{

    Samples.AspNet.WebService.EchoStringAndDate(
        new Date("1/1/2007"), " Happy",
        SucceededCallback, 
        FailedCallback, "HappyNewYear");

}

// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object, the user context, and the 
// calling method name as parameters.
function SucceededCallbackWithContext(result, userContext, methodName)
{
    var output;
    
    // Page element to display feedback.
    var RsltElem = document.getElementById("ResultId");
    
    var readResult;
    if (userContext == "XmlDocument")
	{
	
	    if (document.all) 
	        readResult = 
		        result.documentElement.firstChild.text;
		else
		    // Firefox
		   readResult =
		        result.documentElement.firstChild.textContent;
		
	     RsltElem.innerHTML = "XmlDocument content: " + readResult;
	}
    
}

// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object as a parameter.
function SucceededCallback(result, eventArgs)
{
    // Page element to display feedback.
    var RsltElem = document.getElementById("ResultId");
    RsltElem.innerHTML = result;
}


// This is the callback function invoked if the Web service
// failed.
// It accepts the error object as a parameter.
function FailedCallback(error)
{
    // Display the error.    
    var RsltElem = 
        document.getElementById("ResultId");
    RsltElem.innerHTML = 
    "Service Error: " + error.get_message();
}


// ********************************** ozzi *********************************************
            function AttachAjaxEvents()
            {
                var nodes = document.getElementsByTagName("a");
                for(var i=0; i<nodes.length; i++)
                {
                    var node = nodes[i];
                    if(node.rel && node.rel.substring(0,4)=="ajax")
                    {
                        //alert(node.rel);
                        $D.AddEvent(node, "mouseover", function(e) { return AjaxGetProduct(e); },false);
                        $D.AddEvent(node, "mouseout", function(e) { return AjaxCancelRequest(e); },false);
                        var oParent = node.parentNode;
                        if(oParent)
                        {
                            $D.AddEvent(oParent, "mouseover", function(e) { return onOverAjaxDiv(e); },false);
                            $D.AddEvent(oParent, "mouseout", function(e) { return onOutAjaxDiv(e); },false);
                        }
                    }
                }
            }
            
            function onOverAjaxDiv(e)
            {
                elem = e.target ? e.target : event.srcElement;
                if(elem)
                {
                    var oLi,oDiv;
                    oLi = findLiElem(elem);
                    if(oLi==outElem && outID)
                    {
                        window.clearTimeout(outID);
                    }
                }
            }
            
            function onOutAjaxDiv(e)
            {
                elem = e.target ? e.target : event.srcElement;
                var oLi,oDiv;
                if(elem)
                {
                    oLi = findLiElem(elem);
                    if(oLi==outElem && outID)
                        window.clearTimeout(outID);
                    
                    oDiv = findDiv(oLi);
                    if(oDiv.innerHTML!="")
                    {
                        outElem = oLi;
                        outID = window.setTimeout(function(){oDiv.innerHTML = ""},50);
                    }
                }
            }
            
            function findLiElem(elem)
            {
                var oLi;
                if(elem && elem.parentNode)
                {
                    oLi = elem.parentNode;
                    while(oLi.nodeName!="LI")
                        oLi = oLi.parentNode;
                }
                return oLi;
            }
            
            function findDiv(liElem)
            {
                var oDiv;
                var oChilds = liElem.childNodes;
                
                for(var i=0; i<oChilds.length; i++)
                {
                        var item = oChilds[i];
                        if(item.nodeName=="DIV")
                        {
                            oDiv = item;
                            break;
                        }
                }
                
                return oDiv;
            }
            
            var oTarget;
            var oPageIndex=0;
            var oParam;
            var oHID = 0;
            var outID, outElem;
            function AjaxGetProduct(e)
            {
                var elem, paramStr, param, prm2;
                elem = e.target ? e.target : event.srcElement;
                
                //onOverAjaxDiv(elem);
                        
                paramStr = elem.rel;
                prm2 = elem.href;
                oHID=0;
                var startIndex = prm2.indexOf("hID=",0);
                if(startIndex!=-1)
                {
                    var endIndex = prm2.indexOf("&",startIndex);
                    oHID = prm2.substring(startIndex+4,endIndex);
                }
                oParam = paramStr.replace("ajax[@CatID:","").replace("]","");
                oPageIndex = 0;
                if(oTarget)
                    oTarget.innerHTML = "";
                oTarget = elem.nextSibling;
                oTarget.innerHTML = String.format("<div style='width:245px;height:175px;'>{0}</div>",GetProgress());
                //alert(oTarget);
//                var newe = document.createElement("div");
//                newe.setAttribute("style","position:relative;width:200px;height:200px;background-color:yellow;float:left");
//                obj.appendChild(newe);
//                var bound = Sys.UI.DomElement.getBounds(elem);
//                var MiniPanel = $get("MiniPanel");
                
//                Sys.UI.DomElement.setLocation(MiniPanel,bound.x+200,bound.y);
//                MiniPanel.style.display='block'; 
                GetAjaxProduct(oParam, oPageIndex, RenderToProduct, OnError);
                //GetAjaxProduct(param, 0, RenderToProduct, OnError);
            }
            
            
            function AjaxCancelRequest(e)
            {
                //var MiniPanel = $get("MiniPanel").style.display='none';
                elem = e.target ? e.target : event.srcElement;
//                var oDiv;
//                if(elem)
//                {
//                    if(elem==outElem && outID)
//                        window.clearTimeout(outToID);
//                    
//                    oDiv = elem.nextSibling;
//                    if(oDiv.innerHTML!="")
//                    {
//                        outElem = elem;
//                        outToID = window.setTimeout(function(){oDiv.innerHTML = ""},300);
//                    }
//                }
            }
            
            function GetProgress()
            {
                var sb = new Sys.StringBuilder();
                sb.append("<div class=\"prog\" style='width:31px;height:31px;margin:0;display:block;position:absolute;padding:87px 107px;background-color:#0097FF;opacity:0.5;filter:alpha(opacity=50);'><img src=\"/styles/images/ajax-loader.gif\" alt=\"\" /></div>");
                //sb.append("<table cellpadding='0' cellspacing='0' border='0' width='245'>");
                //sb.append("<tr><td style='height:155px;text-align:center;background-color:black;opacity:0.7;filter:alpha(opacity=70);'><img src=\"/styles/images/ajax-loader.gif\" alt=\"\" /></td></td>");
                //sb.append("</table>");
                
                
                return sb.toString();
            }
            function GoNext()
            {
                //oTarget.innerHTML = "Yükleniyor...";
                var oLoader = $get("panel"+oParam);
                if(oLoader)
                {
                    oLoader.innerHTML = GetProgress() + oLoader.innerHTML;
                }
                oPageIndex++;
                GetAjaxProduct(oParam, oPageIndex, RenderToProduct, OnError);
            }
            function GoBack()
            {
                //oTarget.innerHTML = "Yükleniyor...";
                var oLoader = $get("panel"+oParam);
                if(oLoader)
                {
                    oLoader.innerHTML = GetProgress() + oLoader.innerHTML;
                }
                oPageIndex--;
                GetAjaxProduct(oParam, oPageIndex, RenderToProduct, OnError);
            }
            function RenderToProduct(Result)
            {
                //oTarget.style.visibility = "visible";
                var sb = new Sys.StringBuilder();
                if(Result.Product.Title!=null)
                {
                    //sb.append(oPageIndex);
                    sb.append(String.format("<div id=\"panel{0}\">",oParam));
                    sb.append("<table width=\"210\" height=\"185\" style=\"margin:10px 15px 10px 20px;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
                    sb.append("<tr>");
                    
                    //sb.append(String.format("<td><a href=\"Javascript:GoBack();\"><img src=\"images/ico_ajax_left.jpg\" style=\"width:12px;height:17px;visibility:{0};\" /></a></td>",Result.IsBack?"visible":"hidden"))
                    sb.append(String.format("<td><input type=\"image\" onclick=\"Javascript:GoBack();\" src=\"images/ico_ajax_left.jpg\" style=\"visibility:{0};\" class=\"ajxbut\" /></td>",Result.IsBack?"visible":"hidden"))
                    var thbx = "/images/prodNoImage.jpg";
                    if(Result.Product.Thb!="")
                        thbx = Result.Product.Thb;
                    sb.append(String.format("<td align=\"center\"><a href=\"ProductDetails.aspx?hID={4}&RecID={2}&amp;CatID={3}\"><img src=\"{0}\" alt=\"{1}\" class=\"AjxImg\" /></a></td>",thbx,Result.Product.Title,Result.Product.ProdID,Result.Product.CatID,oHID));
                    //sb.append(String.format("<td align=\"right\"><a href=\"Javascript:GoNext();\"><img src=\"images/ico_ajax_right.jpg\" style=\"width:12px;height:17px;visibility:{0}\;\" /></a></td>",Result.IsNext?"visible":"hidden"))
                    sb.append(String.format("<td align=\"right\"><input type=\"image\" onclick=\"Javascript:GoNext();\" src=\"images/ico_ajax_right.jpg\" style=\"visibility:{0}\;\" class=\"ajxbut\" /></td>",Result.IsNext?"visible":"hidden"))

                    sb.append("</tr>");
                    sb.append("<tr>");
                    sb.append(String.format("<td height=\"20\"></td><td valign=\"middle\">{0}<br/><span class=\"ajax_price\">{1}</span></td><td valign=\"bottom\"></td>",Result.Product.Title,Result.Product.Price));
                    //sb.append(String.format("<td height=\"20\"></td><td valign=\"middle\"><div class=\"ajax_text\">{0}<br/>{1}<br/><span class=\"ajax_price\">{2}</span></td><td valign=\"bottom\"></td>",Result.Product.Mark,Result.Product.Title,Result.Product.Price));
                    sb.append("</tr>");
                    sb.append("<tr>");
                    sb.append(String.format("<td colspan='3' height='20' align='right'>{0}/{1}</td>",Result.CurrentPage+1,Result.TotalPage));
                    sb.append("</tr>");
                    sb.append("</div>");
                   
                   //sb.append(String.format("<img src=\"{0}\" alt=\"\" />",Result.Price));
                   //sb.append("<br/>");
                   //sb.append(String.format("<p>Son Güncelleme : {0}</p>",result.DateUpdated.localeFormat("dd MMMM yyyy")));
                }
                else
                {
                    sb.append("<table width=\"210\" height=\"185\" style=\"margin:10px 15px 10px 20px;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
                    sb.append("<tr>");
                    sb.append("<td style='text-align:center'>Bu ürünle ilgili bilgi almak için çağrı merkezimizi (444 0 140) arayabilirsiniz!</td>");
                    sb.append("</tr>");
                    sb.append("</table>");
                }
                         
                oTarget.innerHTML = sb.toString();
            }
            function OnError()
            {
            
            }
            
            

            function RenderToResellers(Result)
            {
                var sb = new Sys.StringBuilder();
                var oCont = $get("ResellerListContainer");
                if(Result!=null && Result.length>0)
                {
                    for(var ix in Result)
                    {
                        sb.append("<div class=\"satis_kanallari\">");
                        sb.append(String.format("<h5><a href=\"#\">{0}</a></h5>",Result[ix].Title));
                        sb.append(String.format("<strong>Adres</strong>: {0}<br />",Result[ix].Address));
                        sb.append(String.format("<strong>Telefon</strong>: {0}",Result[ix].Phone));
                        sb.append("</div>");
                   }
                }
                else
                {
                    sb.append("<p>Bu bölgede bulunan servis noktaları ile ilgili bilgi almak için çağrı merkezimizi (444 0 140) arayabilirsiniz!</p>");
                }
                         
                oCont.innerHTML = sb.toString();
            }
            
            function onErrorRenderToReseller()
            {
                var oCont = $get("ResellerListContainer");
                oCont.innerHTML = "Error";
            }

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
