// place Functions here 

// Generic PopUp Function
function popUp(wname,url,width,height,statusbar,scrollbars,resizable,toolbar){

	//define height and width if they are not passed
	//as arguments
	if(!height)
		height=300;
	if(!width)			
		width=500;
	if(!scrollbars)			
		scrollbars="yes";
	if(!resizable)			
		resizable="no";
	if(!toolbar)			
		toolbar="no";
	if(!statusbar)			
		toolbar="no";

	var theWidth = width;
	var theHeight = height;

		
	x = (640 - theWidth)/2, y = (480 - theHeight)/2;

  	if (screen) {
      		y = (screen.availHeight - theHeight)/2;
      		x = (screen.availWidth - theWidth)/2;
  		}
	if (screen.availWidth > 1800) { 
		x = ((screen.availWidth/2) - theWidth)/2; 
  		} 

		
	var settings = "status=" + statusbar + "toolbar=" + toolbar + ",resizable=" + resizable + ",height=" + height + ",width=" + width + ",scrollbars=" + scrollbars + ',width='+theWidth+',height='+theHeight+',screenX='+x+', screenY='+y+', top='+y+',left='+x;
	PopWin = window.open(url,wname,settings);
	PopWin.focus();
}
			
			

						
//Pulling Data from Other Web pages with XMLHTTP 
function RemoteScriptXMLHTTPGetPage(ExternalPageURL){
	var xmlhttp = null;
		
	try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");} catch (e) {
	try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");} catch (E) {
	xmlhttp = false; }
	 }
	if (xmlhttp) {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	xmlhttp.open("get", ExternalPageURL,true);
	xmlhttp.onreadystatechange= function() {
	if (xmlhttp.readyState==4) { document.write(xmlhttp.responseText) ; } 
	} 
	xmlhttp.send(null) 
	}
}

//---------------------- Newsletter Ad scrolling out functions		  


function initFocalAd(){	   

	 if  (document.getElementById("idCMNewsSweepstakesAd"))  {
		objDiv = document.getElementById("idCMNewsSweepstakesAd");
	
	
		objDiv.style.pixelTop = intTop;	 
		objDiv.style.pixelLeft =intLeft;	 		 
		objDiv.style.pixelHeight=intHeight;		
		objDiv.style.pixelWidth=intWidth;
		objDiv.style.position='absolute';	 
		objDiv.style.visibility='visible';	
		objDiv.style.display='block';
		
		intObjClip = 0;
		intObjOtop = 0;	
		
		intRevCount = intHeight;
		objDiv.style.clip='rect(0,'+intWidth+','+intHeight+',0)'; 
	
	   
		setTimeout("MoveOutFocalAd();",5000);  	
		
		return true;
	 } else {
	 	alert('where is the ad');
		return false;
	 }		

}
	   
function MoveOutFocalAd()
{
	intObjClip = intObjClip+intSpeed;

	objDiv.style.clip='rect('+  intObjClip +',auto,'+objDiv.style.pixelHeight+',auto)';

	objDiv.style.pixelTop = objDiv.style.pixelTop-intSpeed;


	intRevCount = intRevCount-intSpeed;

	if(intRevCount > 0) {
		setTimeout("MoveOutFocalAd();",0);
	} else {   		
		  intRevCount = Math.abs(intRevCount)+5;
		  objDiv.style.display='none'; 	 

	}	
}

//---------------------- Newsletter Ad scrolling out functions END





function determineserverdatetime() {
var localdate = new Date();
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');

var cseNewDate = DateAdd("h",(localdate.getTimezoneOffset()/60),localdate); 
var ServerDate = DateAdd("h",-8,cseNewDate);
var dispdate = ServerDate.getMonth()+1+'/'+ServerDate.getDate()+'/'+fourdigits(ServerDate.getYear())+', '+ days[ServerDate.getDay()]+','+ampmtime(ServerDate)+' (PST)' 										

return dispdate;
}

function DateAdd(timeU,byMany,dateObj) {
	var millisecond=1;
	var second=millisecond*1000;
	var minute=second*60;
	var hour=minute*60;
	var day=hour*24;
	var year=day*365;

	var newDate;
	var dVal=dateObj.valueOf();
	switch(timeU) {
		case "ms": newDate=new Date(dVal+millisecond*byMany); break;
		case "s": newDate=new Date(dVal+second*byMany); break;
		case "mi": newDate=new Date(dVal+minute*byMany); break;
		case "h": newDate=new Date(dVal+hour*byMany); break;
		case "d": newDate=new Date(dVal+day*byMany); break;
		case "y": newDate=new Date(dVal+year*byMany); break;
	}
	return newDate;
}

function fourdigits(number)	{
          return (number < 1000) ? number + 1900 : number;}	
					
function ampmtime(number) {
    var ampm = "AM";		 
		hour = number.getHours();
		minute = number.getMinutes();
    var xhour = hour;
    var xminute = minute;
    if (xminute < 10) xminute = "0" + xminute;									
    if (hour >= 12) {
				   ampm = "PM";
  					 if (hour != 12) xhour = hour - 12;
						 }
						 return xhour + ":"+ xminute + " " + ampm;
}
	
	
function pte(theImage) {
   if (theImage.src !== '/images/ProductThumbNoImage.gif') {	 
	 		theImage.src = '/images/ProductThumbNoImage.gif';
	 }
}

function pde(theImage) {
   if (theImage.src !== '/images/ProductDetailNoImage.gif') {	 
	 		theImage.src = '/images/ProductDetailNoImage.gif';
	 }
}

function wbe(theImage) {
   if (theImage.src !== '/images/NoBannerImage.gif') {	 
	 		theImage.src = '/images/NoBannerImage.gif';
	 }
}

//----------------- Init Search on Co-Branded Websites	e.g. Millionaire Match, CC Offers,  OnLine Hotel Reservations
	function initiatesearchmm() {

		  if ( document.searchform.s.value.replace(/^\s+/,"").replace(/\s+$/,"").length < 3 ) {
		   	return false;
		  } else {
		  	 if (document.searchform.sc[document.searchform.sc.selectedIndex].value=='0') {
				 idSearchMessageTxt.innerText = "Searching Millions of Products, Hundreds of Merchants and Tons of Specials for '"+document.searchform.s.value.replace(/^\s+/,"").replace(/\s+$/,"")+"'. Please Wait!";
				 document.getElementById('idSearchMessage').style.border="solid 1 #000000";
				  document.getElementById('idSearchMessage').style.backgroundColor ='#ffeeee';	 	
			 }
		  	 if (document.searchform.sc[document.searchform.sc.selectedIndex].value=='2') {
				 idSearchMessageTxt.innerText = "Searching Millions of Products for '"+document.searchform.s.value.replace(/^\s+/,"").replace(/\s+$/,"")+"'. Please Wait!";			
				 document.getElementById('idSearchMessage').style.border="solid 1 #000000";	 
				  document.getElementById('idSearchMessage').style.backgroundColor ='#ffeeee';
							  
			  }					
			 return true;
		  }
	}	 

//--- JS Function for CC Offers
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}	



function initiatesearchrb() {

		  if ( document.searchform.s.value.replace(/^\s+/,"").replace(/\s+$/,"").length < 3 ) {
		   	return false;
		  } else {
				 var sSearchMsg = "";

		  	 if (document.searchform.sc[document.searchform.sc.selectedIndex].value=='0') {
				   sSearchMsg = "Searching millions of Products, Hundreds of Merchants and Tons of Specials for '"+document.searchform.s.value.replace(/^\s+/,"").replace(/\s+$/,"")+"'. Please Wait!";
			   }
		  	 if (document.searchform.sc[document.searchform.sc.selectedIndex].value=='2') {
				   sSearchMsg = "Searching millions of Products for '"+document.searchform.s.value.replace(/^\s+/,"").replace(/\s+$/,"")+"'. Please Wait!";			
			   }	
				 
				 if (!sSearchMsg=='') {
				   document.getElementById("idSearchMessageTxt").innerHTML =  sSearchMsg ;	
           objDivSearch = document.getElementById("idSearchMessage");
           objDivSearch.style.display='block';
				 }			 
				 
		    return true;
		  }
			
}	

function showCMcssID(cssID) {
  objCSSid = document.getElementById(cssID);
	objCSSid.style.visibility='visible';	
	objCSSid.style.display='block';	

}

function hideCMcssID(cssID) {
  objCSSid = document.getElementById(cssID);
  objCSSid.style.visibility='hidden';
  objCSSid.style.display='none';
}


function IE7AddCm2SeP() {
strAddURI = "http://www.consumermatch.com/include/IE7-CM-SearchProvider.xml"; 
try{ window.external.AddSearchProvider(strAddURI); }
catch(eX){ 		if (70 == (eX.number & 0xFFFF)){
					         alert("For security reasons, you must use the mouse\n(or the Enter key) to click the Install button."); 
					    } else {
                   alert("Unable to add search provider. This feature requires MS Internet Explorer 7.   [" + (eX.number & 0xFFFF) + "]");
              }
			   }
return false;				       
}