function init_dw_Scroll() {
    var wndo = new dw_scrollObj('wn', 'lyr1');
    wndo.setUpScrollbar("dragBar", "track", "v", 1, 1,0);
    wndo.setUpScrollControls('scrollbar');
	
	var wndo2 = new dw_scrollObj('wn2', 'lyr2');
    wndo2.setUpScrollbar("dragBar2", "track2", "v", 1, 1,0);
    wndo2.setUpScrollControls('scrollbar2');
	
	var wndo3 = new dw_scrollObj('wn3', 'lyr3');
    wndo3.setUpScrollbar("dragBar3", "track3", "v", 1, 1,0);
    wndo3.setUpScrollControls('scrollbar3');
}

// if code supported, link in the style sheet and call the init function onload
if ( dw_scrollObj.isSupported() ) {
    dw_writeStyleSheet('/images/dailydeals2_1/css/scrollbar.css')
    dw_Event.add( window, 'load', init_dw_Scroll);
}


//  script for thumbnail rollover effect in hero product

var cur = "thumb1";
var prev = "thumb1";

function activateBG(obj,url)
{
	cur = obj;
	if( cur != prev)
	{
		document.getElementById(cur).className = "thumb_active";
		document.getElementById(prev).className = "thumb";
		document.getElementById('heroImage').src = url;
		prev = cur;
	}
}

//  script to activate and deactive What's Deal hidden area

var activID = null;
var prevID = null;

function showWD()
{
	/* Flash Tag logic/code for the What's the Deal button */
	var d = new Date();
	var t = new Image();
	t.src = "http://vs.target.com/flashtag.txt?site=daily_deals&pagename=whats_the_deal&cachedefeat="+d.getTime(); 
	/********************************/
	
	document.getElementById('wdContainer').className='wdContainer';
	setTimeout(WDactive,500);
	FLWnormal();
	//document.getElementById('watsdeal').style.zIndex=-1;
	//document.getElementById(activID).className = "for_screenreaders";
	if (activID != null)
		document.getElementById(activID).className = "for_screenreaders";
	
}
function hideWD()
{
	document.getElementById('wdContainer').className='for_screenreaders';
	//document.getElementById('watsdeal').style.zIndex=1;
	prevID = null;
	WDnormal();
}
function WDactive()
{
	document.getElementById('hc_whatsDeal').className = 'wd_active';
}
function WDnormal()
{
	document.getElementById('hc_whatsDeal').className = 'wd_normal';
}


//function to show share and follow popup menus//

function showLyr(id)
{
	if(id != "sharePOPUP_window")
	{
		document.getElementById(id).className = "follow_popup";
		document.getElementById('sharePOPUP_window').className = "for_screenreaders";
		FLWactive();
		SWnormal();
	}
	else
	{
		document.getElementById(id).className = "share_popup";
		document.getElementById('followPOPUP_window').className = "for_screenreaders";
		SWactive();
		FLWnormal();
	}
}
function FLWactive()
{
	document.getElementById('hc_follow').className = 'follow_active';
}
function FLWnormal()
{
	document.getElementById('hc_follow').className = 'follow_normal';
}
function SWactive()
{
	document.getElementById('hc_share').className = 'share_active';
}
function SWnormal()
{
	document.getElementById('hc_share').className = 'share_normal';
}


var prevLayer = null;
function showLayer(id)
{
	if(prevLayer == null)
	{
		document.getElementById(id).className = "bgContainer"
	}
	else if(prevLayer != id)
	{
		document.getElementById(prevLayer).className = "for_screenreaders";
		document.getElementById(id).className = "bgContainer"
	}
	prevLayer = id;
}

/***** SCRIPT FOR FADE-IN EFFECT STARTS HERE *****/

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 
function shiftOpacity(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
        opacity(id, 0, 100, millisec);
    } else {
        opacity(id, 0, 100, millisec);
    }
	document.getElementById('wdContainer').className='for_screenreaders';
	document.getElementById('hfeDone').className='for_screenreaders';
	showDiv(id,activID);
} 
/***** SCRIPT FOR FADE-IN EFFECT ENDS HERE *****/

// generalized function for showing the follow and share sub layers
function showDiv(id1,id2)
{
	prevID = null;
	if(id2 != null)
		document.getElementById(id2).className='for_screenreaders';
	if(id1 != null)
	{
		document.getElementById(id1).className='bgContainer';
		activID = id1;
	}
	if(id1 == "hfSMS")
	{
		document.getElementById('smsTC').className='for_screenreaders';
		document.getElementById('smsFAQ').className='for_screenreaders';
		document.getElementById('hfSmsRight').className='';
		document.getElementById('hfSMS').style.background = '#fff url(/images/dailydeals2_1/images/signup_sms_bg.gif)';
		document.getElementById('smsFirstName').value = "";
		document.getElementById('smsLastName').value = "";
		document.mobSubmit.phone_1st3digits.value = "";
		document.mobSubmit.phone_2nd3digits.value = "";
		document.mobSubmit.phone_last4digits.value = "";
		document.mobSubmit.selCarrier.selectedIndex = 0 ;
		document.mobSubmit.local_time_zone.selectedIndex = 0 ;
		document.mobSubmit.hour_of_day.selectedIndex = 0 ;
		document.getElementById('hfSMSAge').checked = false;
		document.getElementById('hfsErr').innerHTML = "";
		document.getElementById('smsFirstName').className = "";
		document.getElementById('smsLastName').className = "";
		document.mobSubmit.phone_1st3digits.className = "";
		document.mobSubmit.phone_2nd3digits.className = "";
		document.mobSubmit.phone_last4digits.className = "";
		document.getElementById('hfSMSAge').className = "";
		document.mobSubmit.selCarrier.className = "";
		document.mobSubmit.local_time_zone.className = "";
		document.mobSubmit.hour_of_day.className = "";
	}
	WDnormal();
	hideLayer('followPOPUP_window');
	setTimeout(FLWactive,100);
}

function openFAQ(id)
{
	document.getElementById('hfSmsRight').className='for_screenreaders';
	document.getElementById(id).className='smsFAQ';
	document.getElementById('hfSMS').style.background = '#fff';
}
function hideLayer(id)
{
	document.getElementById(id).className='for_screenreaders';
	SWnormal();
	FLWnormal();
}


function validateEmail()
{
	var email = document.subscriptionForm.Email.value;
	var emailc = document.subscriptionForm.VerifyEmail.value;
	var mail = false;
	var mailCont = false;
	var age = false;
	if(email == "" || emailc == "")
	{
		document.getElementById('hfErNotxt').className='hfeRqd';
		document.subscriptionForm.Email.className='hfEmail';
		document.subscriptionForm.VerifyEmail.className='hfEmail';
		mail = false;
	}
	else 
	{
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		if(reg.test(email) == false) 
		{
		  	document.getElementById('hfErNotxt').className='hfeRqd';
			document.getElementById('hfErNotxt').innerHTML='Please enter a valid e-mail address';
			document.subscriptionForm.Email.className='hfEmail';
			document.subscriptionForm.VerifyEmail.className='hfEmail';
			mail = false;
	    }
		else
		{
			document.getElementById('hfErNotxt').className='for_screenreaders';
			document.subscriptionForm.Email.className='';
			document.subscriptionForm.VerifyEmail.className='';
			mail = true;
		}
	}
	var em1 = email.toLowerCase();
	var em2 = emailc.toLowerCase();
	if (em1 != em2)
	{
		document.getElementById('hfErEamil').className='hfeRqd';
		document.subscriptionForm.Email.className='hfEmail';
		document.subscriptionForm.VerifyEmail.className='hfEmail';
		document.getElementById('hfErNotxt').className='for_screenreaders';
		mailCont = false;
	}
	else 
	{
		document.getElementById('hfErEamil').className='for_screenreaders';
		mailCont = true;
	}
	var ob = this.document.subscriptionForm;
	for(var i=0; i<ob.moreThan13.length; i++)
	{
		if(ob.moreThan13[i].checked)
		{
			var chkValue = ob.moreThan13[i].value;
		}
	}
	if (chkValue == "false")
	{
		document.getElementById('hfErAge').className='hfeRqd';
		document.subscriptionForm.moreThan13.className='hfEmail';
		age = false;
	}
	else
	{
		document.getElementById('hfErAge').className='for_screenreaders';
		document.subscriptionForm.moreThan13.className='';
		age = true;
	}
	/*if(document.subscriptionForm.moreThan13.checked == false)
	{
		document.getElementById('hfErAge').className='hfeRqd';
		document.subscriptionForm.moreThan13.className='hfEmail';
		age = false;
	}
	else
	{
		document.getElementById('hfErAge').className='for_screenreaders';
		document.subscriptionForm.moreThan13.className='';
		age = true;
	}*/
	if(mail == true && mailCont == true && age == true)
		emailSubmit();
	else
		return false;
}
/////////////////	AJAX Function to submit email and get the response	////////////////////////////////////
function emailSubmit()
{
var url = "http://sites.target.com/site/en/spot/newsletter_receiver.jsp" ;
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();  // creating an object for firefox and other
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP"); // creating an object for IE
}
req.open("GET", url, true);
req.onreadystatechange = updatePage1; 
req.send(null); 
}

function updatePage1(){

	 if (req.readyState == 4) {
	
    document.getElementById('hfeSignup').className='for_screenreaders';
	
	//shiftOpacity('hfeDone', 500);
	
   
	 }
}

///////////////////////////////////
function getURLParameters() 
{
	/*var browser = BrowserDetect.browser;
	if (browser == "Safari")
	{
		document.getElementById('hfeSignup').style.marginTop = '-910px';
		document.getElementById('smsTC').style.margin = '5px 0px 0px -46px';
		document.getElementById('smsFAQ').style.margin = '5px 0px 0px -46px';
	}*/
	
	var sURL = window.document.URL.toString();
	//alert(sURL);
	if (sURL.indexOf("?") > 0)
	{
		var arrParams = sURL.split("?");
			
		var arrURLParams = arrParams[1].split("&");
		
		var arrParamNames = new Array(arrURLParams.length);
		var arrParamValues = new Array(arrURLParams.length);
		
		var i = 0;
		for (i=0;i<arrURLParams.length;i++)
		{
			var sParam =  arrURLParams[i].split("=");
			arrParamNames[i] = sParam[0];
			if (sParam[1] != "")
				arrParamValues[i] = unescape(sParam[1]);
			else
				arrParamValues[i] = "No Value";
		}
		if(arrParamNames == "title,_requestid" || arrParamNames == "title,title,_requestid")
			document.getElementById('hfeDone').className='bgContainer';
		else if(arrParamNames == "title,mobile")
			document.getElementById('hfsDone').className='bgContainer';
		for (i=0;i<arrURLParams.length;i++)
		{
			if(arrParamValues[i] == "error"){
			   document.getElementById('hfeDone').className='bgContainer';
			   document.getElementById('hfThank').className='for_screenreaders';
			   document.getElementById('hfError').className='';
			   }
			else if(arrParamValues[i] == "mobile"){			   
			   document.getElementById('hfSMS').className='bgContainer';
			   }			
		}
	}
	
}
////////////////////////////////////////////////////////////////////////////////////
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}
function validateSMS()
{
	var mob1 =  document.mobSubmit.phone_1st3digits;
	var mob2 =  document.mobSubmit.phone_2nd3digits;
	var mob3 =  document.mobSubmit.phone_last4digits;
	var mob = false;
	var cob = true;
	var age = false;
	var mesg="";
	document.getElementById('hfsErr').innerHTML="";
	
	if(mob1.value == "" || mob2.value == "" || mob3.value == "")

	{
		
		document.getElementById('hfsErr').innerHTML += "Please enter the Mobile Number<br>";
		mob1.className='hfEmail';
		mob2.className='hfEmail';
		mob3.className='hfEmail';
		mob = false;
	}
	else
	{
		if(IsNumeric(mob1.value) == false || IsNumeric(mob2.value) == false || IsNumeric(mob3.value) == false)
		{
		    document.getElementById('hfsErr').innerHTML += "Please enter numbers only <br>";
			mob1.className='hfEmail';
			mob2.className='hfEmail';
			mob3.className='hfEmail';
			mob = false;
		}
		else
		{
			document.getElementById('hfsErr').innerHTML = "";
			mob1.className='';
			mob2.className='';
			mob3.className='';
			mob = true;
		}
	}
	
	if(document.mobSubmit.selCarrier.value =="-1")
	{
		document.getElementById('hfsErr').innerHTML += "Please Select your Carrier<br>";		
		document.mobSubmit.selCarrier.className='hfEmail';
		cob = false;
	
	}
	
	
	if(document.mobSubmit.hour_of_day.value  =="-1")
	{
		document.getElementById('hfsErr').innerHTML += "Please Select your Reminder Time<br>";
		document.mobSubmit.hour_of_day.className='hfEmail';
		cob = false;
	
	}
	
	if(document.mobSubmit.local_time_zone.value=="-1")
	{
	
		document.getElementById('hfsErr').innerHTML += "Please Select your Time Zone <br>";
		document.mobSubmit.local_time_zone.className='hfEmail';
		cob = false;
	  

	}

	
	
	if(document.getElementById('hfSMSAge').checked == false)
	{
		document.getElementById('hfsErr').innerHTML += "We're sorry, but we cannot send SMS to guests under the age of 13. You can still view our daily deals at Target.com/dailydeals.";
		document.getElementById('hfSMSAge').className='hfEmail';
		age = false;
	}
	else
	{
		age = true;
	}
	
	if(mob == true && age == true && cob == true)
		mobileSubmit();
	else
		return false;
}
/////////////////	AJAX Function to submit email and get the response	////////////////////////////////////
function mobileSubmit()
{
var url = "http://sites.target.com/site/en/spot/dd_signup_thankyou.jsp" ;
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();  // creating an object for firefox and other
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP"); // creating an object for IE
}
req.open("GET", url, true);
req.onreadystatechange = updatePage; 
req.send(null); 
}

function updatePage(){
 if (req.readyState == 4) {
 //   page is getting a response
 document.getElementById('hfSMS').className='for_screenreaders';
 //shiftOpacity('hfsDone', 500);
 activID = 'hfsDone';
      
 }
}
//////////////////////////////////////////////////////////////////////////////////////-------------//

// script to hide quickinfo popup layer when it was called by keypress event
var glob_flag = 0;
function goDetail(e,url,pm1,pm2)
{
	if (e.which == 13)   // for firefox
	{
		glob_flag = e.which;
		location.href = url;
	}
	else
	{
			if (e.which == 1 && glob_flag == 0)
			{
				invokeQuickInfo(url,pm1,pm2); 
				return false;
			}
	}
	
	var evt = window.event;	// for IE
	if (evt.keyCode == 13)
	{
		glob_flag = evt.keyCode;
		location.href = url;
	}
	else
	{
		if (evt.keyCode == 0 && glob_flag == 0)
		{
			invokeQuickInfo(url,pm1,pm2); 
			return false;
		}
	}
}