// JavaScript Document
function getIEVersionNumber() {
    var ua = navigator.userAgent;
    var MSIEOffset = ua.indexOf("MSIE ");
    
    if (MSIEOffset == -1) {
        return 0;
    } else {
        return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
    }
}



function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

var gAutoPrint = true; // Flag for whether or not to automatically call the print function

function printSpecial()
{
	if (document.getElementById != null)
	{
		var html = '<HTML>\n<HEAD>\n';

		if (document.getElementsByTagName != null)
		{
			var headTags = document.getElementsByTagName("head");
			if (headTags.length > 0)
				html += headTags[0].innerHTML;
		}
		
		html += '\n</HE' + 'AD>\n<BODY>\n';
		
		var printReadyElem = document.getElementById("printReady");
		
		if (printReadyElem != null)
		{
				html += printReadyElem.innerHTML;
		}
		else
		{
			alert("Could not find the printReady section in the HTML");
			return;
		}
			
		html += '\n</BO' + 'DY>\n</HT' + 'ML>';
		
		var printWin = window.open("","printSpecial");
		printWin.document.open();
		printWin.document.write(html);
		printWin.document.close();
		if (gAutoPrint)
			printWin.print();
	}
	else
	{
		alert("Sorry, the print ready feature is only available in modern browsers.");
	}
}

function toggleVis(id){
        if(document.getElementById(id).style.display==""){
                document.getElementById(id).style.display="none"
        }else{
                document.getElementById(id).style.display=""
        }
}

function validSearch(){
	
if(document.srchForm.q.value.length<2 || document.srchForm.q.value=='Keyword or item #'){alert('the search box must contain at least 2 characters.');}
else{document.srchForm.submit();}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
    window.open(theURL,winName,features);
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function swapimg(imgid,newsource)
{
	document.getElementById(imgid).src=newsource;
}
function deltext(objid,inputtext)
{	
	if(document.getElementById(objid).value==inputtext)
	{
	 document.getElementById(objid).value="";
	}
}
function puttext(objid,inputtext)
{
	if(document.getElementById(objid).value=="")
	{
	document.getElementById(objid).value=inputtext;
	}
}

function validateContactus(){
	
	if(document.contact.dept.value==""){alert("Please choose a department!"); document.contact.dept.focus(); return false;}
	if(document.contact.fullname.value==""){alert("Please enter your full name!"); document.contact.fullname.focus(); return false;}
	if(document.contact.email.value==""){alert("Please enter your Email!"); document.contact.email.focus(); return false;}
	if(document.contact.message.value==""){alert("Please enter your message!"); document.contact.message.focus(); return false;}

return true;
}

function validateEmail(str){
	
	var filter =/^.+\@.+..{2,3}$/ ;
 
  if ( str == "" || !filter.test(str) )
         {
        
        
        return (false);
        }
		return (true);
	}




//////////////////////////////////////////////JQUERY FUNCTIONS
var timer;

 function hotOffersSlide(){	

//alert($('#hotoffers .offer').not('.hidden').html());

}
$(document).ready(
		function() {
			MM_preloadImages('images/boottomleftcorner.gif','images/boottomrightcorner.gif','images/topleftcorner.gif','images/toprightcorner.gif','images/searchon.gif','images/backimgon.gif','images/updateimgon.gif','images/resetimgon.jpg','images/submitimgon.jpg','images/checkoutimgon.gif','images/enterbuttonon.jpg','images/goimgon.jpg','images/close.png','images/MA-useron.gif','images/MA-carton.gif','images/takeoursurvey2arrowson.jpg','images/nopic.gif');
	$('#rollup h3').click(function() {
								   
			$(this).parent('li').siblings('li').children('h3').removeClass('rolledup').next().slideUp(300);
			
																												
			$(this).toggleClass('rolledup').next().slideToggle(300);
			
			
			
			}).hover(
									function(){
										
											$(this).addClass('hover');},
									function(){
										$(this).removeClass('hover');})	;
	if(false)$('#hotoffers img.reflected').reflect({height: 0.3, opacity: 0.6});
	$('#hotoffers #pages').find('a').each(function (index){
										$(this).click(function(){
																	$('#hotoffers #pages').find('a').removeClass('hover');
																	
																	
																	//clear the timer
																	clearTimeout(timer);
																	$(this).addClass ('hover');
																	$('.offer').hide();
																	$('#offers').children('div').eq(index).fadeIn(500);
																	var isIE7Min = getIEVersionNumber();

																if (isIE7Min > 6 || isIE7Min==0 && !Safari ) {
																	$('.offer img.reflected').reflect({height: 0.3, opacity: 0.6});
																	$('.offer img.offer-pics').reflect({height: 0.7, opacity: 0.3});
																}
									
																	
																	//get index of this link
																	var i=$('#hotoffers #pages').find('a').index(this);
											
										//click the next link after 4 seconds
										if($('#hotoffers .offer').length>1)
										timer=setInterval('$(\'#hotoffers #pages\').find(\'a:eq('+((i+1)%numberofoffers)+')\').click()',4000);
												
																			   });
															 
															 });
	//click the first offer
	$('#hotoffers #pages:eq(0)').find('a:eq(0)').click();
		
	//add reflection to brands images
	$('#brands img').reflect({height: 0.3, opacity: 0.3});
	
	// setInterval( "hotOffersSlide()", 4000 );
	
	$('ul.Menu li').hover(function(){
		$(this).find('ul').show(); $(this).find('a').addClass('Mitem-on');
		if (jQuery.browser.msie)
		if(parseInt(jQuery.browser.version) == 6)
		$('#search-select select').addClass('hide');
		},function(){
		$(this).find('ul').hide(); $(this).find('a').removeClass('Mitem-on');
		$('#search-select select').removeClass('hide');
		});
	$('ul.Menu > li:last').addClass('last');
	
	
			});

function attachChkEvents()
{
	var bf = $("#BILLINGFORM");
	var chks = $('input[type=checkbox]',bf);
	chks.click(function(){
	var ci = chks.index($(this));
	var t=0;
	if($(this).attr("checked"))
	 	chks.each(function(){
			$(this).attr("checked",(chks.index($(this))<=ci?true:false));
			t += (chks.index($(this))<=ci? parseInt($(this).next().val()):0);
			});
	else
	 	chks.each(function(){if(chks.index($(this))>ci) $(this).attr("checked",false);
		 	t += (chks.index($(this))<ci? parseInt($(this).next().val()):0);});
	$('#totalA').text(t);
	});
	
}



