function checkQty(formObj) {
        if (formObj.op1.value == "" || formObj.op1.value == "0") {
                formObj.op1.value = "1";
        }
        if(formObj.op2){
           if (formObj.op2.value == "" || formObj.op2.value == "0") {
                 formObj.op2.value = "10";
           }
        }
}

function openDetails(pid) {
        window.open("index.php?page=show_prod&pid="+pid,"DetailsProd","width=420,height=700,scrollbars=yes,status=yes");
}
/* sharetool functions */

function showHideShareTool (id1, id2) {

        if (document.getElementById) {
                if (document.getElementById(id1).className == 'hide') {
                        document.getElementById(id1).className = 'show';
                        document.getElementById(id2).className = 'sharebox';
                } else {
                        document.getElementById(id1).className = 'hide';
                        document.getElementById(id2).className = 'share';
                }
        }
        return false;
}

function blogPostShare(site, keywords, pubdate, theID) {

        var title;
        var description;
        var popUpUrl;
        var byline;
        var formCtl;
        var formID;
        var section;

        title = '';
        description = '';
        popUpUrl = '';
        byline = '';
        section = '';

        formID = 'emailThis_' + theID;

        if(document.getElementById) {
                formCtl = document.getElementById(formID);
                if(formCtl) {
                        description = formCtl.description.value;
                        title = formCtl.title.value;
                        popUpUrl = formCtl.url.value;
                        byline = 'By ' + formCtl.author.value;
                        section = formCtl.section.value;
                }
        }

        switch (site) {
                case "newsvine":
                postPopUp('http://www.newsvine.com/_wine/save?ver=2&popoff=0&aff=JW_Marriott_Camelback_INN&t=' + keywords + '&e=' + description + '&h=' + title + '&u=' + popUpUrl, 'newsvine', 'toolbar=0,status=0,height=445,width=650,scrollbars=yes,resizable=yes');
                s_code_linktrack('Article-Tool-Share-Newsvine');
                break;
                case "facebook":
                postPopUp('http://www.facebook.com/sharer.php?u=' + popUpUrl + '&t=' + title, 'facebook', 'toolbar=0,status=0,height=436,width=646,scrollbars=yes,resizable=yes');
                s_code_linktrack('Article-Tool-Share-Facebook');
                break;
                case "digg":
                postPopUp('http://digg.com/remote-submit?phase=2&url=' + popUpUrl + '&title=' + title + '&bodytext=' + description, 'digg', 'toolbar=0,status=0,height=450,width=650,scrollbars=yes,resizable=yes');
                s_code_linktrack('Article-Tool-Share-Digg');
                break;
                case "permalink":
                postPopUp('http://www.nytimes.com/export_html/common/new_article_post.html?url=' + popUpUrl + '&title=' + title+ '&summary=' + description + '&section=' + section + '&pubdate=' + pubdate + '&byline=' + byline, 'permalink', 'toolbar=0,status=0,height=410,width=490,scrollbars=yes,resizable=no');
                s_code_linktrack('Article-Tool-Share-Permalink');
                break;
                case "delicious":
                postPopUp('http://del.icio.us/post?v=4&partner=JW_Marriott_Camelback_INN&noui&jump=close&url=' + popUpUrl + '&title=' + title + '&bodytext=' + description, 'delicious', 'toolbar=0,status=0,height=400,width=700,scrollbars=yes,resizable=no');
                s_code_linktrack('Article-Tool-Share-Delicious');
                break;

                case "mixx":
                try {
                        var otherParams =
                        '&title='       + title
                        + '&description=' + description
                        + '&tags='        + keywords
                        + '&partner='     + 'JW_Marriott_Camelback_INN';
                        postPopUp(
                        'http://mini.mixx.com/submit/story'
                        + '?page_url='    + popUpUrl
                        + otherParams,
                        'mixx',
                        'toolbar=0,status=0,height=550,width=700,scrollbars=yes,resizable=no'
                        );
                } catch(e) {
                        postPopUp(
                        'http://mini.mixx.com/submit/story'
                        + '?page_url='    + popUpUrl
                        + '&title='       + title
                        + '&partner='     + 'JW_Marriott_Camelback_INN'
                        ,
                        'mixx',
                        'toolbar=0,status=0,height=550,width=700,scrollbars=yes,resizable=no'
                        );
                }
                s_code_linktrack('Article-Tool-Share-Mixx');
                break;

                case "linkedin":
                //http://www.linkedin.com/shareArticle?mini=true&url={articleUrl}&title={articleTitle}&summary={articleSummary}&source={articleSource}
                postPopUp(
                'http://www.linkedin.com/shareArticle?mini=true'
                + '&url='         + popUpUrl
                + '&title='       + title
                + '&summary='     + description
                + '&source='      + 'JW Marriott Camelback INN'
                ,
                'Linkedin',
                'toolbar=0,status=0,height=550,width=700,scrollbars=yes,resizable=no'
                );
                s_code_linktrack('Article-Tool-Share-LinkedIn');
                break;
        }
}

function postPopUp(url, name, params) {
        var win = window.open(url, name, params);
        if(win) {
                win.focus();
        }
}


/* sharetool functions end */


// validates that the field value string has one or more characters in it
function isNotEmpty(elem) {
        var str = elem.value;
        var re = /.+/;
        if(!str.match(re)) {
                alert("Please fill in the required field.");
                setTimeout("focusElement('" + elem.form.name + "', '" + elem.name + "')", 0);
                return false;
        } else {
                return true;
        }
}
//validates that the entry is a positive or negative number
function isNumber(elem) {
        var str = elem.value;
        var re = /^[-]?\d*\.?\d*$/;
        str = str.toString();
        if (!str.match(re)) {
                alert("Enter only numbers into the field.");
                setTimeout("focusElement('" + elem.form.name + "', '" + elem.name + "')", 0);
                return false;
        }
        return true;
}
// validates that the entry is 16 characters long
function isLen16(elem) {
        var str = elem.value;
        var re = /\b.{16}\b/;
        if (!str.match(re)) {
                alert("Entry does not contain the required 16 characters.");
                setTimeout("focusElement('" + elem.form.name + "', '" + elem.name + "')", 0);
                return false;
        } else {
                return true;
        }
}
// validates that the entry is formatted as an e-mail address
function isEMailAddr(elem) {
        var str = elem.value;
        var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
        if (!str.match(re)) {
                alert("Verify the e-mail address format.");
                setTimeout("focusElement('" + elem.form.name + "', '" + elem.name + "')", 0);
                return false;
        } else {
                return true;
        }
}
// validate that the user made a selection other than default
function isChosen(select) {
        if (select.selectedIndex == 0) {
                alert("Please make a choice from the list.");
                return false;
        } else {
                return true;
        }
}

// validate that the user has checked one of the radio buttons
function isValidRadio(radio) {
        var valid = false;
        for (var i = 0; i < radio.length; i++) {
                if (radio[i].checked) {
                        return true;
                }
        }
        alert("Make a choice from the radio buttons.");
        return false;
}

function focusElement(formName, elemName) {
        var elem = document.forms[formName].elements[elemName];
        elem.focus();
        elem.select();
}

function isPhone(string) {
        if (string.search(/^[0-9][0-9][0-9]\-[0-9][0-9][0-9]\-[0-9][0-9][0-9][0-9]$/) != -1){
                return true;
        }else{
                document.form2.phone1.focus()
                alert("You must supply a valid phone number.");
                return false;
        }
}

function checkmail(form) {
      if (isNotEmpty(form.semail)) {
              if (isEMailAddr(form.semail)) {
                    if (isNotEmpty(form.remail)) {
                                  return true;
                    }
              }
      }
      return false;
}
