timeout = 10;
closeTimer = 0;

//Top and Left Co-ordinates for Wine Press Legend pop-up.
var X = 0;
var Y = 0;

function closeMenu(){
	document.getElementById('WineOtherPopup').style.display='none';
	
	// added by Ayan On January 10th for current sale
	document.getElementById('PromotionCurrentSalePopup').style.display='none';
	
	//added by Ayan on March 15th
	document.getElementById('OtherSpiritsPopup').style.display='none';
	
}
function closeScotchMenu(){
	document.getElementById('WineScotchPopup').style.display='none';
}
function closeScotchMenuTime(){
	closeTimer = window.setTimeout(closeScotchMenu,timeout);
}

function closeWhiskeyMenu(){
	document.getElementById('WineSWhiskeyPopup').style.display='none';
}  

// added by Ayan on March 10th to add Cocktail sub-menu
function closeOtherSpiritsMenu(){
	document.getElementById('OtherSpiritsPopup').style.display='none';
} 
// end of addition

function closeWhiskeyMenuTime()
{
	closeTimer = window.setTimeout(closeWhiskeyMenu,timeout);
}

// added by Ayan on March 10th to add Cocktail sub-menu
function closeOtherSpiritsMenuTime()
{
	closeTimer = window.setTimeout(closeOtherSpiritsMenu,timeout);
}
// end of addition

function closeonlineMenu(){
	document.getElementById('WineonlinePopupONS').style.display='none';
}  

function closeonlineMenuTime()
{
	closeTimer = window.setTimeout(closeonlineMenu,timeout);
}

function closePromotionMenu(){
	document.getElementById('idPromotionSales').style.display='none';
}  

function closePromotionMenuTime()
{
	closeTimer = window.setTimeout(closePromotionMenu,timeout);
}


function closeeventsMenu(){
	document.getElementById('WineeventsPopup').style.display='none';
}  

function closeeventsMenuTime()
{
	closeTimer = window.setTimeout(closeeventsMenu,timeout);
}
function closeMenuTime(){
	closeTimer = window.setTimeout(closeMenu,timeout);
}
function cancelMenuHide(){
	if(closeTimer){
		window.clearTimeout(closeTimer);
		closeTimer = null;
	}
}



function showPopup(id){
//  document.getElementById(id).setAttribute("class", id + "_over");
  document.getElementById(id).className= id + "_over";
  document.getElementById(id + "DD").style.display="block";
}

function hidePopup(id){
// document.getElementById(id).setAttribute("class", id + "_normal");
 document.getElementById(id).className= id + "_normal";
 document.getElementById(id + "DD").style.display="none";
}
function hidePopupSpirits(id){
// document.getElementById(id).setAttribute("class", id + "_normal");
 document.getElementById(id).className= id + "_normal";
 document.getElementById(id + "DD").style.display="none";
}
function hidePopupWine(id){
// document.getElementById(id).setAttribute("class", id + "_normal");
 document.getElementById(id).className= id + "_normal";
 document.getElementById(id + "DD").style.display="none";
	
}

/*function showSubLinks(idMain, displayLinks) {
  document.getElementById(idMain).className="menuContainer_over";
  document.getElementById(idMain + "Left").className="menuLeft_over";
  document.getElementById(idMain + "Middle").src="images/"+idMain+"_over.jpg";
  document.getElementById(idMain + "Right").className="menuRight_over";
  document.getElementById("menuLowerContainer").style.display="block";
  document.getElementById(displayLinks).style.display="block";
}

function hideSubLinks(idMain, displayLinks) {
  document.getElementById(idMain).className="menuContainer_normal";
  document.getElementById(idMain + "Left").className="menuLeft_normal";
  document.getElementById(idMain + "Middle").src="images/"+idMain+"_normal.jpg";
  document.getElementById(idMain + "Right").className="menuRight_normal";
  document.getElementById("menuLowerContainer").style.display="none";
  document.getElementById(displayLinks).style.display="none";
}*/
function showSubLinks(idMain, displayLinks) {
  hideAllLinks();

  document.getElementById(idMain).className="menuContainer_over";
  document.getElementById(idMain + "Left").className="menuLeft_over";
  document.getElementById(idMain + "Middle").src="/wcsstore/WineandSpirits/en_US/images/"+idMain+"_over.jpg";
  document.getElementById(idMain + "Right").className="menuRight_over";
  document.getElementById("menuLowerContainer").style.display="block";
  document.getElementById(displayLinks).style.display="block";
}

function hideSubLinks(idMain, displayLinks) {
  document.getElementById(idMain).className="menuContainer_normal";
  document.getElementById(idMain + "Left").className="menuLeft_normal";
  document.getElementById(idMain + "Middle").src="/wcsstore/WineandSpirits/en_US/images/"+idMain+"_normal.jpg";
  document.getElementById(idMain + "Right").className="menuRight_normal";
  if(document.getElementById("menuLowerContainer") != null)
  	document.getElementById("menuLowerContainer").style.display="none";
  document.getElementById(displayLinks).style.display="none";

  //closeWhiskeyMenuTime();
  //closeonlineMenuTime();
  //closeeventsMenuTime();
}

function hideAllLinks(){
	hideSubLinks('wine', 'wineLink');
	hideSubLinks('spirits', 'spiritLink');
	hideSubLinks('promotions', 'promotionsLink');
	hideSubLinks('wineClub', 'wineClubLink');
	hideSubLinks('learn', 'learnLink');
	hideSubLinks('entertain', 'entertainLink');
	hideSubLinks('gifts', 'giftsLink');
}

function hideAllTertiaryMenus() {
    closeWhiskeyMenu();
    closeonlineMenu();
    closeeventsMenu();
}

/*Start of Menu Navigation functions (Designer2)*/
function hideItems(){
	a=hideItems.arguments;
	for(i=0; i<a.length; i++)
	{
	    if(document.getElementById(''+a[i]) != null){
	        document.getElementById(''+a[i]).style.display="none";
	    }
	}
}
function showItems(){
	a=showItems.arguments; 
	for(i=0; i<a.length; i++)
	{
		if(document.getElementById(""+a[i]) != null){
   	    	document.getElementById(""+a[i]).style.display="block";
    	}
   }
}

/*End of Menu Navigation functions (Designer2)*/

function showPopupBlock(popup){
        popupWindow = document.getElementById(popup);
        pageHeight= document.body.clientHeight;
        pageWidth = document.body.clientWidth;
        popupWindow.style.left = eval(pageWidth-1117+185)+'px';
        popupWindow.style.top = '450px';
        popupWindow.style.display='block';
}


/*Classes for EmailPopup Handling (15Oct2009, NTV)*/
function closePopupBlock(popup){
        popupWindow = document.getElementById(popup);
       
        popupWindow.style.display='none';
}
function showEmailPopup(popup){
        popupWindow = document.getElementById(popup);
        pageHeight= document.body.clientHeight;
        pageWidth = document.body.clientWidth;
       
        popupWindow.style.left = eval(pageWidth/2-200-popupWindow.offsetWidth)+'px';
        popupWindow.style.display='block';
}

function showPopupWin(popup){
        popupWindow = document.getElementById(popup);
        pageHeight= document.body.clientHeight;
        pageWidth = document.body.clientWidth;
        popupWindow.style.display='block';
}

function onPressEnterKey(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if (keycode == 13)
	{
		myfield.form.submit();
		return false;
	}else return true;
}

/**
This function displays the WinePress Legend Popup.
**/
function showWinePressLegendPopup(popup){
 	popupWindow = document.getElementById(popup);
	pageHeight= document.body.clientHeight;
	pageWidth = document.body.clientWidth;	

	if(getBrowserName() != 'IE'){
		document.captureEvents(Event.MOUSEMOVE);
	}
	
	document.onmousemove = getPosition;
	if(Y != 0){
		popupWindow.style.top = (Y < 248) ? '238px' : (Y-10)+'px';
		
	}
	if(X != 0){
		popupWindow.style.left = X-500+'px';
	}
	//popupWindow.style.left = eval(pageWidth/2-200-X)+'px';
	popupWindow.style.display='block';
}

function getPosition(args)
{
  // Gets IE browser position
 if(getBrowserName() == 'IE')
  {
    //X = event.clientX + document.body.scrollLeft;
    //Y = event.clientY + document.body.scrollTop;
    
    //X = event.clientX + event.offsetX;
    //Y = event.clientY + event.offsetY;
    
    X = 550;
    Y = 272;
    
  }
  // Gets position for other browsers
  else
  {
    X = args.pageX;
    Y = args.pageY;
  }
}

/*The following function identifies the user Browser*/


function getBrowserDetails(){

var browserDetails = '';

if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
 var ffversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (ffversion>=3)
  //document.write("You're using FF 3.x or above");
 browserDetails = 'FF-3.x';
 else if (ffversion>=2)
  //document.write("You're using FF 2.x");
 browserDetails = 'FF-2.x';
 else if (ffversion>=1)
  //document.write("You're using FF 1.x")
  browserDetails = 'FF-1.x';
}
else 
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (ieversion>=8)
  //document.write("You're using IE8 or above");
  browserDetails = 'IE-8.x';
 else if (ieversion>=7)
  //document.write("You're using IE7.x");
  browserDetails = 'IE-7.x';
 else if (ieversion>=6)
  //document.write("You're using IE6.x");
  browserDetails = 'IE-6.x';
 else if (ieversion>=5)
  //document.write("You're using IE5.x");
  browserDetails = 'IE-5.x';
}
else

//Note: userAgent in Opera9.24 WinXP returns: Opera/9.24 (Windows NT 5.1; U; en)
//         userAgent in Opera 8.5 (identified as IE) returns: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Opera 8.50 [en]
//         userAgent in Opera 8.5 (identified as Opera) returns: Opera/8.50 (Windows NT 5.1; U) [en]

if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Opera/x.x or Opera x.x (ignoring remaining decimal places);
 var oprversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (oprversion>=10)
  //document.write("You're using Opera 10.x or above");
 browserDetails = 'Op-10.x';
 else if (oprversion>=9)
  //document.write("You're using Opera 9.x");
 browserDetails = 'Op-9.x';
 else if (oprversion>=8)
  //document.write("You're using Opera 8.x");
 browserDetails = 'Op-8.x';
 else if (oprversion>=7)
  //document.write("You're using Opera 7.x");
 browserDetails = 'Op-7.x';
 }
 
 return browserDetails;
}

function getBrowserName(){
	var browserDetails = '';
	var browserName = '';
	
	browserDetails = getBrowserDetails();

	if(browserDetails != ''){
		browserName = browserDetails.split('-')[0];		
	}

	return browserName;
}

function getBrowserVersion(){
	var browserDetails = '';
	var browserVersion = 0;

	browserDetails = getBrowserDetails();

	if(browserDetails != ''){
		browserVersion = new Number(browserDetails.split('-')[1].substring(0, 1));
	}
	return browserVersion;
}



/*End of classes for EmailPopup Handling*/


/*Start: methods for managing maxLength of textbox*/

function manageMaxLength(objectId, maxLengthValue){
	var obj = document.getElementById(objectId);

	if(obj != null){
		if(!isNaN(parseInt(maxLengthValue))){		
			obj.maxLength = parseInt(maxLengthValue);
		}else{
			//alert('maxLength parameter is not a valid length!');
		}
	}else{
		//alert('object does not exists!');
	}
}

/*End: methods for managing maxLength of textbox*/

function resetValue(objectId){
	var obj = document.getElementById(objectId);
	if(obj != null){
		obj.value = "";
	}
}

function manageObjectDisplay(strObjId, displayProperty){
	var obj = document.getElementById(strObjId);
	if(obj != null){
		obj.style.display = displayProperty;
	}
}

//Added email validation for issue CSD000000231027
function validateEmail(emailId) {
	var str=null;
	if (emailId==null || emailId=='null' || emailId.length == 0) {
		str ="E-mail address can not be blank\n";
	} else {
		var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;   
		var isValid = emailPattern.test(emailId);
		// alert(isValid);
		if(!isValid) {
			str = "Please enter a valid e-mail address. E-mail addresses must contain '.' and '@' sign along with characters preceding and following it."
		}
	}
	// alert(str);
	return str;
}


