
$(document).ready(Load);

var oPage=new Object();
oPage.Path=document.location,
oPage.error=function(msg, url, line)
{
    alert("error:"+msg+"\n"+url+"\n"+line);
    return true;
},
oPage.ShopType=new String(),
oPage.Location=window.location,
oPage.Nothing=function()
{
    var NoPage=new Object();
    var div=Create('div');
    $(div).attr("class","nothingAvail");
    var p1=Create('p');
    $(p1).attr("class","nothingAvail").html("We were unable to find results for: <b>"+oPage.Txt()+"</b>.").appendTo(div);
    var divUl=Create('div');
    var ul=Create('ul');
    var arr=new Array();
    arr.push("Check your spelling.");
    arr.push("Try more general words.");
    arr.push("Try different words that mean the same thing.");
    $.each(arr, function(i, item){
        var li=Create('li');
        $(li).html(item).appendTo(ul);
    });
    $(divUl).attr("class","right_Content").append(ul).appendTo(div);
    var br=Create("br");
    $(br).appendTo(div);
    return $(div);
},
oPage.Wait=function()
{
    var div=Create('div');
    $(div).css({textAlign:"center", height:"150px"});
    var img=Create('img');
    $(img).attr("src","../resources/images/ajax-loader3.gif").css("padding-top", "20px").appendTo(div);
    return $(div);
},
oPage.SearchTxt="",
oPage.SuggestQuery="",
oPage.Txt=function(text)
{
    if(text!=null)
        return $(".txtSearch").val(text);
    else
        return $(".txtSearch").val();
},
oPage.BtmTxt=function(text)
{
    if(text!=null)
        return $(".txtSearchBottom").val(text);
    else
        return $(".txtSearchBottom").val();
},
oPage.BtmText=function()
{
return $(".txtSearchBottom");
},
oPage.Text=function()
{
    return $(".txtSearch");
},
oPage.Btn=function()
{
    return $(".btnSearch");
},
oPage.addBtnLnk=function()
{
    return $(".aBtnLnk");
},
oPage.HomePage=true,
oPage.GoTo=function(adress)
{
    try
    {
        window.location = adress;
    }
    catch(err)
    {
    }
},
oPage.Redirect=function(type, radio, page)
{
    var radioType;
    var PageNumber;
    (radio!=null) ? radioType="&radio="+radio : radioType="";
    (radioType=="&radio=Google") ? radioType="" : "";
    (page!=null) ? PageNumber="&page="+page : PageNumber="";
    (PageNumber=="&page=1") ? PageNumber="" : "";
    var path=this.Path.protocol+"//"+this.Path.hostname+this.Path.pathname;

    if(oPage.Txt().length>0)
        window.location = path+"?q="+escape(oPage.Txt())+"&type="+type+radioType+PageNumber;
},
oPage.Slogan=true,
oPage.SearchTxtFocus=function(arg)
{
    if(oPage.Slogan)
    {
        oPage.Slogan=false;
    }
    else
    {
        oPage.Text()[0].select();
    }
},
oPage.SearchTestTextBox=function()
{
},
oPage.IsPasted=false,
oPage.Paste=function()
{
    $("#primaryContent").show();
    var T=setTimeout("StartSearch('"+oPage.Txt()+"');", 100);
    this.IsPasted=true;
},
oPage.Decode=function(text)
{
    while(text.indexOf("'")>-1)
    text=text.replace("'","%27");
    
    while(text.indexOf("=")>-1)
    text=text.replace("=","%3D");
    
    while(text.indexOf("#")>-1)
    text=text.replace("#","%23");
    
    return text;
},
oPage.Empty=function()
{
    var EmptyCell=Create('div');
    $(EmptyCell).attr({className:"emptyCell", id:"dvEmpty"});
    $(EmptyCell).droppable({accept:"#todaysTips"});
    $(EmptyCell).html("Empty");
    return $(EmptyCell);
},
oPage.DraggablePosition=function(draggable)
{
    var ElemntsArray=$("#"+draggable.parent().attr("id")+"> .modbox");
    var CurrentId=draggable.attr("id");
    
    $(ElemntsArray).each(function(i){
        if($(this).attr("id")==CurrentId)
            {
            CurrentIndex=i;
            }
    });
    var Order=new Object();
    Order.top=(CurrentIndex==0)?null:$($(ElemntsArray)[CurrentIndex-1]);
    Order.bottom=(CurrentIndex==ElemntsArray.length-1)?null:$($(ElemntsArray)[CurrentIndex+1]);
    return Order;
},
oPage.WidgetAppr=function(FullName)
{
    GetApprInfo(FullName);
},
oPage.Block=function(InnerChild)
{
      var height=($(window).height()>$("body").height())?$(window).height():$("body").height();
      $("#dvBlock, #dvInner").remove();
      var div=Create('div');
      $(div).attr({className:"dvBlock", id:"dvBlock"}).height(height).appendTo($("body"));
      var InnerObj=Create('div');
      if(InnerChild!=null)
      {
          $(InnerObj).attr({className:"dvInner", id:"dvInner"}).append(InnerChild).appendTo($("body"));
          $(InnerObj).width(InnerChild.width());
          var Left=((jQuery.browser.opera) ? window.innerWidth - $(InnerObj).width() : $(window).width() - $(InnerObj).width())*0.5;
          var Top=((jQuery.browser.opera) ? window.innerHeight - $(InnerObj).height() : $(window).height() - $(InnerObj).height())*0.5;
          $(InnerObj).css({left:Left, top:Top});
      }
},
oPage.UnBlock=function()
{
      $("#dvBlock, #dvInner").remove();
},
oPage.ObjPosition=function(Obj)
{
    MainObj=Obj;
    var x = Obj.offsetLeft;
    while (Obj = Obj.offsetParent) x += Obj.offsetLeft;

    Obj=MainObj;
    var y = Obj.offsetTop;
    while (Obj = Obj.offsetParent) y += Obj.offsetTop;

    var Res={
        Top: y,
        Left: x
    };
    return Res;
},
oPage.New=function()
{
}
/*****************end oPage ******************/

function Load()
{
    oPage.Text().focus();
    oPage.Text().click(oPage.SearchTxtFocus);

    oPage.Text().keydown(function(arg){
        if(arg.keyCode==13)
            {
               window.location.href ="http://www.leapfish.com/web.aspx?q="+oPage.Txt();
            
             return false;
             //
             //btnSearchClick();
            //document.Main.submit();
            }
        else
           oPage.SearchTestTextBox();
    });
    
//    $(".txtSearch").click(function(){
//        if(!oPage.Slogan && oPage.Txt().length>0)
//            document.Main.submit();
//    });
    
    oPage.Btn().click(function(){
        if(!oPage.Slogan && oPage.Txt().length>0)
            document.Main.submit();
    });
}

function btnRealTimeClick()
{
    if(!oPage.Slogan && oPage.Txt().length>0)
        window.location="/real.aspx?q="+oPage.Txt();
}
