function doLoad() {
  // does nothing
}

function addEvent( obj, type, fn ){  // the add event function
  if (obj.addEventListener) obj.addEventListener( type, fn, false );
  else if (obj.attachEvent) {
    obj["e"+type+fn] = fn;
    obj[type+fn] = function() {
      obj["e"+type+fn]( window.event );
    };
    obj.attachEvent( "on"+type, obj[type+fn] );
  }
}

var firstEl;

function validateForm(frm) {
  errs = "";
  firstEl = null;
  els = frm.elements;
  for(i=0; i<els.length; i++) {
    if(els[i].id == "req")
      errs += checkVal(els[i]);
  }
  if(errs != "") {
    alert("Please make the following changes:\n\n" + errs);
    if(firstEl)
      firstEl.focus();
    return false;
  }
  return true;
}

function checkVal(el) {
  if(el) {
    if(((el.tagName == "INPUT" || el.tagName == "TEXTAREA") && el.value == "")
       || (el.tagName == "SELECT" && el.options[el.selectedIndex].value == "")) {
      if(firstEl == null)
        firstEl = el;
      return "- " + el.title + "\n";
    }
  }
  return "";
}

var tabOver = function(el) {
  cls = el.className;
  if(cls.indexOf('xed') != -1)
    el.className = 'tab xedover';
  else if(cls.indexOf('on') == -1)
    el.className = 'tab over';
}

var tabOut = function(el) {
  cls = el.className;
  if(cls.indexOf('xedover') != -1)
    el.className = 'tab xed';
  else if(cls.indexOf('on') == -1)
    el.className = 'tab';
}
  


/** MOUSE OVER EFFECTS **/
function preloadImgs() {
  imgs = document.images;
  for(i=0; i<imgs.length; i++) {
    src = imgs[i].src;
    if(imgs[i].className != 'no-hover' && src.indexOf('_off') != -1) {
      document.onImg = new Image();
      document.onImg.src = src.replace('_off', '_on');
      
      addEvent(imgs[i], "mouseover", toggleImg);
      addEvent(imgs[i], "mouseout", toggleImg);
    }
  }
  imgs = document.getElementsByTagName("input");
  for(i=0; i<imgs.length; i++) {
    if(imgs[i].type.toLowerCase() == 'image') {
      src = imgs[i].src;
      if(imgs[i].className != 'no-hover' && src.indexOf('_off') != -1) {
        document.onImg = new Image();
        document.onImg.src = src.replace('_off', '_on');
        
        addEvent(imgs[i], "mouseover", toggleImg);
        addEvent(imgs[i], "mouseout", toggleImg);
      }
    }
  }
}

addEvent(window, "load", preloadImgs);

function toggleImg() {
  src = this.src;
  if(src.indexOf('_off') != -1)
    this.src = src.replace('_off', '_on');
  else if(src.indexOf('_on') != -1)
    this.src = src.replace('_on', '_off');
}


function fixIE() {
  if(document.all) {
    theObjects = document.getElementsByTagName("object");
    for (var i = 0; i < theObjects.length; i++) {
      theObjects[i].outerHTML = theObjects[i].outerHTML;
    }
  }
}
//addEvent(window, "load", fixIE);


function goTo(u) {
  window.location = u;
}

function openPopupWindow(url, width, height, scrolling, name) {
  if (!width) width = 350;
  if (!height) height = 350;
  if (!scrolling) scrolling = "no"; 
  if (!name) name = "win"+Math.round(Math.random()*1000); 
  
  features = "width="+width+","
           + "height="+height+","
           + "toolbar=no,"
           + "location=no,"
           + "status=no,"
           + "menubar=no,"
           + "scrollbars="+scrolling+","
           + "top=50,"//+(window.screen.height-height)/2+","
           + "left=50";//+(window.screen.width-width)/2;
  win = window.open(url,name,features);
  if(win)
    win.focus();
  return win;
}

function popup(u) {
  openPopupWindow('http://www.synccreation.com/popup'+u, 600, 600, "yes");
  return false;
}

function viewImg(u) {
  openPopupWindow("/popup.jsp?url="+u);
}

function watchVid(u) {
  openPopupWindow("/video.jsp?url="+u, 680, 416, "no", "vidWin");
}

/**
 * Search Functions
 */
function sFocus(el){
  t = el.title;
  if(el.value == t)
    el.value = '';
}
function sBlur(el) {
  t = el.title;
  if(el.value == '')
    el.value = t;
}
function sSubmit(frm) {
  s = frm.s.value;
  t = frm.s.title;
  if(s == t || s == '') {
    alert('Please enter something to search for');
    return false;
  }
  return true;
}

function trackTrans() {
	// override on thanks page
}

function _clear(el) {
  t = el.title;
  if(el.value == t)
    el.value = '';
}

function _blur(el) {
  t = el.title;
  if(el.value == '')
    el.value = t;
}

function _validate(frm) {
  eml = frm.email;
  at = eml.value.indexOf('@');
  if(eml.value == eml.title || eml.value == '') {
    alert('Please enter your phone number or email address');
    return false;
  } else if(at == -1 || eml.value.indexOf('.', at) <= at) {
    alert('Please enter a valid email address');
    return false;
  }
  return true;
}

/* Cart Function */
function editItem(s) {
  window.location = s;
}

function updateCart(i) {
  document.forms['item'+i].action.value = 'update';
  document.forms['item'+i].submit();
}

function removeItem(i) {
  document.forms['item'+i].action.value = 'remove';
  document.forms['item'+i].submit();
}

function changeShipping(el) {
  window.location = window.location.pathname+"?shipping="+el.value;
}

function viewOptions() {
  s = document.getElementById("shipping-options").style;
  if(s.display == 'block')
    s.display = 'none';
  else
    s.display = 'block';

}

function setCookie(c_name,value,expiredays){
	var exdate=false;
	if(expiredays!=null && expiredays){	exdate=new Date(); exdate.setDate(exdate.getDate()+expiredays); extime=exdate.toGMTString(); }
	document.cookie=c_name+"="+escape(value)+(exdate ? ";expires="+extime : '')+'; path=/';
}

function getCookie(c_name){
	var cookies=document.cookie.split(';');
	for(i in cookies){
		tmp_cookie=cookies[i].split('=');
		cookie_name=tmp_cookie[0].replace(/^\s+|\s+$/g, '');
		if(cookie_name==c_name){
			cookie_value=tmp_cookie.length?unescape(tmp_cookie[1].replace(/^\s+|\s+$/g,'')):1;
			return cookie_value;
			break;
		}
	}
	return null;
}
