function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
    
}

function enc(s)
{
	return escape(s);
}
var preLoad = new Array()
preLoad[0] = new Image()
preLoad[1] = new Image()
preLoad[2] = new Image()
preLoad[3] = new Image()
preLoad[4] = new Image()
preLoad[5] = new Image()
preLoad[6] = new Image()
preLoad[7] = new Image()
preLoad[8] = new Image()
preLoad[9] = new Image()
preLoad[10] = new Image()
preLoad[11] = new Image()
preLoad[12] = new Image()
function preloadStatusImage()
{
    preLoad[0].src = "/images/addtocart.gif"
	preLoad[1].src = "/images/sold.gif"
	preLoad[2].src = "/images/Soldoffline.gif"
	preLoad[3].src = "/images/onhold.gif"
	
	preLoad[4].src = "/images/available.gif"
	preLoad[5].src = "/images/notavailable.gif"
	preLoad[6].src = "/images/notavailable.gif"
	preLoad[7].src = "/images/hold.gif"
	
	preLoad[8].src = "/images/available.gif"
	preLoad[9].src = "/images/notavailable.gif"
	preLoad[10].src = "/images/hold.gif"
	
	preLoad[11].src = "/images/notforsale.gif"
	preLoad[12].src = "/images/notsate.gif"
}
addLoadEvent(preloadStatusImage);
	
	function displayPage(PageID)
	{
	    document.getElementById('siteLoader').style.display = '';
	    
		document.getElementById("mainContent").innerHTML =document.getElementById("Page" + PageID).innerHTML;
		var anchors = document.getElementsByTagName("a");
		var find=0;
		for (var i=0; i<anchors.length; i++){
			var anchor = anchors[i];
			if(anchor.getAttribute('rel')!=undefined)
			{
				var relAttribute =(anchor.getAttribute('rel'));							
				if (anchor.getAttribute('imgpath') && (relAttribute=='lightbox')){
					find=1;
					i=anchors.length;
				}				
			}
		}
		if(find==1)
		{
			initLightbox();
		}
		var icount=document.getElementById('hdnPageCnt').value;			
				
		var i=0;		
		for(i=0; i<icount; i++)
		{
		    if(PageID==i)
		    {
		        document.getElementById('ach' + i).className="BoldPageNo";
		    }
		    else
		    {
		        document.getElementById('ach' + i).className="NormalPageNo";
    	    }		    
		}
		
		    //setTimeout("LoadingPage()",3000);   	
	}	 

	function displayPageOld(PageID)
	{		
    	//initLightbox();    
    	if(document.getElementById("Page" + PageID) != null)
    	{
		    document.getElementById("mainContent").innerHTML =document.getElementById("Page" + PageID).innerHTML;	
		    if(document.getElementById('hdnPageCnt') != null)
		    {
	            if(document.getElementById('hdnPageCnt').value != "")
	            {	
	                var icount=document.getElementById('hdnPageCnt').value;					
	                var i=0;		
	                for(i=0; i<icount; i++)
	                {
	                    if(PageID==i)
	                    {
	                        document.getElementById('ach' + i).className="BoldPageNo";
	                    }
	                    else
	                    {
	                        document.getElementById('ach' + i).className="NormalPageNo";
	                    }		    
	                }	
	            }
		    }
		}	
	}		 
	
	function functionaddcart(ProdID)
	{		    
    	if(isNaN(parseInt(ProdID)))
    	{
    	    if(StrIndexOf(ProdID,'imgBtnPrdID_1')==0)
	        {
    	        ProdID=StrReplace(ProdID,'imgBtnPrdID_1',''); 
	        }
	        else
	        {
	            ProdID =StrReplace(ProdID,'imgBtnPrdID','')     	    
	        }	      
    	}    	
    	
		document.forms[0].method="Post";
		document.forms[0].action="frmAddtocart.ashx?PID=" + ProdID;
		document.forms[0].submit();
    }
    function functionaddcart_Cat(ProdID)
	{	
	    ProdID = StrReplace(ProdID,'imgBtnCatPrdID','')
		document.forms[0].method="Post";
		document.forms[0].action="frmAddtocart.ashx?PID=" + ProdID;
		document.forms[0].submit();
    }    
    function funImageCall(ImgObj,ProdID)
	{
		var ProdStatus=AjaxUtilsMethods.ProductDetails(ProdID).value;
		if(ProdStatus==1)
		{   		    
			var addCartimg;
			addCartimg=document.getElementById(ImgObj);
			addCartimg.src=preLoad[0].src		
			addCartimg.setAttribute("onclick", function(){functionaddcart(ProdId);});	                            	
			addCartimg.setAttribute("onClick","functionaddcart(" + ProdID + ")");
		}
		else 
		{
			document.getElementById(ImgObj).src=preLoad[1].src
		}	
	} 
    function funCheckStatus(TempPids)
	{		 
		var response = AjaxUtilsMethods.GetProductStatus(TempPids);            
        var ds = response.value;        
        if(ds != null && typeof(ds) == "object" && ds.Tables != null)
        {            
            if(ds.Tables[0].Rows.length>0)
            {   
                var i=0;                
                for(i=0; i<ds.Tables[0].Rows.length; i++)
                {                    
                     if(ds.Tables[0].Rows[i].statusID !="")
                     {  
                        if(ds.Tables[0].Rows[i].RemoveFromCatalog)        
                        {
                            ds.Tables[0].Rows[i].statusID=2;
                        }
                        else if(ds.Tables[0].Rows[i].isDeleted)        
                        {
                            ds.Tables[0].Rows[i].statusID=2;
                        }
                        else if((ds.Tables[0].Rows[i].isSold))        
                        {
                            ds.Tables[0].Rows[i].statusID=2;
                        }

                        var addCartimg;
                        var addCartimg_1;
                        
                        var ProdId=ds.Tables[0].Rows[i].productID;
                        var ImgId= "imgBtnPrdID" + ProdId;  
                        var ImgId_1= "imgBtnPrdID_1" + ProdId;                          
                        
                       
                        
                        var addCartimg;
                        var addCartimg_1;
                        addCartimg=document.getElementById(ImgId);                         
                        addCartimg_1=document.getElementById(ImgId_1);                         
                        if(ds.Tables[0].Rows[i].statusID == "1")
                        {   
                            addCartimg.src=preLoad[0].src;	                            
							addCartimg.style.cursor="hand";
							addCartimg.style.cursor="pointer";
                            addCartimg.setAttribute("onclick", function(){eval("functionaddcart(this.id);")});	                            
                            addCartimg.setAttribute("onClick","functionaddcart(this.id)");                           
                            
                            
                            addCartimg_1.src=preLoad[0].src;	                            
							addCartimg_1.style.cursor="hand";
							addCartimg_1.style.cursor="pointer";
                            addCartimg_1.setAttribute("onclick", function(){eval("functionaddcart(this.id);")});                           
                            addCartimg_1.setAttribute("onClick","functionaddcart(this.id)");                                   
                        }
                        else if(ds.Tables[0].Rows[i].statusID == "3")
                        {
                            addCartimg.src=preLoad[3].src
                            addCartimg_1.src=preLoad[3].src
                        }
                        else if(ds.Tables[0].Rows[i].statusID == "4")
                        {                            
                            addCartimg.src=preLoad[2].src
                            addCartimg_1.src=preLoad[2].src
                        }
                        else if(ds.Tables[0].Rows[i].statusID == "2")
                        {
                           addCartimg.src=preLoad[1].src
                           addCartimg_1.src=preLoad[1].src
                        }    
                        else if(ds.Tables[0].Rows[i].statusID == "5")
                        {
                           addCartimg.src=preLoad[11].src
                           addCartimg_1.src=preLoad[11].src
                        }                 
                        else 
                        {
                           addCartimg.src=preLoad[1].src
                           addCartimg_1.src=preLoad[1].src
                        }       
                     }
               }                                                
            }            
        }            	
	}
	function funCheckTop16PrdStatus(TempPids)
	{	
		var response = AjaxUtilsMethods.GetProductStatus(TempPids);            
        var ds = response.value;        
        if(ds != null && typeof(ds) == "object" && ds.Tables != null)
        {
            if(ds.Tables[0].Rows.length>0)
            {                
                var i=0;                               
                for(i=0; i<ds.Tables[0].Rows.length; i++)
                {    
                     if(ds.Tables[0].Rows[i].statusID !="")
                     {
					    if(ds.Tables[0].Rows[i].RemoveFromCatalog)        
                        {
                            ds.Tables[0].Rows[i].statusID=2;
                        }
                        else if(ds.Tables[0].Rows[i].isDeleted)        
                        {
                            ds.Tables[0].Rows[i].statusID=2;
                        }
                        else if((ds.Tables[0].Rows[i].isSold))        
                        {
                            ds.Tables[0].Rows[i].statusID=2;
                        }

                        var addCartimg;
                        var ProdId=ds.Tables[0].Rows[i].productID;
                        var ImgId= "imgTop16BtnCatPrdID" + ProdId;  
                        var addCartimg;
                        addCartimg=document.getElementById(ImgId);                                            
						if(addCartimg!=undefined)
						{
							if(ds.Tables[0].Rows[i].statusID == "1")
							{   
								addCartimg.src=preLoad[8].src;
								addCartimg.title="Available";
							}
							else if(ds.Tables[0].Rows[i].statusID == "3")
							{
								addCartimg.src=preLoad[10].src
								addCartimg.title="On Hold";
							}
							else if(ds.Tables[0].Rows[i].statusID == "4")
							{                            
								addCartimg.src=preLoad[9].src
								addCartimg.title="Sold";
							}
							else if(ds.Tables[0].Rows[i].statusID == "5")
							{                            
								addCartimg.src=preLoad[12].src
								addCartimg.title="Not For Sale";
							}
							else if(ds.Tables[0].Rows[i].statusID == "2")
							{
							   addCartimg.src=preLoad[9].src
							   addCartimg.title="Sold";
							}
							else
							{
							   addCartimg.src=preLoad[9].src
							   addCartimg.title="Sold";
							}
						 }
                     }
               }                                                
            }            
        }            	
	}
	function funCheckCatPrdStatus(TempPids)
	{	
		var response = AjaxUtilsMethods.GetProductStatus(TempPids);            
        var ds = response.value;        
        if(ds != null && typeof(ds) == "object" && ds.Tables != null)
        {
            if(ds.Tables[0].Rows.length>0)
            {                
                var i=0;                               
                for(i=0; i<ds.Tables[0].Rows.length; i++)
                {    
                     if(ds.Tables[0].Rows[i].statusID !="")
                     {
					    if(ds.Tables[0].Rows[i].RemoveFromCatalog)        
                        {
                            ds.Tables[0].Rows[i].statusID=2;
                        }
                        else if(ds.Tables[0].Rows[i].isDeleted)        
                        {
                            ds.Tables[0].Rows[i].statusID=2;
                        }
                        else if((ds.Tables[0].Rows[i].isSold))        
                        {
                            ds.Tables[0].Rows[i].statusID=2;
                        }

                        var addCartimg;
                        var ProdId=ds.Tables[0].Rows[i].productID;
                        var ImgId= "imgBtnCatPrdID" + ProdId;  
                        var addCartimg;
                        addCartimg=document.getElementById(ImgId);                                            
                        if(ds.Tables[0].Rows[i].statusID == "1")
                        {   
                            addCartimg.src=preLoad[4].src;	
                            addCartimg.style.cursor="hand";     
                            addCartimg.style.cursor="pointer";  
                            addCartimg.title="Available";  
                            addCartimg.setAttribute("onclick", function(){eval("functionaddcart_Cat(this.id);")});	                            
                            addCartimg.setAttribute("onClick","functionaddcart_Cat(this.id)");                                                                          
							
                        }
                        else if(ds.Tables[0].Rows[i].statusID == "3")
                        {
                            addCartimg.src=preLoad[7].src
                            addCartimg.title="Hold";  
                        }
                        else if(ds.Tables[0].Rows[i].statusID == "4")
                        {                            
                            addCartimg.src=preLoad[6].src
                            addCartimg.title="Sold";  
                        }
                        else if(ds.Tables[0].Rows[i].statusID == "5")
                        {                            
                            addCartimg.src=preLoad[12].src
                            addCartimg.title="Not For Sale";  
                        }
                        else if(ds.Tables[0].Rows[i].statusID == "2")
                        {
                           addCartimg.src=preLoad[5].src
                           addCartimg.title="Sold";
                        }
                        else
                        {
                           addCartimg.src=preLoad[5].src
                           addCartimg.title="Sold";
                        }
                     }
                }                                                
            }            
        }            	
	}
	function CntMenu()
    { 
        alert('This image is copyrighted');        
        return false;
    }
    function functionImageCall()
    {        
		var lginspan;
		lginspan=document.getElementById("spnlgnUser");
		if(lginspan!=undefined)
		{
			var UserLginmsg=AjaxUtilsMethods.CheckUserLoginStatus().value;
			lginspan.innerHTML=UserLginmsg;
		}
		
        var imgBtns;
		var myProdID;
		var img1;
		var sltpages;
		sltpages=document.getElementById("sltPage")
		if(sltpages!=undefined)            
		{
		    if(document.getElementById("hdnPageCnt")!=null)
		    {
			    for(j=0;j < document.getElementById("hdnPageCnt").value;j++)
			    {			 
				    sltpages.options[j]=new Option(j+1)      
			    }
			}
			else
			{
			    if(document.getElementById("trPages") !=null)
		        {
    		    document.getElementById('trPages').style.display = 'none' ;        
		        }
			}
		}
		var sltShowCasepages;
		sltShowCasepages=document.getElementById("sltPageShowCase") 
		
		if(document.getElementById("hdnPageCnt")!=null)
		{
		    if(sltShowCasepages!=undefined)            
		    {    		
			    for(j=0;j < document.getElementById("hdnPageCnt").value;j++)
			    {			 
				    sltShowCasepages.options[j]=new Option(j+1)      
			    }
		    }    
		}
		
		//end
		var tempPids='';
		var tempCatPids='';
		var tempTop16Pids='';
		var ForCatOnly='0';
		for(i=0;i<document.images.length;i++)
		{			    		
		    document.images[i].setAttribute("oncontextmenu", function(){return CntMenu();});	                            			    
		    document.images[i].setAttribute("onContextMenu","return CntMenu();");
			if(document.images[i].name=="imgBtnPrdID")
			{			    
				tempextrasids=document.images[i].id;
				myProdID=document.images[i].id; 				
				tempextrasids = StrReplace(tempextrasids,'imgBtnPrdID','');				
				myProdID=tempextrasids;
				tempPids +=tempextrasids + ",";							
			}
			else if(document.images[i].name=="imgBtnCatPrdID")
			{			    
				tempextrasids=document.images[i].id;
				myProdID=document.images[i].id; 				
				tempextrasids = StrReplace(tempextrasids,'imgBtnCatPrdID','');
				myProdID=tempextrasids;
				tempCatPids +=tempextrasids + ",";	
				ForCatOnly = '1';						
			}	
			else if(document.images[i].name=="imgTop16BtnCatPrdID")
			{					    
				tempextrasids=document.images[i].id;
				myProdID=document.images[i].id; 				
				tempextrasids = StrReplace(tempextrasids,'imgTop16BtnCatPrdID','');
				myProdID=tempextrasids;
				tempTop16Pids +=tempextrasids + ",";	
				ForCatOnly = '2';						
			}				
		}	
		if(tempPids!="" && ForCatOnly == '2')
		{
		    funCheckStatus(tempPids);
		    funCheckTop16PrdStatus(tempTop16Pids);
		}			
		else if(ForCatOnly == '1')
		{		    
		    funCheckCatPrdStatus(tempCatPids);
		}
		else if(ForCatOnly == '2')
		{
		    funCheckTop16PrdStatus(tempTop16Pids);
		}
		else
		{
		    funCheckStatus(tempPids);
		}		
		
		if(sltpages!=undefined)
		{		    
			displayPageOld(0);
		}	
    }	
	function functionPhImg()
	{
		
	}

	addLoadEvent(functionImageCall);
    function windowopen(str)
    {
        window.open(str);
    }
	function functionaddFavoriteProduct(ProdID)
	{	    
		document.forms[0].method="Post";
		document.forms[0].action="frmAddFavorites.ashx?PID=" + ProdID;
		document.forms[0].submit();
    }
    function functionaddManufacturer(ArtID)
	{	    
		document.forms[0].method="Post";
		document.forms[0].action="frmAddFavorites.ashx?AID=" + ArtID;
		document.forms[0].submit();
    }
    function functionCheckCommentProduct(ProdID)
	{	    
		document.forms[0].method="Post";
		document.forms[0].action="frmAddComment.ashx?PID=" + ProdID +"&Chk=1";
		document.forms[0].submit();
    }
    function functionCheckCommentManufProfile(ArtID)
	{	    
		document.forms[0].method="Post";
		document.forms[0].action="frmAddComment.ashx?AID=" + ArtID +"&Type=P&Chk=1";
		document.forms[0].submit();
    }
    function functionCheckCommentManufGallery(ArtID)
	{	    
		document.forms[0].method="Post";
		document.forms[0].action="frmAddComment.ashx?AID=" + ArtID +"&Type=G&Chk=1";
		document.forms[0].submit();
    }
    function functionProductImages()
    {	
        var strImages=AjaxUtilsMethods.BindAllProductDetails().value;
	    if(strImages != "")
	    {
          return strImages;
        }
        else
        { 
          return "";
        }
    }
    function functionSoldProductDetails()
    {	
        var response = AjaxUtilsMethods.BindSoldProductDetails();            
        var dsPrd = response.value;        
        if(dsPrd != null && typeof(dsPrd) == "object" && dsPrd.Tables != null)
        {
            if(dsPrd.Tables[0].Rows.length>0)
            { 
              return dsPrd;
            }
            else
            { 
              return null;
            }
        }
        else
        { 
          return null;
        }
}
 var urlAddress = "http://www.artflute.com/index.shtml";
    var pageName = "ArtFlute.com"; 
    function addBookMark()
    {
         if (window.external)
         {
            window.external.AddFavorite(urlAddress,pageName) 
         }
         else
         {
            alert("Sorry! Your browser doesn't support this function."); 
         }
   } 
   
    function displayPageBold(PageId)
    {	
	    if(document.getElementById('hdnPageCnt')!=null)
	    {
	        var icount=document.getElementById('hdnPageCnt').value;
	        var i=0;		
	        for(i=0; i < icount; i++)
	        {
		        if(PageId==i)
		        {			   
			        document.getElementById('ach' + i).className="BoldPageNo";
		        }
		        else
		        {
			        document.getElementById('ach' + i).className="NormalPageNo";
		        }		    
	        }
    	    
	        if(document.getElementById("sltPageShowCase")!=undefined)
		    {
			    document.getElementById('sltPageShowCase').options[PageId].selected = true;
		    }
		}
		else
		{
		    document.getElementById('trPaging').style.display="none";
		}
		
    } 
     function GetData(PageId,CatId,imgProcess)
     {     
          document.getElementById('siteLoader').style.display = '';
          if(document.getElementById("hdnFileName")!=undefined)
          {                      
              var strPrd = AjaxUtilsMethods.IncludePageContent(document.getElementById("hdnFileName").value ,PageId);                 
              document.getElementById("mainContent").innerHTML = strPrd.value;          
              
              functionImageCall();
              displayPageBold(PageId);
               
              if(imgProcess == 1)
	          {			  
                    var anchors = document.getElementsByTagName("a");
		            var find=0;
		            for (var i=0; i<anchors.length; i++){
			            var anchor = anchors[i];
			            if(anchor.getAttribute('rel')!=undefined)
			            {
				            var relAttribute =(anchor.getAttribute('rel'));							
				            if (anchor.getAttribute('imgpath') && (relAttribute=='lightbox')){
					            find=1;
					            i=anchors.length;
				            }				
			            }
		            }
		            if(find==1)
		            {
			            initLightbox();
		            }
	          }
	      }
	      //setTimeout("LoadingPage()",3000);	      
      }

function OpenHelpWindow()
{   
    window.open('/help.htm','help','scrollbars=yes,left=100px,top=100px,width=800,height=600');     
    return false;
}

function Paging_Prev()
{
    document.getElementById('siteLoader').style.display = '';    
    
    document.getElementById("hdnCurrentPage").value=parseInt(document.getElementById("hdnCurrentPage").value)-1;
    var TotalPages=document.getElementById("hdnPageCnt").value;    
    var CurrentPage=document.getElementById("hdnCurrentPage").value;    
    var loopcount=0;    
    
    //Display Next, Prev
    if(parseInt((parseInt(CurrentPage)*10)+10) >=TotalPages)
    {
        GetData(parseInt(CurrentPage)*10,200812,1)
    
        loopcount=parseInt(TotalPages)-parseInt(((parseInt(CurrentPage)-1)*10)+10);                
        document.getElementById("achNext").style.display="none";  
    }
    else if(parseInt((parseInt(CurrentPage)*10)+10) < TotalPages)
    {
        GetData(parseInt(CurrentPage)*10,200812,1)
    
        loopcount=10;
        document.getElementById("achNext").style.display="";  
    }
    if(parseInt(CurrentPage)!=0)
    {
        document.getElementById("achPrev").style.display="";        
    }    
    else if(parseInt(CurrentPage)==0)
    {
        document.getElementById("achPrev").style.display="none";        
    }   
    //End
    
    //Display Loop ach's
    var concatvar="";
    if(CurrentPage>0)
    {
        concatvar=CurrentPage;
    }    
    for(j=0;j<TotalPages;j++)
    {        
        if(document.getElementById("ach" + j))
        {
            document.getElementById("ach" + j).style.display="none";
        }
    }
    for(i=0;i<loopcount;i++)
    {
        if(document.getElementById("ach" + concatvar + i))
        {
            document.getElementById("ach" + concatvar + i).style.display="";
        }
    } 
    
    //setTimeout("LoadingPage()",3000);
}
function Paging_Next()
{
    document.getElementById('siteLoader').style.display = '';
    
    
    document.getElementById("hdnCurrentPage").value=parseInt(document.getElementById("hdnCurrentPage").value)+1;
    var TotalPages=document.getElementById("hdnPageCnt").value;    
    var CurrentPage=document.getElementById("hdnCurrentPage").value;    
    var loopcount=0;
    
    
    //Display Next, Prev
    if(parseInt((parseInt(CurrentPage)*10)+10) >=TotalPages)
    {
        GetData(parseInt(CurrentPage)*10,200812,1)
    
        loopcount=parseInt(TotalPages)-parseInt(((parseInt(CurrentPage)-1)*10)+10);                
        document.getElementById("achNext").style.display="none";  
    }
    else if(parseInt((parseInt(CurrentPage)*10)+10) < TotalPages)
    {
        GetData(parseInt(CurrentPage)*10,200812,1)
    
        loopcount=10;
        document.getElementById("achNext").style.display="";  
    }
    if(parseInt(CurrentPage)!=0)
    {
        document.getElementById("achPrev").style.display="";        
    }    
    else if(parseInt(CurrentPage)==0)
    {
        document.getElementById("achPrev").style.display="none";        
    }   
    //End
    
    //Display Loop ach's
    var concatvar="";
    if(CurrentPage>0)
    {
        concatvar=CurrentPage;
    }    
    for(j=0;j<TotalPages;j++)
    {        
        if(document.getElementById("ach" + j))
        {
            document.getElementById("ach" + j).style.display="none";
        }
    }
    for(i=0;i<loopcount;i++)
    {
        if(document.getElementById("ach" + concatvar + i))
        {
            document.getElementById("ach" + concatvar + i).style.display="";
        }
    }  
    
    //setTimeout("LoadingPage()",3000);   
}


