﻿var browsertype;
var prodimg ;
var namediv;
function windowload()
{
        //alert(document.getElementById("qm0").offsetWidth);
       // document.getElementById("menutopdiv").style.width = document.getElementById("menuspan").offsetWidth+"px";
        padd = (parseInt(document.body.clientWidth)-document.getElementById("qm0").offsetWidth)/2;
        //alert(padd);
        //document.getElementById("qm0").style.margin ="0px " +(padd-160)+"px " +"0px " +padd+"px "; 
        
        if(document.getElementById("captxttd")!= null)
        {
            document.getElementById("captxttd").style.textAlign  =document.getElementById("hfcontentalign").value;
        }
        
        if(document.getElementById("conttxttd")!= null)
        {
            document.getElementById("conttxttd").style.textAlign  =document.getElementById("hfcontentalign").value;
        }
        if (typeof(pagetype) == 'undefined')
        {
            contenthtml = document.getElementById("content").innerHTML;
            winh = parseInt(document.documentElement.clientHeight) ;
	        doch=parseInt(document.body.clientHeight);
	        //alert("dd");
	        
	        
	        
            //document.getElementById("qm0").style.marginRight=(winw-490-160)/2+"px";
	        
	        if (document.getElementById("leftimg")!= null)
	        {
	            //alert("dd");
	            img = document.getElementById("leftimg").innerHTML ;
	            
	            r1 = getViewableHeight();
	            r2= getViewableWidth();
	            //alert(r1);
	            skewratio =getViewableWidth()/2;
	            img  = img.replace(/width="100"/i,"width=\""+getViewableWidth()/2+"\"");
	            img  = img.replace(/width=100/i,"width=\""+getViewableWidth()/2+"\"");
	            img  = img.replace(/height="100"/i,"height=\""+r1+"\"");
	            img  = img.replace(/height=100/i,"height=\""+r1+"\"");
	            //alert(img);
	            document.getElementById("leftimg").innerHTML = img;
	        }
	      
	        
	        document.getElementById("contentheight").style.height=getViewableHeight()+"px";
	        if (document.getElementById("caprgshadow")!=null)
	            document.getElementById("caprgshadow").className=getClassForPngShadow("imgCapBG");
	    }
	    else if (pagetype== "media")
	    {
	        
	        winh = parseInt(document.documentElement.clientHeight) ;
	        exwidth=(parseInt((getViewableWidth()-20)/200)* 200);
	        margin = (getViewableWidth()-exwidth-20)/2 ;
	        doch = parseInt(document.body.clientHeight);
	         contenthtml = document.getElementById("content").innerHTML;
	        document.getElementById("content").style.width=exwidth-1+"px";
	        
	      
	        
	        //alert (parseInt((getViewableWidth()-20)));
	       if (winh< doch)
	        {
	            document.getElementById("content").style.width=exwidth+20-1+"px";
	            document.getElementById("content").style.height=getViewableHeight()+"px";
	            document.getElementById("content").className="scrollDiv";
	            document.getElementById("content").innerHTML="";
                document.getElementById("content").innerHTML= contenthtml ; 
                
	        }
	        document.getElementById("content").style.marginLeft=margin+"px";
	        document.getElementById("content").style.marginRight=margin+"px";  
	        document.getElementById("contentheight").style.height=getViewableHeight()+"px";
	        //alert(document.getElementById("content").style.width);
	    }
	     else if (pagetype== "mediadetail")
	    {
	        
//	        winh = parseInt(document.documentElement.clientHeight) ;
//	        exwidth=(parseInt((getViewableWidth()-20)/200)* 200);
//	        margin = (getViewableWidth()-exwidth-20)/2 ;
//	        doch = parseInt(document.body.clientHeight);
//	         contenthtml = document.getElementById("content").innerHTML;
//	        document.getElementById("content").style.width=exwidth-1+"px";
//	        
//	      
//	        
//	        //alert (parseInt((getViewableWidth()-20)));
//	       if (winh< doch)
//	        {
//	            document.getElementById("content").style.width=exwidth+20-1+"px";
//	            document.getElementById("content").style.height=getViewableHeight()+"px";
//	            document.getElementById("content").className="scrollDiv";
//	            document.getElementById("content").innerHTML="";
//                document.getElementById("content").innerHTML= contenthtml ; 
//                
//	        }
//	        document.getElementById("content").style.marginLeft=margin+"px";
//	        document.getElementById("content").style.marginRight=margin+"px";  
//	        document.getElementById("contentheight").style.height=getViewableHeight()+"px";
	        //alert(document.getElementById("content").style.width);
	    }
	    else if (pagetype== "product")
	    {
	        //test();
	        //document.images.imgpane.style.display = "none";
	        //pagedivw = document.getElementById("paginationouterdiv").offsetWidth;;
	        //alert(pagedivw);
	        //pageinnerdivw = document.getElementById("paginationinnerdiv1").offsetWidth	        +document.getElementById("paginationinnerdiv2").offsetWidth	        +document.getElementById("paginationinnerdiv3").offsetWidth;
	        id="paginationinnerdiv1"
	        
	        //alert(pageinnerdivw);
	        contenthtml = document.getElementById("content").innerHTML;
            winh = parseInt(document.documentElement.clientHeight) ;
            doch=parseInt(document.body.clientHeight);
            //alert (location.href);
	        vh=getViewableHeight();
	        vw=getViewableWidth();
	        document.getElementById("content").style.height=vh+"px";
	        //alert(document.getElementById("hf_prodtype").value);
	        if (document.getElementById("hf_prodtype").value=="ecl")
	        {
	            document.getElementById("eclprod").style.display="block";
	            
	            
	            //document.getElementById("eclprod").innerHTML=document.getElementById("eclprod").innerHTML +"<br>" +"<br>"+document.getElementById("hf_eclstrip").value +"<br>" +     document.getElementById("hf_eclimg").value +"<br>";
	            //alert(document.getElementById("eclprod").innerHTML);
	            
	            img = document.getElementById("hf_eclimg").value;
	            iid = document.getElementById("hf_prodiid").value;
	           
	            prodimg = new Image() 
		        prodimg.onerror = function()
		        {
		            prodimg.src = "ImageStore/noimage.jpg";
		            document.images.imgpane1.src= "ImageStore/noimage.jpg";
    		        
		        }
		        
	            prodimg.onLoad=eclecticImgLoaded();
		        prodimg.src ="ImageStore/"+iid+"/"+img;
		        //alert(prodimg.src);
		        
		        stripimg =  new Image();
                stripimg.onLoad=eclecticImgLoaded();
                
                stripimg.src =  document.images.imgpane2.src;
                
                
	        }
	        else if (document.getElementById("hf_prodtype").value=="fur")
	        {
	            //alert("Furniture");
	            
	            document.getElementById("eclprod").style.display="block";
	            
	            //document.getElementById("eclprod").innerHTML=document.getElementById("eclprod").innerHTML +"<br>" +"<br>"+document.getElementById("hf_eclstrip").value +"<br>" +     document.getElementById("hf_eclimg").value +"<br>";
	            //alert(document.getElementById("eclprod").innerHTML);
	            
	            img = document.getElementById("hf_eclimg").value;
	            iid = document.getElementById("hf_prodiid").value;
	            
	            
	            
	            prodimg = new Image() 
		        prodimg.onerror = function()
		        {
		            prodimg.src = "ImageStore/noimage.jpg";
		            document.images.imgpane1.src= "ImageStore/noimage.jpg";
    		        
		        }
		        
	            prodimg.onLoad=eclecticImgLoaded();
		        prodimg.src ="ImageStore/"+iid+"/"+img;
		        //alert(prodimg.src);
		        
		        //stripimg =  new Image();
                //stripimg.onLoad=eclecticImgLoaded();
                
                //stripimg.src =  document.images.imgpane2.src;
                document.getElementById("stripimgdiv").style.display="none";
                //document.getElementById("ecthumbsscroll").style.width="50px";
                
                var a  = document.createElement("DIV");
                a.style.padding="50px 0px 0px 0px";
                document.getElementById("ecthumbsscroll").appendChild(a); 
              
                
	        }
	        else
	        {
	            document.getElementById("genprod").style.display="block";
	            document.images.imgpane2.style.display = "none";
	            img = document.getElementById("hf_prodimg").value;
	            iid = document.getElementById("hf_prodiid").value;
	            flash = document.getElementById("hf_flash").value;
	            
		        //alert (contenthtml.indexOf("ptour.swf"));
		        //alert("fid=<%=prodid%>img=<%=prodimg%>");
    		    
		        /* === Flash Image Viewer
		        while (contenthtml.indexOf("xxx.swf")!=-1)
		        {
			        contenthtml=contenthtml.replace(/xxx.swf/i,flash+"uh="+vh+"&uw="+vw+"&fid="+iid+"&img="+img);
		        }
		        document.getElementById("content").innerHTML=contenthtml;
		        === Flash Image Viewer */
		        //document.images.imgpane.style.padding = "50px" +" 0px 0px 0px" ;
    		    
		        prodimg = new Image() ;
		        prodimg.onerror = function()
		        {
		            prodimg.src = "ImageStore/noimage.jpg";
		            document.images.imgpane.src= "ImageStore/noimage.jpg";
    		        
		        }
	            prodimg.onLoad=imgLoaded();
		        prodimg.src ="ImageStore/"+iid+"/"+img;
		        
	        }
	        
		    
	    }
}

function resize_viewport() {
  document.event.remove( this, "resize", resize_viewport);

  // do what you need to do
  document.event.add( this, "resize", reloadPage);
}
function reloadPage()
{
    var sURL = escape(window.location);
    //alert(sURL);
    window.location.href = unescape(sURL);
}
window.onresize = function()
{
   //window.onresize = null;
    //window.onresize = arguments.callee;
    //resize_viewport();
    //$(window).resize(resize_viewport())


    
}
window.onload = function () 
{
        windowload();
}
function imgLoaded()
{
    //alert("Image loaded complete");
    setTimeout ( "resizeImage()", 0 );
    
}
function eclecticImgLoaded()
{
    //alert("Image loaded complete");
    //alert(namediv);
    setTimeout ( "resizeEclecticImage()", 100 );
    
}

function resizeEclecticImage()
{
    
    
    mainh = getViewableHeight();
	mainw = getViewableWidth();
    imgw = prodimg.width ;
    imgh = prodimg.height;
    
    //alert ("PROPERTIES  "+mainw+"  "+imgw+" "+mainh+" "+imgh );
    var r=100;
    var r1=100;
    var r2=100;
    if (imgw > mainw || imgh > mainh) 
    {
        r1 = (mainw / imgw)*100;
        r2 = (mainh / imgh) *100;
        r = r1;
        if (r2<r1) r = r2
        
    }
    makeheight=imgh *r /100-2;
    document.images.imgpane1.width =imgw * r /100;
    document.images.imgpane1.height =makeheight ;
    
    document.images.imgpane2.height = makeheight;
    topmargin = (mainh-imgh)/2;
    
    
    
    if(topmargin<0) 
    topmargin =0;
    
    document.images.imgpane1.style.padding = topmargin +"px" +" 0px 0px 0px" ;
    document.images.imgpane2.style.padding = topmargin +"px" +" 0px 0px 0px" ;
    //margin for eclsthumbs
    document.getElementById("ecthumbs").style.padding=topmargin +"px" +" 0px 0px 0px" ;
    
    
    document.getElementById("ecthumbsscroll").style.height= makeheight+"px";
    
    //alert(document.getElementById("ecthumbsscroll").offsetHeight+"--"+ makeheight);
    if (document.getElementById("ecthumbsscroll").offsetHeight>= makeheight)
    {
        document.getElementById("ecthumbsscroll").className="scrollDiv";
    }
    else
        document.getElementById("ecthumbsscroll").className="";
   
    if (imgh <= imgh *r /100)
    {
        //alert("s");
        
    }
    //document.getElementById('falsegifdiv').style.width=mainw+"px";
    //document.getElementById('falsegifdiv').style.height=mainh+"px";
    //alert(document.images.imgpane.height );
    //document.getElementById('falsegifdivec').style.width=imgw * r /100+50+"px";
    
    
    document.getElementById('falsegifdivec').style.height=mainh+"px";
    document.images.imgpane1.style.display = "block";
    document.images.loader1.style.display = "none";
    document.getElementById("ecthumbsscroll").style.display = "block";
    document.getElementById("stripimg").style.display = "block";
    
    
    thumbpnw = document.getElementById('ecthumbs').offsetWidth;
    document.getElementById('falsegifdivec').style.width=(mainw-thumbpnw)+"px";
    
    
}
function resizeStripImage()
{
    //alert(document.images.imgpane2.width);
}

function resizeImage()
{
    mainh = getViewableHeight();
	mainw = getViewableWidth();
    imgw = prodimg.width ;
    imgh = prodimg.height;
    //alert ("PROPERTIES  "+mainw+"  "+imgw+" "+mainh+" "+imgh );
    var r=100;
    var r1=100;
    var r2=100;
    if (imgw > mainw || imgh > mainh) 
    {
        r1 = (mainw / imgw)*100;
        r2 = (mainh / imgh) *100;
        r = r1;
        if (r2<r1) r = r2
        
    }
   
    //document.images.imgpane.src = document.images.imgpane.src;
    document.images.imgpane.width =imgw * r /100;
    //alert(r+ "aaasss"+document.images.imgpane.width);
    document.images.imgpane.height = imgh *r /100;
    topmargin = (mainh-imgh)/2;
    //alert(topmargin);
    
    if(topmargin<0) 
    topmargin =0;
    document.images.imgpane.style.padding = topmargin +"px" +" 0px 0px 0px" ;
    document.getElementById('falsegifdiv').style.width=mainw+"px";
    document.getElementById('falsegifdiv').style.height=mainh+"px";
    //alert(document.images.imgpane.height );
    document.images.imgpane.style.display = "block";
    document.images.loader.style.display = "none";
    
}

function testFlash() 
{
    var MM_contentVersion = 6;
    var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
    if ( plugin ) {
    var words = navigator.plugins["Shockwave Flash"].description.split(" ");
    for (var i = 0; i < words.length; ++i)
    {
        if (isNaN(parseInt(words[i])))
        continue;
        var MM_PluginVersion = words[i];
    }
    var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
    }
    else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") != -1)) 
    {
        document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
        document.write('on error resume next \n');
        document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFla sh." & MM_contentVersion)))\n');
        document.write('</SCR' + 'IPT\> \n');
    }
    if ( MM_FlashCanPlay ) 
    {
        //document.getElementById("hasflash").style.backgrou ndColor="yellow";
        alert("flash yes");
        return true;
    } 
    else
    {
        //document.getElementById("noflash").style.backgroun dColor="yellow";
        //alert("flash no");
        return false;
    }
}
function getClassForPngShadow(classname)
{
    //alert(browsertype);
    if (browsertype=="Explorer")
    {
    classname = classname+"IE";
 
    }
    return classname;
}

function getViewableHeight()
{
	var y =0;
	var top=232;
	//alert("aasd");
    if (typeof(overrideh) != 'undefined')
    top = top+overrideh;
	if (self.innerHeight)
	{
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		y = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		y = document.body.clientHeight;
	}
	
	return y-top;
}

function getViewableWidth()
{
	var y =0;
	var top=0;
	if (self.innerWidth)
	{
		y = self.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		y = document.documentElement.clientWidth;
	}
	else if (document.body)
	{
		y = document.body.clientWidtht;
	}
	
	return y-top;
}



var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
browsertype=BrowserDetect.browser;

function popup(url) 
{
 var width  = 700;
 var height = 550;
 var left   = (screen.width  - width)/2;
 var top    = (screen.height - height)/2;
 var params = 'width='+width+', height='+height;
 params += ', top='+top+', left='+left;
 params += ', directories=yes';
 params += ', location=yes';
 params += ', menubar=yes';
 params += ', resizable=yes';
 params += ', scrollbars=yes';
 params += ', status=yes';
 params += ', toolbar=yes';
 newwin=window.open(url,'windowname5', params);
 if (window.focus) {newwin.focus()}
 return false;
}

function showtooltip()
{
    document.getElementById("sstooltip").style.display="block";
}

function hidetooltip()
{
    document.getElementById("sstooltip").style.display="none";
}