<!--
//
var async = true;
var def_country = 'US'; // Default Country
var alt_country = 'CA'; // Alternate Country
var ALERT_TITLE = "Attention!";
var ALERT_BUTTON_TEXT = "Ok";
var ns = (document.layers);
var ie = (document.all);
var w3 = (document.getElementById);
var form;
var i;
var payment_showing;

if (navigator.appVersion.indexOf("MSIE") != -1) {
    var bName = 'MSIE';
    var temp = navigator.appVersion.split("MSIE");
    var bVer = parseFloat(temp[1]);
}
else {
    var bName = navigator.appName;
    var bVer = parseFloat(navigator.appVersion);
}

function getstamp(){
    date = new Date();
    return date.getTime();
}

function loadDoc(url, postdata, cb_func){
    var req;
    req = false;
    if (window.XMLHttpRequest) {
        try {
            req = new XMLHttpRequest();
        } 
        catch (e) {
            req = false;
        }
    }
    else 
        if (window.ActiveXObject) {
            try {
                req = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e) {
                try {
                    req = new ActiveXObject("Microsoft.XMLHTTP");
                } 
                catch (e) {
                    req = false;
                }
            }
        }
    if (req) {
        req.open("POST", url, async);
        req.onreadystatechange = function(){
            if (req.readyState == 4 && req.status == 200 && cb_func != "") {
                eval("cb_" + cb_func + "(req.responseText);");
            }
        }
        req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        req.send(postdata);
    }
}

function fillDIV(inner_cont, inner_layer, append){
    if (w3) 
        var e = document.getElementById(inner_layer);
    else 
        if (ie) 
            var e = document.all[inner_layer];
        else 
            if (ns) 
                var e = document.layers[inner_layer];
    
    if (append == 1) {
        e.innerHTML += inner_cont;
    }
    else {
        e.innerHTML = inner_cont;
    }
}

function selectAll(frm, item){
    var e = frm.elements;
    var re = new RegExp("^" + item);
    for (i = 0; i < e.length; i++) {
        if (e[i].id != '' && e[i].id.match(re)) {
            e[i].checked = true;
        }
    }
}

function del_event(id){
    if (jsconfirm()) 
        location.href = 'index.php?l=account&d=deletereg&id=' + id + '&tab=5';
}

function jsconfirm(note){
    if (note == undefined) 
        note = 'Are you sure you want to complete this action?';
    if (confirm(note)) {
        return true;
    }
    else {
        return false;
    }
}

function cb_updatePrice(txt){
    var result = txt.split("||");
    if (document.getElementById("product_price")) 
        document.getElementById("product_price").innerHTML = result[0];
    if (document.getElementById("list_price")) 
        document.getElementById("list_price").innerHTML = result[1];
    if (document.getElementById("sale_price")) 
        document.getElementById("sale_price").innerHTML = result[2];
    if (document.getElementById("product_price" + result[3])) 
        document.getElementById("product_price" + result[3]).innerHTML = result[0];
    if (document.getElementById("sale_price" + result[3])) 
        document.getElementById("sale_price" + result[3]).innerHTML = result[2];
}

function cb_getResult(txt){
    fillDIV(txt, 'message');
}

function cb_revResult(txt){
    eval(txt);
}

function cb_payResult(txt){
    if (txt != "ok") 
        fillDIV(txt, 'message');
    else 
        document.forms['payment'].submit();
}

function rowVisibility(strVisibility, intRowIndex, id){
    if (navigator.product == "Gecko" && navigator.productSub && navigator.productSub > "20041010" && (navigator.userAgent.indexOf("rv:1.8") != -1 || navigator.userAgent.indexOf("rv:1.9") != -1)) {
        document.getElementById(id).rows[intRowIndex].style.visibility = strVisibility;
    }
    else 
        if (strVisibility == "visible") {
            if (document.all && document.compatMode && document.compatMode == "CSS1Compat" && !window.opera) {
                document.getElementById(id).rows[intRowIndex].style.display = "block";
            }
            else 
                if (document.getElementById && document.getElementById(id).rows) {
                    document.getElementById(id).rows[intRowIndex].style.display = "table-row";
                }
        }
        else 
            if (strVisibility == "collapse") {
                document.getElementById(id).rows[intRowIndex].style.display = "none";
            }
}

function cc_type(val){
    if (val == 'Solo' || val == 'Switch') {
        rowVisibility('visible', 5, 'cc_table');
        rowVisibility('visible', 6, 'cc_table');
    }
    else {
        rowVisibility('collapse', 5, 'cc_table');
        rowVisibility('collapse', 6, 'cc_table');
    }
}

function clearMessages(){
    fillDIV('', 'message');
}

function updatePrice(frm, url){
    var e = frm.elements;
    var opts = [];
    var post;
    for (i = 0; i < e.length; i++) {
        if (e[i].type == 'select-one') {
            opts.push(e[i].name + "=" + e[i].value);
        }
        if ((e[i].type == 'radio' || e[i].type == 'checkbox') && e[i].checked) {
        
            opts.push(e[i].name + "=" + e[i].value);
        }
    }
    post = opts.join("&");
    loadDoc(url, post, 'updatePrice');
}

function check_payment(url){
    var e = document.forms['payment'].elements;
    var data = [];
    var post;
    for (i = 0; i < e.length; i++) 
        data.push(e[i].name + "=" + e[i].value);
    post = data.join("&");
    loadDoc(url, post, 'payResult');
}

function check_quickcheckout(url){
    var e = document.forms['customer_info'].elements;
    var data = [];
    var post;
    for (i = 0; i < e.length; i++) {
        if ((e[i].type == 'radio' || e[i].type == 'checkbox') && e[i].checked) {
            data.push(e[i].name + "=" + e[i].value);
        }
        if (e[i].type != 'radio' && e[i].type != 'checkbox') 
            data.push(e[i].name + "=" + e[i].value);
    }
    post = data.join("&");
    loadDoc(url, post, 'revResult');
}

function edit_event(id){
    loadDoc('index.php?l=edit_registry', 'id=' + id, 'revResult');
}


function hold_order(){
    loadDoc('checkout.php?l=hold_order', '', 'revResult');
}

function ajaxPost(frm, url, result){
    if (!result) 
        result = 'getResult';
    var e = frm.elements;
    var data = [];
    var i;
    var post;
    for (i = 0; i < e.length; i++) {
        if ((e[i].type == 'checkbox' && e[i].checked) || e[i].type != 'checkbox') {
            data.push(e[i].name + "=" + e[i].value);
        }
    }
    post = data.join("&");
    loadDoc(url, post, result);
}

function pause(form_name, perform, message){
    form = document.forms[form_name];
    if (message != null) 
        var mess = '&mess=' + escape(message);
    else 
        var mess = '';
    ajaxPost(form, 'index.php?l=loading' + mess, 'revResult');
    setTimeout("ajaxPost(form, '" + perform + "', 'revResult')", 2000);
}

function toggle_country(value, type){
    if (value != def_country && value != alt_country && value != "") {
        document.getElementById(type + '_other').style.display = 'inline';
        document.getElementById(type + '_state').style.display = 'none';
        document.forms['customer_info'].elements['userinfo[' + type + '_oset]'].value = '1';
    }
    else {
        document.getElementById(type + '_other').style.display = 'none';
        document.getElementById(type + '_state').style.display = 'inline';
        document.forms['customer_info'].elements['userinfo[' + type + '_oset]'].value = '0';
    }
}

function toggle_payment(name){
    document.getElementById(name).style.display = 'inline';
    if (payment_showing != null) 
        document.getElementById(payment_showing).style.display = 'none';
    payment_showing = name;
}

function reset_forms(items, form){
    for (x in items) {
        var titem = items[x];
        var fitem = document.forms[form].elements[titem];
        if (fitem.selectedIndex != null) 
            fitem.selectedIndex = 0;
        else 
            fitem.value = '';
    }
}

function bill_to_ship(form){
    if (form.elements['userinfo[same]'].checked) {
        form.elements['userinfo[ship_first_name]'].value = form.elements['userinfo[bill_first_name]'].value;
        form.elements['userinfo[ship_last_name]'].value = form.elements['userinfo[bill_last_name]'].value;
        form.elements['userinfo[ship_company_name]'].value = form.elements['userinfo[bill_company_name]'].value;
        form.elements['userinfo[ship_address1]'].value = form.elements['userinfo[bill_address1]'].value;
        form.elements['userinfo[ship_address2]'].value = form.elements['userinfo[bill_address2]'].value;
        form.elements['userinfo[ship_city]'].value = form.elements['userinfo[bill_city]'].value;
        form.elements['userinfo[ship_state]'].selectedIndex = form.elements['userinfo[bill_state]'].selectedIndex;
        form.elements['userinfo[ship_other]'].value = form.elements['userinfo[bill_other]'].value;
        form.elements['userinfo[ship_zip]'].value = form.elements['userinfo[bill_zip]'].value;
        form.elements['userinfo[ship_country]'].selectedIndex = form.elements['userinfo[bill_country]'].selectedIndex;
        toggle_country(form.elements['userinfo[ship_country]'].value, 'ship');
    }
}

function popupImage(full_url, url){
    window.open(full_url + 'index.php?l=product_images&' + url, 'popupImage', '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');
}
function popupImage2 (full_url, url, width, height) {
	 window.open(full_url+'index.php?l=product_images&' + url, 'popupImage','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=' + width + ',height=' + height + ',screenX=150,screenY=150,top=150,left=150');
}


function reload_image(prefix, num){
    var stamp = getstamp();
    document.images['verify_image' + num].src = prefix + 'include/classes/class.iverify.php?' + stamp;
    if (bName == "MSIE" && bVer == 6) {
        alert('Image Reloaded Successfully!');
    }
}

function toggle_div(fname){
    if (document.getElementById(fname).style.display == 'block') 
        document.getElementById(fname).style.display = 'none';
    else 
        document.getElementById(fname).style.display = 'block';
}

$(document).ready(function(){
    $('#search-submit').click(function(){
        $('#searchForm').submit();
    });
    $('#search-query').click(function(){
        if ($('#search-query').val() == 'Product Search') {
            $('#search-query').val('');
        }
        else {
        }
    });
    
    $('#search-query').focus(function(){
        if ($('#search-query').val() == 'Product Search') {
            $('#search-query').val('');
        }
        else {
        }
    });
    
    
    
});
function lightboxView(imgUrl){
    $('#lightbox > img').attr('src', imgUrl);
    
  $('#lightbox > img').load(function(){ 
        // Remove attributes in case img-element has set width and height
        $('#lightbox > img').removeAttr("width").removeAttr("height").css({
            width: "",
            height: ""
        }); 
         // Remove css dimensions as well
       width = this.width;
        height = this.height;
        
		
		 var viewportwidth;
 var viewportheight;

      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight

 

	 var wheight = (viewportheight / 2)
		
		
		
        left = (width / 2);
        var top = (height / 2);
		if (top > wheight) {  var height = (wheight - 100); }
		else {
			var height = top;
		}
        style = 'margin-left: -'+ (width / 2) +'px; margin-top: -'+ height +'px;';
      $('#lightbox').attr('style', style);
        $('#lightbox').show('slow');
      });    
    
}

function showcustomertype(id) {
	document.getElementById('returningcustomer').style.display='none';
	document.getElementById('newcustomer').style.display='none';
	document.getElementById('new_acc').style.display='none';
	
	if (id==1)
	{
		document.getElementById('newcustomer').style.display='block';
		document.getElementById('new_acc').style.display='block';
		
	} else if(id==2) {
		document.getElementById('returningcustomer').style.display='block';
	}
}

function showcustomerinfo(id) {
	document.getElementById('customerinfosection').style.display='block';
	if (id==0)
	{
		if (document.getElementById('eventdate')) {
			document.getElementById('customerinfosection').style.display='none';
		}
	} else if(id==1) {
		document.getElementById('ShowCustomerInfo').style.display='none';
	}
		
}

function check_date(field)
{
  // regular expression to match required date format
  re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;

  if(field.value != '' && !field.value.match(re)) {
    alert("Invalid date format: " + field.value);
    field.focus();
    return false;
  }

  return true;
}

function check_date_entered(value)
{
  // regular expression to match required date format
  re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
alert(value);
  if(value != '' && !value.match(re)) {   
    return false;
  }

  return true;
}

function isDate (year, month, day) {
	// month argument must be in the range 1 - 12
	month = month - 1; // javascript month range : 0- 11
	if (month >= 0 && day > 0) {
		var tempDate = new Date(year,month,day);
		if ( (getYear(tempDate.getYear()) == year) &&
		(month == tempDate.getMonth()) &&
		(day == tempDate.getDate()) )
		return true;
		else
		return false
	} else {
		return false;
	}
	
}

function getYear(d) {
	return (d < 1000) ? d + 1900 : d;
	}

function changedate(id) { 
	
	var month = document.getElementById("month");
	var day = document.getElementById("day");	
	var year = document.getElementById("year");	
	
	var value = month.options[month.selectedIndex].value + '/' + day.options[day.selectedIndex].value + '/' + year.options[year.selectedIndex].value;
	
	if (isDate(year.options[year.selectedIndex].value, month.options[month.selectedIndex].value, day.options[day.selectedIndex].value)) {
		document.getElementById('ShowCustomerInfo').disabled = false;
		document.getElementById('NecessityYes').checked = true;
						
	} else {
		document.getElementById('ShowCustomerInfo').disabled = true;
	}
};	
//-->

