function Mod10(ccNumb)
{  // v2.0
    var valid = "0123456789"  // Valid digits in a credit card number
    var len = ccNumb.length;  // The length of the submitted cc number
    var iCCN = parseInt(ccNumb);  // integer of ccNumb
    var sCCN = ccNumb.toString();  // string of ccNumb
    sCCN = sCCN.replace (/^s+|s+$/g,'');  // strip spaces
    var iTotal = 0;  // integer total set at zero
    var bNum = true;  // by default assume it is a number
    var bResult = false;  // by default assume it is NOT a valid cc
    var temp;  // temp variable for parsing string
    var calc;  // used for calculation of each digit

    // Determine if the ccNumb is in fact all numbers
    for (var j=0; j<len; j++) {
        temp = "" + sCCN.substring(j, j+1);
        if (valid.indexOf(temp) == "-1"){bNum = false;}
    }

    // if it is NOT a number, you can either alert to the fact, or just pass a failure
    if(!bNum){
        /*alert("Not a Number");*/bResult = false;
    }

    // Determine if it is the proper length
    if((len == 0)&&(bResult)){  // nothing, field is blank AND passed above # check
        bResult = false;
    } else{  // ccNumb is a number and the proper length - let's see if it is a valid card number
        if(len >= 15){  // 15 or 16 for Amex or V/MC
            for(var i=len;i>0;i--){  // LOOP throught the digits of the card
                calc = parseInt(iCCN) % 10;  // right most digit
                calc = parseInt(calc);  // assure it is an integer
                iTotal += calc;  // running total of the card number as we loop - Do Nothing to first digit
                i--;  // decrement the count - move to the next digit in the card
                iCCN = iCCN / 10;                               // subtracts right most digit from ccNumb
                calc = parseInt(iCCN) % 10 ;    // NEXT right most digit
                calc = calc *2;                                 // multiply the digit by two
                // Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
                // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
                switch(calc){
                    case 10: calc = 1; break;       //5*2=10 & 1+0 = 1
                    case 12: calc = 3; break;       //6*2=12 & 1+2 = 3
                    case 14: calc = 5; break;       //7*2=14 & 1+4 = 5
                    case 16: calc = 7; break;       //8*2=16 & 1+6 = 7
                    case 18: calc = 9; break;       //9*2=18 & 1+8 = 9
                    default: calc = calc;           //4*2= 8 &   8 = 8  -same for all lower numbers
                }
                iCCN = iCCN / 10;  // subtracts right most digit from ccNum
                iTotal += calc;  // running total of the card number as we loop
            }  // END OF LOOP
            if ((iTotal%10)==0){  // check to see if the sum Mod 10 is zero
                bResult = true;  // This IS (or could be) a valid credit card number.
            } else {
                bResult = false;  // This could NOT be a valid credit card number
            }
        }
    }
    // change alert to on-page display or other indication as needed.
    if(bResult) {
        //alert("This IS a valid Credit Card Number!");
    }
    if(!bResult){
        //alert("This is NOT a valid Credit Card Number!");
    }
    return bResult; // Return the results
}
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 Mod10(str);
	} else {
	    return false;
	}
}

function IsNumeric(strString)
{
    var strValidChars = "0123456789";
    var strChar;
    var blnResult = true;
    if (strString.length == 0) return true;
    for (i = 0; i < strString.length && blnResult == true; i++) {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;
        }
    }
    return blnResult;
}

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;
}