function formSub(fName) {
    var submit = true;
    if (fName == 'search_form') { 
        submit = check_srch('reg');
    }
    if (submit) {
        eval("document." + fName + ".submit();");
    }
}

function p(url,wid,hei) { 
   newwin = window.open(url,'newwin','status=no,resizable=yes,scrollbars=yes,width='+wid+',height='+hei+',left=20,top=20');
   newwin.window.focus();
} 

function srch(srch_whr) {
    var srch_str;
    var cmre;
    if (srch_whr == 'top') {
        cmre     = "cm_re=Search*Top*Top";
        srch_str = escape(document.getElementById('topsrchstr').value); 
    } else if (srch_whr == 'mdl') {
        cmre     = "cm_re=Search*Middle*Middle";
        srch_str = escape(document.getElementById('mdlsrchstr').value);
    } else {
        cmre     = "cm_re=Search*Left*Left";
        srch_str = escape(document.getElementById('regsrchstr').value);
        if (document.getElementById('grpselect')) {
        var urlparam = document.getElementById('grpselect').name;
        var opts = document.getElementById('grpselect').options;
        for (var i=0; i<opts.length; i++) {
            if (opts[i].selected) {
                if (opts[i].value != '') {
                    srch_str += "&"+urlparam+"="+opts[i].value;
                    break;
                }
            }
        }
        }
    }
    if (check_srch(srch_whr)) {
        do_p = false;
        if(typeof cmCreateManualLinkClickTag == 'function') {
            cmCreateManualLinkClickTag('/search/?'+cmre);
        }
        window.location.href = "/search/?v="+srch_str;
    }
}

function check_srch(srch_whr) {
   var emptyString = /^\s*$/;
   var srch_str;
   var descString = /Enter Item # or Keyword\./;
   if (srch_whr == 'reg') { 
      srch_str = document.getElementById('regsrchstr').value; 
   } else if (srch_whr == 'mdl') {
      srch_str = document.getElementById('mdlsrchstr').value; 
   } else { 
      srch_str = document.getElementById('topsrchstr').value; 
   }
   if (emptyString.test(srch_str) || descString.test(srch_str)) {
      alert('Please enter an item # or keyword in the search box.');
      if (srch_whr == 'reg') { 
         document.getElementById('regsrchstr').focus(); 
      } else if (srch_whr == 'mdl') {
         document.getElementById('mdlsrchstr').focus(); 
      } else { 
         document.getElementById('topsrchstr').focus(); 
      }
      return false;
   }
   return true;
}

function checkenter(e,whr) {
    var e = e ? e : window.event;
    var characterCode = e.which ? e.which : e.keyCode;
    if (characterCode == 13) {
        if (whr == 'raf') {
            rafgo();
        } else if ((whr == 'emailsignup') || (whr == 'emailsignup_btn')) {
            emailgo(whr);
        } else {
            srch(whr);
        }
    }
}

function emailgo(whr) {
    if (!whr){
      whr = "emailsignup";
    }
    do_p = false;
    var email_addr = escape(document.getElementById(whr).value);
    window.location.href = "/101/?email="+email_addr;
    //window.location.href = "/pages/?page_id=256&id=8&?email="+email_addr;
}

function emailgo_e() {
    do_p = false;
    var email_addr = escape(document.getElementById('emailsignup').value);
    window.location.href = "/email/?email="+email_addr;
}

function rafgo() {
    do_p = false;
    var email_one = escape(document.getElementById('raf_one').value);
    var email_two = escape(document.getElementById('raf_two').value);
    window.location.href = "/raf/?email="+email_one+"&f_email="+email_two;
}


function addBookmark(title,url) {
    url = "http://"+url+"/";
    if (window.sidebar) {
        window.sidebar.addPanel(title, url,"");
    } else if( document.all ) {
        window.external.AddFavorite( url, title);
    } else {
        alert("Our apologies - We are unable to add "+title+" to your list of bookmarked web sites");
    }
}

function toggle(obj, action) {
    var el = document.getElementById(obj);
    if ( el.style.display != 'none' ) {
        el.style.display = 'none';
        if (action == 'chgImg')
        document['toggle_icon'].src='/images/plus.gif';
    }
    else {
        el.style.display = '';
        if (action == 'chgImg')
        document['toggle_icon'].src='/images/minus.gif';
    }
}

/***old - ajax**/
var status = 1;

function loadXMLDoc(url) {
    if (status == 0) {
        setTimeout("loadXMLDoc('"+url+"');",50);
    } else {

    status = 0;
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
    }
}

function processReqChange() {
    // only if req shows "complete"
    if (req.readyState == 4) {
       status = 1;
       // only if "OK"
       if (req.status == 200) {
          response  = req.responseXML.documentElement;
          method = response.getElementsByTagName('method')[0].firstChild.data;
          eval(method + '(response)');
       } else {
          alert("There was a problem processing your request. Please try again.");
       }
    }
}

/***product page ptabs and image preview and testimonial tab**/

$(document).ready(function(){
   $('#p-tabs li a').click(function(){
   $('a').removeClass('hot');
   $(this).addClass('hot');
   var rel = $(this).attr('rel');
   var cat = "TAB:"+rel;
   var pid = this.id;
   /*hide all tabs*/
   $('#p-review').hide();
   $('#p-detail').hide();
   $('#p-experts').hide();
   $('#p-activities').hide();
   $('#p-bought').hide();
   $('#p-others').hide();
   loadContent();
   function loadContent(){
     switch(pid){
      case "p1":
         cmCreatePageElementTag("Product Details", ''+cat+'');
         $('#p-detail').show();
         break;
      case "p2":
         cmCreatePageElementTag("Product Review", ''+cat+'');
         $('#p-review').show();
         break;
      case "p3":
         cmCreatePageElementTag("Experts Suggest", ''+cat+'');
         $('#p-experts').show();
         break;
      case "p4":
         cmCreatePageElementTag("Contact Us", ''+cat+'');
         $('#p-others').show();
         break;
      case "p5":
         cmCreatePageElementTag("Activities Ideas", ''+cat+'');
         $('#p-activities').show();
         break;
      case "p6":
         cmCreatePageElementTag("Others Bought", ''+cat+'');
         $('#p-bought').show();
         break;
		case "t1":
			$('#testi').load("/pages/testimonial.php");
			break;
		case "t2":
			$('#testi').load("/pages/testimonial.php", {"inst" : "yes"});
			break;
      }
    }

  });
});
function getTabPos(){
   $('#p-tabs li a').removeClass('hot');
   $('#p2 a').addClass('hot');
   $('#p-box').hide();
   $('#p-detail').hide();
   $('#p-experts').hide();
   $('#p-activities').hide();
   $('#p-bought').hide();
   $('#p-others').hide();
   $('#p-review').show();
   $('#p-box').show();
   window.location="#p2";
}


function goDetail(){
   $('#p-tabs li a').removeClass('hot');
   $('#p1 a').addClass('hot');
   $('#p-box').hide();
   $('#p-review').hide();
   $('#p-experts').hide();
   $('#p-activities').hide();
   $('#p-bought').hide();
   $('#p-others').hide();
   $('#p-detail').show();
   $('#p-box').show();
   window.location="#p1";
}

this.imagePreview = function(){
      xOffset = 10;
      yOffset = 30;

   $("a.preview").click(function(){
      return false;
   });
   $("a.preview").hover(function(e){
      this.t = this.title;
      this.title = "";
      var c = (this.t != "") ? "<br/>" + this.t : "";
      $("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");
      $("#preview")
         .css("top",(e.pageY - xOffset) + "px")
         .css("left",(e.pageX + yOffset) + "px")
         .fadeIn("fast");
    },
   function(){
      this.title = this.t;
      $("#preview").remove();
    });
      $("a.preview").mousemove(function(e){
      $("#preview")
         .css("top",(e.pageY - xOffset) + "px")
         .css("left",(e.pageX + yOffset) + "px");
   });
};

$(document).ready(function(){
   imagePreview();
});

function onSelectChangeSite(){
   var dropdown = document.getElementById("snssite");
   var index = dropdown.selectedIndex;
   var ddVal = dropdown.options[index].value;

	var current = window.location;
	var re1 = /\?custm/;
   var re2 = /\?/;

	if (re1.test(current))
      window.location = "?custm=" + ddVal;
	else if (re2.test(current))
		window.location = current + "&custm=" + ddVal;
   else
      window.location = "?custm=" + ddVal;
   
}

