function swatchFindObj(n, d) {
    var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
    }
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=swatchFindObj(n,d.layers[i].document);
    if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function swatchShowHideLayers() {
    var i,p,v,obj,args=swatchShowHideLayers.arguments;
    for (i=0; i<(args.length-2); i+=3) if ((obj=swatchFindObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}
function swatchOver(num) {
    swatchhideall();
    swatchShowHideLayers('swatch' + num,'','show');
    if (swatchMenu != null) { window.clearTimeout(swatchMenu); }
}
function swatchCurrent() {
    swatchhideall();
    swatchShowHideLayers('swatchcopy','','show');
}
function swatchOut(num) {
    if (swatchMenu != null) { window.clearTimeout(swatchMenu); }
    swatchMenu = window.setTimeout('swatchCurrent()',500);
}
function scolorOnChange(size_id)
{
   var ctag = document.getElementById('color_id_' + size_id);
   var qtag = document.getElementById('products_quantity_' + size_id);
   if (ctag.options[ctag.selectedIndex].value == -1) {
       qtag.value = 0;
   } else {
       qtag.value = 1;
   }
}
function show_sizing_chart()
{
    var elem = document.getElementById('sizing_chart');
    elem.style.display = '';
}
function viewSwatches(product_id)
{
    var left = (screen.width - 500) / 2;
    var top = (screen.height - 680) / 2;
    var swatcheswindow = window.open("popup_swatches.html?id=" + product_id,'_blank','left='+left+',top='+top+',resizable=no,scrollbars=yes,height=680,width=500');
}

function viewFullPicture(product_id)
{
    var left = (screen.width - 500) / 2;
    var top = (screen.height - 680) / 2;
    var swatcheswindow = window.open("popup_full_picture.html?id=" + product_id,'_blank','left='+left+',top='+top+',resizable=yes,scrollbars=yes,height=750,width=650');
}
function NewWindow(mypage, myname, w, h, scroll,resize)
{
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable='+resize+''
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function isBlank(val) {
        if (val.length == 0) { return true; }
        for (var i=0; i < val.length; i++) {
                if ((val.charAt(i) != ' ') && (val.charAt(i) != "\t") && (val.charAt(i) != "\n")) { return false; }
        }
        return true;
}

function redirectPage(page) {
	return false; //for now
}


function checkAll2(checkboxes,flag,button) {
	var newValue=true;
    if(flag.value=='true') {
		newValue=true;
        flag.value='false';
        button.value='Uncheck All';
    } else {
		newValue=false;
        flag.value='true';
        button.value='Check All';
    }

	for(var i=0;i<checkboxes.length;i++) checkboxes[i].checked = newValue;
	return true;
}

function checkAll(checkboxes,value) {
	var value = true;
	for(var i=0;i<checkboxes.length;i++) checkboxes[i].checked = value;
}

function checkemail(str){
	var filter= /^([\w-]+(\.[\w-]+)*)@(([\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(\.[a-z]{2})?)$/i;
	if (filter.test(str)) return true; else return false;
}

function checkurl(str) {
	var filter= /^http\:\/\/(([\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(\.[a-z]{2})?).*$/i;
	if (filter.test(str)) return true; else return false;
}

function checklogin(str) {
	var filter=/^[\w-\ ]{4,16}$/i
	if (filter.test(str)) return true; else return false;
}

function checkpassword(str) {
	var filter=/^[\w-\ ]{6,16}$/i
	if (filter.test(str)) return true; else return false;
}

function checkdate(str) {
	var filter=/^\d\d\d\d-\d\d-\d\d$/
	if (filter.test(str)) return true; else return false;
}

function checkdate2(str) {
	var filter=/^\d\d\/\d\d\/\d{2,4}$/
	if (filter.test(str)) return true; else return false;
}

function compare_dates(date1, date2){
	var arrDate1 = date1.split("/");
	var arrDate2 = date2.split("/");
	var rdate1= new Date(arrDate1[2],arrDate1[0]-1,arrDate1[1]);
	var rdate2= new Date(arrDate2[2],arrDate2[0]-1,arrDate2[1]);
	if ( rdate1 > rdate2) return false; else return true;
}

function checkoccupants(str) {
	var filter=/^\d$/
	if (filter.test(str)) return true; else return false;
}

function checknumber(str) {
	var filter=/^\d+$/
	if (filter.test(str)) return true; else return false;
}

function checkprice(str) {
	var filter=/^\d*(\.\d+)?$/
	if (filter.test(str)) return true; else return false;
}

function checkcard_number(str) {
	var filter=/^[\d]{14,16}$/i
	if (filter.test(str)) return true; else return false;
}

function openPopup(theURL,w, h) {
	var left = (screen.width - w) / 2;
	var top = (screen.height - h) / 2;
	var twindow=window.open(theURL,'_blank',"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,left="+left+",top="+top+",width="+w+",height="+h);
	twindow.focus();
}

function replaceLocation(href) {
	window.open(href,'_self',"",false); return;
}

function openPage(file,target) {
	if (target != '') target.window.location.href = file;
	else window.location.href = file;
}

function generateRandomPassword(plength){
	var keylist="abcdefghijklmnopqrstuvwxyz123456789";
	var temp='';
	for (i=0;i<plength;i++) temp+=keylist.charAt(Math.floor(Math.random()*keylist.length));
	return temp;
}

function roundnumber(n, d)
{
    n = n - 0;
    if (d == null) d = 2;
    var f = Math.pow(10, d);
    n += Math.pow(10, - (d + 1));
    n = Math.round(n * f) / f;
    n += Math.pow(10, - (d + 1));
    n += '';
    return d == 0 ? n.substring(0, n.indexOf('.')) :  n.substring(0, n.indexOf('.') + d + 1);
}

function checkAllLink(checkboxes,flag,link,addlink) {
	var newValue=true;
	if (addlink != false) {
	   var addlink_tag = document.getElementById(addlink);
	}
    if(flag.value=='true') {
		newValue=true;
        flag.value='false';
        link.innerHTML='Uncheck All';
        if (addlink != false) {
            addlink_tag.innerHTML='Uncheck All';
        }
    } else {
		newValue=false;
        flag.value='true';
        link.innerHTML='Check All';
        if (addlink != false) {
            addlink_tag.innerHTML='Check All';
        }
    }

	for(var i=0;i<checkboxes.length;i++) { checkboxes[i].checked = newValue; }
	return true;
}
