function popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}

var selected;
var submitter = null;
function submitFunction() {
   submitter = 1;
   }
function selectRowEffect(object, buttonSelect) {
  if (!selected) {
    if (document.getElementById) {
      selected = document.getElementById('defaultSelected');
    } else {
      selected = document.all['defaultSelected'];
    }
  }

  if (selected) selected.className = 'moduleRow';
  object.className = 'moduleRowSelected';
  selected = object;

// one button is not an array
  if (document.checkout_payment.payment[0]) {
    document.checkout_payment.payment[buttonSelect].checked=true;
  } else {
    document.checkout_payment.payment.checked=true;
  }
}

function rowOverEffect(object) {
  if (object.className == 'moduleRow') object.className = 'moduleRowOver';
}

function rowOutEffect(object) {
  if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}

function check_form() {
  var error = 0;
  var error_message = "Errors have occured during the process of your form.\n\nPlease make the following corrections:\n\n";
  var payment_value = null;
  if (document.checkout_payment.payment.length) {
    for (var i=0; i<document.checkout_payment.payment.length; i++) {
      if (document.checkout_payment.payment[i].checked) {
        payment_value = document.checkout_payment.payment[i].value;
      }
    }
  } else if (document.checkout_payment.payment.checked) {
    payment_value = document.checkout_payment.payment.value;
  } else if (document.checkout_payment.payment.value) {
    payment_value = document.checkout_payment.payment.value;
  }

  if (payment_value == "cc") {
    var cc_owner = document.checkout_payment.cc_owner.value;
    var cc_number = document.checkout_payment.cc_number.value;
    var cvvnumber = document.checkout_payment.cvvnumber.value;
    if (cc_owner == "" || cc_owner.length < 3) {
      error_message = error_message + "* The owner's name of the credit card must be at least 3 characters.\n";
      error = 1;
    }
    if (cc_number == "" || cc_number.length < 10) {
      error_message = error_message + "* The credit card number must be at least 10 characters.\n";
      error = 1;
    }
    if (cvvnumber.length > 4) {
      error_message = error_message + "*** The credit card validation number must be 4 digits or less. \n";
      error = 1;
    }
    if (cvvnumber == ""|| cvvnumber.length < 3) {
      error_message = error_message + "*** The credit card validation number must be at least 3 digits . \n";
      error = 1;
    }
  }

  if (payment_value == null && submitter != 1) {
    error_message = error_message + "* Please select a payment method for your order.\n";
    error = 1;
  }

  if (error == 1 && submitter != 1) {
    alert(error_message);
    return false;
  } else {
    return true;
  }
}

function couponpopupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=450,height=280,screenX=150,screenY=150,top=150,left=150')
}



function swapImage(img, newSrc) {
	img.osrc = img.src;
	img.src = newSrc;
}
function restoreImage(img) {
	img.src = img.osrc;
}

function wxyopen(uri,x,y)
{
	window.open(uri,'',"resizable=yes, scrollbars=yes, status=yes" + (y > 0 ? ", height=" + y : "") + (x > 0 ? ", width=" + x : ""));
}

function productPopup(id) 
{
	wxyopen('/popup_image.php?products_id='+id, 470, 640);
}

function filterCommon(select, paramName) 
{
	paramName = paramName + '=';
	var str = window.location.search.substr(1);
	var params = str.split('&');
	var query;
	for (i=0; i<params.length; i++) {
		if (params[i].indexOf(paramName) != -1) {
			params.splice(i, 1);
		}
	}
	if (select.options[select.selectedIndex].value != -1) {
		params.push(paramName+select.options[select.selectedIndex].value);
	}
	var href = window.location.protocol + '//' + window.location.hostname + window.location.pathname + '?' + params.join('&');
	window.location.href = href;
}

function filterPrice(select) 
{
	filterCommon(select, 'price')
}

function filterType(select) 
{
	filterCommon(select, 'type')
}

function filterContents(select) {
	filterCommon(select, 'contents')	
}

function priceChanged(radio) {
	var table = radio.parentNode.parentNode.parentNode;
	var rows = table.getElementsByTagName('tr');
	for (var i=0; i < rows.length; i++) {
		//alert(rows[i]);
		rows[i].className = 'off';
	}
	radio.parentNode.parentNode.className = 'on';
}


function getPos(el) {
  var r = { x: el.offsetLeft, y: el.offsetTop };
  if (el.offsetParent) {
    var tmp = getPos(el.offsetParent);
    r.x += tmp.x;
    r.y += tmp.y;
  }
  return r;
}

function checkNum(obj) {
	state = obj.checked;
	if(state)
		document.getElementById("reas"+obj.id).disabled = false;
	else
		document.getElementById("reas"+obj.id).disabled = true;
}

function showError (frm, elName, msg) {
	var el = document.getElementById (elName);
	if (el == null) {
		el = document.createElement("div");
		el.id = elName;
		el.className = "errorMsg";
		frm.parentNode.insertBefore(el, frm);
	}  
	el.innerHTML = msg;
	var pos = getPos(el);
	window.scrollTo (pos.x, pos.y);
}
