$(document).ready(function($){


	if ($('#subscr_ch').length > 0)
	{
		if (!$('#subscr_ch').attr('checked')) $('#subscr_btn').css('opacity', '0.3').attr('disabled', true);
		else $('#subscr_btn').css('opacity', '1').removeAttr('disabled');
		$('#subscr_ch').bind('click', function(e)
		{
				if ($(e.target).attr('checked')) $('#subscr_btn').css('opacity', '1').removeAttr('disabled');
				else $('#subscr_btn').css('opacity', '0.3').attr('disabled', true);

		});
	}

}); 

function openDetails(url)
  {
    var url_name = new Date().getTime();
    window.open(url,url_name,"width=1000,height=750,copyhistory=no,status=yes,directories=no,menubar=yes,location=no,resizable=yes,scrollbars=yes,toolbar=no");
  }
function openChat(url)
  {
    window.open(url,'chat',"width=600,height=480,copyhistory=no,status=yes,directories=no,menubar=yes,location=no,resizable=yes,scrollbars=yes,toolbar=no");
  }

function lout()
{
	document.forms['logout'].submit();
}
function toggleRemind()
{
	$('#remindForm').show();
}
//-----------------------------------------------------------------------------------------------------------------------------------------
function image(url, w, h)
{
		var newWin = window.open('','img',"width=" + w + ",height=" + h + ",copyhistory=no,status=no,directories=no,menubar=no,location=no,resizable=yes,scrollbars=no,toolbar=no");
		if (newWin)
		 {
			newWin.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
			newWin.document.writeln('<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title></title></head><body style="margin: 0px; padding: 0px;">');
			newWin.document.writeln('<a href="javascript:self.close();" title="Click to close"><img src="' + url + '" border="0" alt="Click to close" /></a>');
			newWin.document.writeln('</body></html>');
			newWin.document.close();
			newWin.focus();
		 }
		return; 
}
//-----------------------------------------------------------------------------------------------------------------------------------------
function copyShipping(el)
{
	if (el.checked)
	{
		document.forms['cout'].elements['ship[fname]'].value = document.forms['cout'].elements['bill[fname]'].value;
		document.forms['cout'].elements['ship[lname]'].value = document.forms['cout'].elements['bill[lname]'].value;
		document.forms['cout'].elements['ship[comp_title]'].value = document.forms['cout'].elements['bill[comp_title]'].value;
		document.forms['cout'].elements['ship[address1]'].value = document.forms['cout'].elements['bill[address1]'].value;
		document.forms['cout'].elements['ship[address2]'].value = document.forms['cout'].elements['bill[address2]'].value;
		document.forms['cout'].elements['ship[city]'].value = document.forms['cout'].elements['bill[city]'].value;
		document.forms['cout'].elements['ship[zip]'].value = document.forms['cout'].elements['bill[zip]'].value;
		var state = document.forms['cout'].elements['bill[state]'].options[document.forms['cout'].elements['bill[state]'].selectedIndex].value;
		var country = document.forms['cout'].elements['bill[country]'].options[document.forms['cout'].elements['bill[country]'].selectedIndex].value;
		var optLen = document.forms['cout'].elements['ship[state]'].options.length;
		for (i = 0; i < optLen; i++)
		{
			if (document.forms['cout'].elements['ship[state]'].options[i].value == state) {document.forms['cout'].elements['ship[state]'].options[i].selected = true; break;}
		}
		var optLen = document.forms['cout'].elements['ship[country]'].options.length;
		for (i = 0; i < optLen; i++)
		{
			if (document.forms['cout'].elements['ship[country]'].options[i].value == country) {document.forms['cout'].elements['ship[country]'].options[i].selected = true; break;}
		}
	}
}
//-----------------------------------------------------------------------------------------------------------------------------------------
function checkoutSendForm(frm,act)
{
	
	//'checkoutID',
	$('#storeLoading').dialog('open');
	//AlerterObject = new Alerter(300, 200, 'storeLoading', {});
	var qStr = act + "&rnd=" + new Date().getTime();
	var serializedForm = $("#"+frm).serialize() + '&return=html';
	//var serializedForm = Form.serialize(frm);
	
	$.post(qStr, serializedForm,
     function(transport){
		$('#checkoutID').html(transport);
		$('#storeLoading').dialog('close');
     }, "html");
	/*
	new Ajax.Request(qStr, {method: 'post', postBody: 'return=html'+ '&' + serializedForm, onSuccess: function(transport){
																											   $('checkoutID').innerHTML = transport.responseText;
																											   AlerterObject.destroy();
																											   }});	
	*/
}
//-----------------------------------------------------------------------------------------------------------------------------------------
function change_cc_dataSendForm(frm,act)
{
	$('#checkoutErrorID').html('');$('#checkoutID').html('');
	$('#storeLoading').dialog('open');
	var qStr = act + "&rnd=" + new Date().getTime();
	var serializedForm = $("#"+frm).serialize() + '&return=json';
	$.post(qStr, serializedForm,
     function(jsonObj){
		if (jsonObj.success == 1) {
			$('#checkoutID').html(jsonObj.responseText);
			if ((op = window.opener) != false) op.location.reload();
			window.close();
		} else {
			var errStr = '<ul class="errlist">';
			$.each(jsonObj.errors, function(i, k){errStr += '<li style="color: #CC0000">' + k + '</li>';});
			errStr += '</ul>';	
			$('#checkoutErrorID').html(errStr);
		}
		$('#storeLoading').dialog('close');
     }, "json");
}
//-----------------------------------------------------------------------------------------------------------------------------------------
function remindpassSendForm(act)
{
	
	//'checkoutID',
	$('#storeLoading').dialog('open');
	//AlerterObject = new Alerter(300, 200, 'storeLoading', {});
	var qStr = act + "&rnd=" + new Date().getTime();
	//var serializedForm = Form.serialize('remindpass');
	var serializedForm = $("#remindpass").serialize() + '&return=json';
	
	$.post(qStr, serializedForm,
     function(jsonObj){
		if (jsonObj.success == 1) {
			$('#remindForm').html(jsonObj.responseText);
		}
		$('#storeLoading').dialog('close');
     }, "json");

	/*
	new Ajax.Request(qStr, {method: 'post', postBody: 'return=json'+ '&' + serializedForm, onSuccess: function(transport){
																											   var jsonObj = eval("("+transport.responseText+")");
																											   if (jsonObj.success == 1)
																											   {
																												   $('remindForm').innerHTML = jsonObj.responseText;
																											   }
																											   $('#storeLoading').dialog('close');
																											   }});	
	*/
}
//-----------------------------------------------------------------------------------------------------------------------------------------
function checkoutGetFreightCost(val,act)
{
	$('#checkoutFreightErrorID').html('');
	//AlerterObject = new Alerter(300, 100, 'freightLoading', {});
	$('#freightLoading').dialog('open');
	var qStr = act + "&rnd=" + new Date().getTime();
	
	$.post(qStr, { action: 'checkout_getfreight', freightType: val},
     function(jsonObj){
		if (jsonObj.success == 1) {
			$('#checkoutFreightID').html(jsonObj.cost);
		} else {
			var errStr = '<ul class="errlist">';
			$.each(jsonObj.errors, function(i, k){errStr += '<li style="color: #CC0000">' + k + '</li>';});
			errStr += '</ul>';	
			$('#checkoutFreightErrorID').html(errStr);
			$('#checkoutFreightID').html('0');
			$('#discount_code').val('');
		}
		$('#checkoutTotalID').html(jsonObj.total);
		$('#freightLoading').dialog('close');
     }, "json");
}
//-----------------------------------------------------------------------------------------------------------------------------------------
function checkoutGetDiscount(val,act)
{
	$('#checkoutDiscountErrorID').html('');
	$('#freightLoading').dialog('open');
	//AlerterObject = new Alerter(300, 100, 'freightLoading', {});
	var qStr = act + "&rnd=" + new Date().getTime();
	
	$.post(qStr, { action: 'checkout_getdiscount', discount_code: val},
     function(jsonObj){
		if (jsonObj.success == 1) {
			$('#checkoutDiscountID').html(jsonObj.discount);
		} else {
			var errStr = '<ul class="errlist">';
			$.each(jsonObj.errors, function(i, k){errStr += '<li style="color: #CC0000">' + k + '</li>';});
			errStr += '</ul>';	
			$('#checkoutDiscountErrorID').html(errStr);
			$('#checkoutDiscountID').html('0');
		}
		$('#checkoutTotalID').html(jsonObj.total);
		$('#freightLoading').dialog('close');
     }, "json");
}
//-----------------------------------------------------------------------------------------------------------------------------------------
function getWinSize() {
        var myWidth = 0, myHeight = 0;
        if (typeof( window.innerWidth ) == 'number') {
            //Non-IE
            myWidth = window.innerWidth;
            myHeight = window.innerHeight;
        } else if (document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight )) {
            //IE 6+ in 'standards compliant mode'
            myWidth = document.documentElement.clientWidth;
            myHeight = document.documentElement.clientHeight;
        } else if (document.body && ( document.body.clientWidth || document.body.clientHeight )) {
            //IE 4 compatible
            myWidth = document.body.clientWidth;
            myHeight = document.body.clientHeight;
        }
        return {'width':myWidth, 'height':myHeight};
    }
//-----------------------------------------------------------------------------------------------------------------------------------------
function registerTempOrder(url, cctype)
{
	$('#Loading').dialog('open');
	
	$.post(url, { action: 'registertemporder', gateway: cctype},
     function(jsonObj){
		if (jsonObj.success == 1) {
			if(jsonObj.google && jsonObj.google.enabled == 1) {
				$('#google_cart').val(jsonObj.google.google_cart);
				$('#google_signature').val(jsonObj.google.google_signature);
				document.forms.google_f.submit();
			} else if(jsonObj.paypal && jsonObj.paypal.enabled == 1) {
				var tId=null;
				tId = window.setTimeout("location.replace('" + jsonObj.paypal.url + "')", 1);
			}
		} else {
			var errStr = '<ul class="errlist">';
			$.each(jsonObj.errors, function(i, k){errStr += '<li style="color: #CC0000">' + k + '</li>';});
			errStr += '</ul>';	
			$('#registerTempOrderErrorID').html(errStr);
		}
		$('#Loading').dialog('close');
     }, "json");
}
//-----------------------------------------------------------------------------------------------------------------------------------------
function getCart()
{
	var url = '/content/store/index.html?mode=ajax&get=csh&return=html';
	$.get(url, {success: 'cart'},function(transport){$('#cart').html(transport);}, "html");
	
}
//-----------------------------------------------------------------------------------------------------------------------------------------
function checkAdv(val)
{
	if (val < 0) return;
	
	if (val == 0) showAdvWindow();
	else window.setTimeout("showAdvWindow()", val);
}
//-----------------------------------------------------------------------------------------------------------------------------------------
function showAdvWindow()
{
	var url = '/chat/index.html?mode=ajax&return=html';
	$.post(url, {'action' : 'chat_adv'},function(transport){popup(transport);}, "html");
}
//-----------------------------------------------------------------------------------------------------------------------------------------
