
window.addEvent('domready', function() {
$$('#footerLeft img,img.roll').each(function(img) {
	var src = img.getProperty('src');
	var extension = src.substring(src.lastIndexOf('.'),src.length)
	img.addEvent('mouseenter', function() { img.setProperty('src',src.replace(extension,'.roll' + extension)); });
	img.addEvent('mouseleave', function() { img.setProperty('src',src); });
});
});


function buttondown( buttonname ) {
  if (document.images) {
    document[ buttonname ].src = eval( buttonname + "down.src" );
  }
}
function buttonup ( buttonname ) {
  if (document.images) {
    document[ buttonname ].src = eval( buttonname + "up.src" );
  }
}

function xreq(text,mode) {
  text = encodeURIComponent(text);
  if (window.ActiveXObject) {
    con = new ActiveXObject("Microsoft.XMLHTTP");
  } else if (window.XMLHttpRequest) {
    con = new XMLHttpRequest();
  }

  con.open("GET","gal.php?n="+text+"&l="+limit+"&m="+mode);
  con.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
  con.send('n='+text);

  con.onreadystatechange=function() {
    if (con.readyState==4) {
      document.getElementById('plateThumbs').innerHTML = con.responseText;
      // success action here
      // content is con.responseText;
    }
    return true;
  }
}

function increment(adder,climit,mode) {
  if ( !climit ) {
    limit = 6;
  } else {
    limit = climit;
  }
  var increment = limit * adder;
  if ( increment+currentNum < 0 ) {
    currentNum = 0;
  } else if ( currentNum+increment > maxnum-limit ) {
    currentNum = maxnum - limit;
  } else {
    currentNum += increment;
  }
  xreq(currentNum,mode);
}

function zoomImage(image,title) {
  document.getElementById('fullSizeImage').src = image;
  document.getElementById('plateTitle').innerHTML = title;
}

function errorField(field,color,bg) {
  if ( document.getElementById(field) ) {
    document.getElementById(field).style.backgroundColor = bg;
    document.getElementById(field).style.color = color;
  }
}

function numCheck(field) {
  var test = document.getElementById(field).value;
  if ( !isNum(test) ) {
    document.getElementById(field).focus();
    document.getElementById(field).select();
  }
}

function regexTest(field,regex) {
  var test = document.getElementById(field).value;
  var query = new RegExp(regex);
  if ( !query.test(test) ) {
    /*document.getElementById(field).focus();
    document.getElementById(field).select();*/
    errorField(field,'#fff','#800');
    return false;
  } else {
    errorField(field,'#000','#fff');
    return true;
  }
}

function isNum(input) {
  var regex = new RegExp(/^-?[0-9.]+$/);
  return regex.test(input);
}

function updateVal(val) {
  //alert(val);
  window[val] = document.getElementById(val).value;
}

function validateAddr() {
  document.getElementById('orderPhone').value = document.getElementById('orderPhone').value.replace(/[^0-9]/img, "");
  updateVal('orderPhone');
  var fields = new Array("orderName","orderEmail","orderPhone");
  var field = new String();
  var conds = new Array(RegExp(/.{5,}/i),RegExp(/.{5,}/i),RegExp(/.{3,}/i),RegExp(/[a-z]{2}/i),RegExp(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/i),RegExp(/[0-9]{10}/i),RegExp(/[0-9]{5}/));
  var error = new String();
  var length = fields.length;
  length = fields.length;
  for ( n=0; n<length; n++ ) {
    if ( !regexTest(fields[n],conds[n]) ) {
      error += fields[n]+" ";
    } else {
      updateVal(fields[n]);
    }
  }

  if ( error.length > 0 ) {
    document.getElementById('errorMsg').innerHTML = '<div id="errorMsg">Please ensure your information is accurate</div>';
    return false;
  } else {
    return true;
  }
}

function signInForm() {
  var boxlink = document.getElementById('loginbtn');
  var box = document.getElementById('logonForm');
  if ( box.style.visibility == 'visible' ) {
    box.style.visibility = 'hidden';
    boxlink.style.backgroundColor = '#b72b2b';
    boxlink.style.borderColor = '#b72b2b';
  } else {
    box.style.visibility = 'visible';
    box.style.behavior = "url('border-radius.htc')";
    boxlink.style.backgroundColor = '#ccc';
    boxlink.style.borderColor = '#ccc';
  }

}

function doX(url,params,target,method) {
  var method = method || "POST";
  var box = document.getElementById(target);
  if (window.ActiveXObject) {
    con = new ActiveXObject("Microsoft.XMLHTTP");
  } else if ( window.XMLHttpRequest ) {
    con = new XMLHttpRequest();
  }
  con.open(method,url,true);
  con.setRequestHeader('Content-Type','application/x-www-form-urlencoded;');
  con.send(params);
  con.onreadystatechange = function() {
    if ( con.readyState == 4 && con.status == 200 ) {
      if ( box ) {
        box.innerHTML = con.responseText;
      }
      return con.responseText;
    } else if ( con.readyState == 4 ) {
      return "Error: "+con.status+" "+con.readyState;
    }
  }
}

function saveUser() {
  if ( !validateAddr() ) {
    return;
  }
  if ( (userId < 0 && !checkPass()) || (userId > 0 && document.getElementById('password1').value.length > 0 && !checkPass() )  ) {
    return;
  }

  var params = new String();
  params += "&orderName="+orderName;
  if ( document.getElementById('password1') && document.getElementById('password1').value.length > 0 ) {
    params += "&orderPass="+encodeURIComponent(document.getElementById('password1').value);
  }
  params += "&orderEmail="+orderEmail;
  params += "&orderPhone="+orderPhone;
  if ( $('orderRefer') ) params += "&orderRefer="+document.getElementById('orderRefer').value;
  params += "&userTrack="+document.getElementById('userTrack').value;
  doX('savenewuser.php',params,'ch2formArea','POST');
}

function checkPass(pid) {
  if ( !document.getElementById('password2') ) return true;
  var pass1 = document.getElementById('password1').value;
  var pass2 = document.getElementById('password2').value;
  if ( pid == 1 && pass2.length == 0 ) return;

  if ( pass1.length < 5 ) {
    document.getElementById('errorMsg').innerHTML = 'Please enter a password that is at least 5 characters.';
    return false;
  } else if ( pass1 === pass2 ) {
    document.getElementById('errorMsg').innerHTML = '';
    return true;
  } else if ( pass1.length > 0 && pass2.length <= 0 ) {
    document.getElementById('errorMsg').innerHTML = 'Please re-enter your password for confirmation.';
    return false;
  } else {
    document.getElementById('errorMsg').innerHTML = "Your passwords do not match.";
    return false;
  }
}

function checkRefer() {
  var refer = 0;
  if ( !document.getElementById('orderRefer') ) {
     return true;
  }
  if ( document.getElementById('orderRefer').value.length == 0 ) return 0;
  else {

    if (window.ActiveXObject) {
      con = new ActiveXObject("Microsoft.XMLHTTP");
    } else if ( window.XMLHttpRequest ) {
      con = new XMLHttpRequest();
    }
    con.open('GET','refercheck.php?refer='+document.getElementById('orderRefer').value,true);
    con.setRequestHeader('Content-Type','application/x-www-form-urlencoded;');
    con.send();
    con.onreadystatechange = function() {
      if ( con.readyState == 4 && con.status == 200 ) {
        if ( con.responseText.length > 0 ) document.getElementById('errorMsg').innerHTML = "Referred by " + con.responseText;
        else document.getElementById('errorMsg').innerHTML = "Sorry, we couldn't find them. Try another e-mail address or phone number.";
      }
    }
  }
}

function sendFeedback() {
  var text = encodeURIComponent(document.getElementById('checkOutFeedBack').value);
  var invoice = document.getElementById('invoice').value;
  var params = "invoice="+invoice+"&text="+text;
  doX('simplemail.php',params,'formArea','POST');
}

function swapSalesPoint() {
  var caption = document.getElementById('salesPointCopy');
  var image = document.getElementById('salesPointImage');
  var salesPoints = new Array(
    new Array('reflective.jpg','Our thermo-resin printing offers one-of-a-kind reflectiveness. &gt;&gt;'),
    new Array('bombproof.jpg','&quot;The thickness of the plates is Bombproof!&quot; <em>-Alfredo Carbonell</em> &gt;&gt;'),
    new Array('vinyl.jpg','Graphics applied to the back guarantee longer life. &gt;&gt;'),
    new Array('width.jpg','Thickest Plates on the Market! <br />Made with 1/16&quot; Lexan. &gt;&gt;')
  );

  caption.innerHTML = salesPoints[sPinterval][1];
  image.innerHTML = '<img src="images/'+salesPoints[sPinterval][0]+'" alt="'+salesPoints[sPinterval][1]+'" />';
  if ( sPinterval < 3 ) sPinterval++;
  else sPinterval = 0;
}

// Mouseover Images
var getstartedup = new Image();
    getstartedup.src = "images/get.started.png";
var getstarteddown = new Image();
    getstarteddown.src = "images/get.started.hover.png";
var larrowup = new Image();
    larrowup.src = "images/left-arrow.png";
var larrowdown = new Image();
    larrowdown.src = "images/left-arrow.hover.png";
var rarrowup = new Image();
    rarrowup.src = "images/right-arrow.png";
var rarrowdown = new Image();
    rarrowdown.src = "images/right-arrow.hover.png";
var orderbtnup = new Image();
    orderbtnup.src = "images/order.button.png";
var orderbtndown = new Image();
    orderbtndown.src = "images/order.button.hover.png";
var newbtnup = new Image();
    newbtnup.src = "images/new.button.png";
var newbtndown = new Image();
    newbtndown.src = "images/new.button.hover.png";

/*************************************************************
* Window Onload Manager (WOM) v1.0
* Author: Justin Barlow - www.netlobo.com
*
* Description:
* The WOM library of functions allows you to easily call
* multiple javascript functions when your page loads.
*
* Usage:
* Add functions to WOM using the womAdd() function. Pass the
* name of your functions (with or without parameters) into
* womAdd(). Then call womOn() like this:
*     womAdd('hideDiv()');
*     womAdd('changeBg("menuopts","#CCCCCC")');
*     womOn();
* WOM will now run when your page loads and run all of the
* functions you have added using womAdd()
*************************************************************/
/*************************************************************
* The womOn() function will set the window.onload function to
* be womGo() which will run all of your window.onload
* functions.
*************************************************************/
function womOn(){
  window.onload = womGo;
}
/*************************************************************
* The womGo() function loops through the woms array and
* runs each function in the array.
*************************************************************/
function womGo(){
  for(var i = 0;i < woms.length;i++)
    eval(woms[i]);
}
/*************************************************************
* The womAdd() function will add another function to the woms
* array to be run when the page loads.
*************************************************************/
function womAdd(func){
  woms[woms.length] = func;
}
/*************************************************************
* The woms array holds all of the functions you wish to run
* when the page loads.
*************************************************************/
var woms = new Array();
