//<![CDATA[

// - Sales_blog.js

// -------------------------------------------------------------------
// -           Newsletter SignUp Cookie Code
// --------------------------------------------------------------------


// cookie code for newsletter signup for industrialego.com
// The way this works is that each time a new user comes to the
// site, on whatever page they enter on, they will get a popup
// encouraging them to sign up for the newsletter.  If they don't
// sign up then a cookie is set to wait for 6 hours before popping
// up the window again.  This makes it less annoying so that they
// can surf the site without a popup happening all the time
// If they do signup for the newsletter, then a long term cookie
// is set and they will not get the popup ever again (for 12 years)
	
var expDays = 5000; // number of days the signup cookie should last
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

var oneexpDays = .00001; // number of days the count cookie should last
var oneday = new Date(); 
oneday.setTime(oneday.getTime() + (oneexpDays*24*60*60*1000));			
	


function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
	  var j = i + alen;    
	  if (document.cookie.substring(i, j) == arg)      
	    return getCookieVal (j);    
	  i = document.cookie.indexOf(" ", i) + 1;    
	  if (i == 0) break;   
	}  
	return null;
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function SetCookie (name, value) {  
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	 
	var path = (argc > 2) ? argv[2] : null;  
	var domain = (argc > 3) ? argv[3] : null;  
	var expires = (argc > 4) ? argv[4] : null; 
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}
//this DeleteCookie function is not working I don't know why
function DeleteCookie (name) {  
var expnow = new Date(); 
alert('deleting the cookie' + name); 
expnow.setTime (expnow.getTime() - 1);  
alert('exp now is ' + expnow);
var cval = GetCookie (name);  
document.cookie = name + "=" + cval + "; expires=" + expnow.toGMTString();
}

function PopTheWin(URL, WIDTH, HEIGHT) {

windowprops = "resizable=yes,left=50,top=0,width=" + WIDTH + ",height=" + HEIGHT;
// preview = window.open(URL, "preview", windowprops);
window.open(URL, "front", windowprops);
}

function doPopup() {
url = "http://www.industrialego.com/shameless-sales-tips.htm";

   width = 750;  // width of window in pixels
   height = 780; // height of window in pixels

//   if (screen)
//   {
//       width = screen.width;
//	   height = screen.height;
//   }
   
delay = 7;    // time in seconds before popup opens
timer = setTimeout("PopTheWin(url, width, height)", delay*1000);
}


// Hover Pop Code
function popWin(){
var ppl="popLayer";var objppl=findObj(ppl);
if (objppl==null){return;}// if the layer does not exist, do nothing.

var args=arguments,movetoX=parseInt(args[0]),movetoY=parseInt(args[1]),movespeed=parseInt(args[2]);
var cycle=10,pxl="";

if (allowpop != 0) {


if(!document.layers){objppl=objppl.style;}
if(objppl.tmofn!=null){clearTimeout(objppl.tmofn);}
var pplcoordX=parseInt(objppl.left),pplcoordY=parseInt(objppl.top);
var xX=movetoX,yY=movetoY;if((pplcoordX!=movetoX)||(pplcoordY!=movetoY)){
   var moveX=((movetoX-pplcoordX)/movespeed),moveY=((movetoY-pplcoordY)/movespeed);
   moveX=(moveX>0)?Math.ceil(moveX):Math.floor(moveX);movetoX=pplcoordX+moveX;
   moveY=(moveY>0)?Math.ceil(moveY):Math.floor(moveY);movetoY=pplcoordY+moveY;
   if((parseInt(navigator.appVersion)>4||navigator.userAgent.indexOf("MSIE")>-1) && (!window.opera)) {pxl="px";}
   if (moveX!=0){eval("objppl.left='" + movetoX + pxl + "'");}
   if (moveY != 0) {eval("objppl.top = '" + movetoY + pxl + "'");}
   var sFunction = "popWin(" + xX + "," + yY + "," + movespeed+ ")";
   objppl.visibility = "visible";

   objppl.tmofn = setTimeout(sFunction,cycle);
   }
 } // end of if allow pop
}

function findObj(theObj, theDoc){
var p, i, foundObj;
if(!theDoc) theDoc = document;
if((p = theObj.indexOf("?")) > 0 && parent.frames.length)
   {theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);}
if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
for (i=0; !foundObj && i < theDoc.forms.length; i++)
foundObj = theDoc.forms[i][theObj];
for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
foundObj = findObj(theObj,theDoc.layers[i].document);
if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
return foundObj;
}
// end Hover Pop Code



function checkForSignupPop() {

	var count = GetCookie('count');
	
	if (count == null) {
	  count=1;
	 // alert(' count is null');
	  SetCookie("count", count, "/", "industrialego.com", oneday);
	
	  
      var signup = GetCookie('signup');
      if (signup == null) {
        // alert(' on homepage they never signed up');
	      doPopup();
	  }
	else {

           // alert(' on homepage they already signed up');
           }

	}
	else {

	 // alert('  count is' + count);
	 // alert(' coockie expires on ' + oneday);
   }





}



function checkForSignupHoverPop() {

	var count = GetCookie('count');
	
	if (count == null) {
	  count=1;
	 // alert(' count is null');
	  SetCookie("count", count, "/", "industrialego.com", oneday);
	
	  
      var signup = GetCookie('signup');
      if (signup == null) {
        // alert(' on homepage they never signed up');
	     // doPopup();
		  
		// start the hover pop
		setTimeout('popWin(70,110,20)',500);
	  }
	  else {
           // alert(' on homepage they already signed up');
           }

	} // end of if count is null
	else {

	 // alert('  count is' + count);
	 // alert(' coockie expires on ' + oneday);
    }
}



function setSignupCookie() {

	var signup = GetCookie('signup');
	if (signup == null) {
	  signup=1;
	 // alert(' they never signed up');
	  SetCookie("signup", signup, "/", "industrialego.com", exp);
	// alert(' exp is ' + exp);

	}
	else {
	 
	
	 // alert('they already signed up ');
   }
   return true;
}


//]]>