// JavaScript Document

var y1 = 10;   //change the # on the left to adjust the Y co-ordinate
(document.getElementById) ? dom = true : dom = false;

var callout = 0;

//Error Handler for common/events.php
onerror=handleErr
function handleErr(msg,url,l)
{
	txt ="RunTime Error!\n\n";
	txt+="Error: " + msg + "\n";
	txt+="URL: " + url + "\n";
	txt+="Line: " + l + "\n";
	txt+="Click OK to continue.\n\n";
	alert(txt); return true;
}

function bestview()
{
	dir = "../../images/browser";
	
	document.write ("<div class='bestview'><table width='145'>"+		
	"<tr><td colspan='5' class='bestview2' valign='top' align='left'>Best viewed under:</td></tr><tr>"+
	"<td width='31'><img src='"+ dir +"/compatible_ie.jpg' alt='IE'/></td>"+
	"<td width='31'><img src='"+ dir +"/compatible_firefox.gif' alt='Firefox' width='31' height='30' size='50%' /></td>"+
	"<td width='28'><img src='"+ dir +"/compatible_safari.gif' alt='Safari' width='28' height='30' /></td>"+
	"<td width='32'><img src='"+ dir +"/compatible_opera.gif' alt='Opera' /></td>"+
	"<td width='10'><img src='"+ dir +"/compatible_chrome.gif' alt='Chrome' width='31' height='30' /></td>"+
	"</tr><tr>"+
	"<td class='bestview' align='center'><!--IE//-->ver. 7</td>"+
	"<td class='bestview' align='center'><!--FF//-->ver. 3</td>"+
	"<td class='bestview' align='center'><!--Saf//-->ver. 4</td>"+
	"<td class='bestview' align='center'><!--Op//-->ver. 9</td>"+
	"<td class='bestview' align='center'><!--Ch//-->ver. 3</td>"+
	"</tr></table></div>");
}

function goto(section){
	//window.location.href='http://www.thewinegallery.com.sg/'+section; /* old ver*/
	
	//alert(location.protocol); //http
	//alert(location.hostname); //localhost or www
	host = location.pathname.split("/");
	host = host[1];
	//alert(host);
	if(location.hostname == "localhost") url = "localhost/" + host
	else url = "www.thewinegallery.com.sg";
	
	var myDomain = location.protocol + '//' + url + "/" + section;
	//alert(myDomain);				
	window.location.href= myDomain;
}

//Tasting Events
var reloadP = 0;
function LoadCurrentEvent(d, h) {	
	if(d == undefined || d == "") d = DateOfTasting;	
	yr = d.substring(0,4);

	//alert("LoadCurrentEvent");
	document.write("<div align='center' id='tasting' name='tasting'><iframe id='t' name='t' src='../pastwine/"+yr+"/"+d+".htm' width='700' height='0' frameborder='0' onload='setHt(this);' scrolling='no'></iframe></div><br/><div id='load' style='visibility:visible' align='center'><font class='loadtasting'><b>Loading Contents..<br/>Hit F5 to refresh the page again if you can't view properly.</b></font></div>");
		
}

//detect browser script
function myBrowser(obj) {
	if(document.getElementById) { return document.getElementById(obj); } //Firefox
	else { return document.all[obj]; } //IE
}

//UPCOMING/INDEX AUTO HT ADJUSTMENT
temp = 0; 
function setHt(obj) {
	//contentHt = obj.contentWindow.htt; alert("contentHt =" + contentHt);
	//document.getElementById('t').height = contentHt;
	//top.frames['t'].location.href = top.frames['t'].location;
	//alert(top.frames['t'].window.htt);
	
	if(reloadP == 0)
	{ 
		if(temp==0) { temp=top.frames['t'].window.htt; }
		
		top.frames['t'].location.reload();  reloadP = 1;
	}
	if (reloadP == 1)
	{		
		browserType = clientbrowser();
		//alert(browserType); //show browser type
		switch (browserType){
			default:
			setTimeout("myBrowser('t').height=top.frames['t'].window.htt; myBrowser('load').style.visibility='hidden';", 1500);
			break; //IE, FF, Opera, Safari, Chrome
		}
	}	
}

function clientbrowser() //browser detection
{
	//affiliate: common/wadbrowser.js
	if(browser.isChrome) return "chrome";
	if(browser.isSafari) return "safari";
	if(browser.isIE) return "ie";
	if(browser.isFirefox) return "firefox";
	if(browser.isOpera) return "opera";	
	//do a test @ http://dithered.chadlindstrom.ca/javascript/browser_detect/example.html
}

function alertSize() {
  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;
  }
  //window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );
}

//htm pgs:gallery,tasting_index.php,bestbuy,itm
function placeIt_v2(close_btn_id) {
	//alert(close_btn_id)	
	if (dom && !document.all) //firefox
  	{			
  		document.getElementById(close_btn_id).style.top = 
		window.pageYOffset + (window.innerHeight - (window.innerHeight-y1)) + "px"; 
	}
  	if (document.all) //IE
	{
		cal = document.documentElement.scrollTop+(document.documentElement.clientHeight-
												  (document.documentElement.clientHeight-y1));
		
		document.all[close_btn_id].style.top = cal+"px";
	}
  	window.setTimeout("placeIt_v2('"+close_btn_id+"');", 10); 
}

function resize(obj)
{
	self.moveTo(0,0);
	
	if(obj=="eventIndex")
	{	
		if(document.width!='713'){
			self.resizeTo([screen.availWidth], [screen.availHeight]);
			self.resizeTo([screen.availWidth], [screen.availHeight]);
		}
	}
		
	if (dom && !document.all) //firefox
  	{
		//alert(document.getElementById('t'))
		if( document.getElementById('t') == null ) //dont have iframe
		{
			self.moveTo(0,0);
		    //alert("resize()")
			if(document.width!='713'){
				self.resizeTo([screen.availWidth], [screen.availHeight]);
				self.resizeTo([screen.availWidth], [screen.availHeight]);
			}
			//reloadchild();
		}
	}
	if (document.all) //IE
	{
		if( parent.document.getElementById("tasting") == undefined ) //dont have iframe
		{
			self.moveTo(0,0);
		    //alert("resize()")
			if(document.width!='713'){
				self.resizeTo([screen.availWidth], [screen.availHeight]);
				self.resizeTo([screen.availWidth], [screen.availHeight]);
			}
			//reloadchild();
		}
	}
}

function reloadchild()
{
	//alert('selfclose.js: reloadchild()')
	if (dom && !document.all) //firefox
	{
		top.frames['t'].location.reload();
		setTimeout("document.getElementById('t').height = top.frames['t'].window.htt; 	document.getElementById('load').style.visibility='hidden'; ",2000);
	}
	
	if (document.all) //IE
	{
		top.frames['t'].location.reload();
		setTimeout("document.all['t'].height = top.frames['t'].window.htt; document.all['load'].style.visibility='hidden'; ",2000);
	}
	//alert(top.frames['t'].location)
	/*if (dom && !document.all)  //firefox
	{
		document.getElementById('t').src = document.getElementById('t').src;
		//alert(top.frames['t'].location); alert("FF")	
		//alert(document.frame);
		//document.getElementById('t').height = document.getElementById('t').innerHeight;
	}
  	if (document.all) 
	{
		document.all["t"].src = document.all["t"].src;
		top.frames['t'].location.reload();
		alert("IE")
		//alert(document.getElementById('t').documentElement.clientHeight);
	} */
}

//TWG INDEX PG
function main(){	
	var twg_win=document.open('welcome.htm','twg','toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=yes,copyhistory=0,fullscreen=0,resizable=0');
}

//INCLUDE PG SCRIPT: new prototype defintion
document.include = function (url) {
 	if ('undefined' == typeof(url)) return false;
 
 	var p,rnd;
 	if (document.all){ p = new ActiveXObject("Microsoft.XMLHTTP"); } // For IE, create an ActiveX Object instance 
 	else { p = new XMLHttpRequest(); } 								 // For mozilla, create an instance of XMLHttpRequest.

 	// Prevent browsers from caching the included page
 	// by appending a random number
 	rnd = Math.random().toString().substring(2);
 	url = url.indexOf('?')>-1 ? url+'&rnd='+rnd : url+'?rnd='+rnd;
 	// Open the url and write out the response
 	p.open("GET",url,false);
 	p.send(null);
 	document.write( p.responseText );
}

//GOOGLE ANALYTICS
function googleanalytic()
{	
	document.write ("<a href=\"http://www.addthis.com/bookmark.php?v=250&pub=thewinegallery\" onmouseover=\"return addthis_open(this, '', '[URL]', '[TITLE]')\" onmouseout=\"addthis_close()\" onclick=\"return addthis_sendto()\"><img src=\"http://s7.addthis.com/static/btn/lg-share-en.gif\" width=\"125\" height=\"16\" alt=\"Bookmark and Share\" style=\"border:0\"/></a>");
	
}

//RIGHT CLICK SCRIPT
var lastclick = "";
var message="The Wine Gallery by Magnum Spirits & Wine";

function clickIE4(){
	if (event.button==2){ alert(message); return false; }
}
function clickNS4(e){
	if (document.layers||document.getElementById&&!document.all){
	if (e.which==2||e.which==3){ alert(message); return false; }
	}
}
if (document.layers){
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
	document.onmousedown=clickIE4;
}
document.oncontextmenu=new Function("alert(message);return false")