<!--

//--------------------------------------------------------------------------------
//	Cookie functions
//--------------------------------------------------------------------------------

// FUNCTION create Cookie
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";

}

// FUNCTION read cokkie
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

//--------------------------------------------------------------------------------
//	FontResize functions
//--------------------------------------------------------------------------------

// FUNCTION set Font Size and create cookie
function setFontSize(size, id) {

	var smallsize  = '11px';
	var mediumsize = '13px';
	var largesize  = '16px';

	if(size == 'small') {
		document.getElementById(id).style.fontSize=smallsize;
		createCookie("fontsize", 'small', 365);
	}else if (size == 'medium') {
		document.getElementById(id).style.fontSize=mediumsize;
		createCookie("fontsize", 'medium', 365);
	} else if (size == 'large') {	
		document.getElementById(id).style.fontSize=largesize;
		createCookie("fontsize", 'large', 365);
	} else {
		document.getElementById(id).style.fontSize=smallsize;
		createCookie("fontsize", 'small', 365);
	}
}

// FUNCTION read fontsize from cookie and launch setFontSize()
function getFontSize() {
var cookie = readCookie("fontsize");
	if (cookie != null) {
		setFontSize(cookie, 'body');
	}

}

//--------------------------------------------------------------------------------
//	Cart functions
//--------------------------------------------------------------------------------

// FUNCTION update cart form
function updateCart() {
	document.cart.submit();
}

// FUNCTION set +1 or -1 pt in the input field (curs = up|down)
function setUpOrDownField (field, curs) {

	var CurrentValue = parseInt(document.cart.field.value);
	
	if (CurrentValue != 0) {
		
		if (curs == 'down') CurrentValue --;
		else CurrentValue ++;
	
	}
	
	document.cart.field.value = CurrentValue;

}

//--------------------------------------------------------------------------------
//	Checkout functions
//--------------------------------------------------------------------------------

// FUNCTION chack valid data in field and submit form
function checkFormAndSubmit() {

	var submit = true;
	var ErrorColor = '#fffaa8'; 
	var ValidColor = '#ffffff';


	// SHIPPING

	// FirstName
	if(document.checkout.FirstName.value =='') {
		document.getElementById('FirstName').style.background=ErrorColor;
		submit = false;
	} else {
		document.getElementById('FirstName').style.background=ValidColor;
	}

	// LastName
	if(document.checkout.LastName.value =='') {
		document.getElementById('LastName').style.background=ErrorColor;
		submit = false;
	} else {
		document.getElementById('LastName').style.background=ValidColor;
	}

	// Street_Shipping
	if(document.checkout.Street_Shipping.value =='') {
		document.getElementById('Street_Shipping').style.background=ErrorColor;
		submit = false;
	} else {
		document.getElementById('Street_Shipping').style.background=ValidColor;
	}

	// City_Shipping
	if(document.checkout.City_Shipping.value =='') {
		document.getElementById('City_Shipping').style.background=ErrorColor;
		submit = false;
	} else {
		document.getElementById('City_Shipping').style.background=ValidColor;
	}

	// Zip_Shipping
	if(document.checkout.Zip_Shipping.value =='') {
		document.getElementById('Zip_Shipping').style.background=ErrorColor;
		submit = false;
	} else {
		document.getElementById('Zip_Shipping').style.background=ValidColor;
	}

	// email
	if(document.checkout.email.value =='') {
		document.getElementById('email').style.background=ErrorColor;
		submit = false;
	} else {
		document.getElementById('email').style.background=ValidColor;
	}
	
	// email retype
	if(document.checkout.email_retype.value =='' || document.checkout.email.value.toLowerCase() != document.checkout.email_retype.value.toLowerCase()) {
		document.getElementById('email_retype').style.background=ErrorColor;
		submit = false;
	} else {
		document.getElementById('email_retype').style.background=ValidColor;
	}
	
	// phone1
	if(document.checkout.phone1.value == '') {
		document.getElementById('phone1').style.background=ErrorColor;
		submit = false;
	} else {
		document.getElementById('phone1').style.background=ValidColor;
	}	
	
	if (document.checkout.ship_eq.checked == true) {

		// BILLING

		// Street_Billing
		if(document.checkout.Street_Billing.value == '') {
			document.getElementById('Street_Billing').style.background=ErrorColor;
			submit = false;
		} else {
			document.getElementById('Street_Billing').style.background=ValidColor;
		}

		// City_Billing
		if(document.checkout.City_Billing.value == '') {
			document.getElementById('City_Billing').style.background=ErrorColor;
			submit = false;
		} else {
			document.getElementById('City_Billing').style.background=ValidColor;
		}

		// Zip_Billing
		if(document.checkout.Zip_Billing.value == '') {
			document.getElementById('Zip_Billing').style.background=ErrorColor;
			submit = false;
		} else {
			document.getElementById('Zip_Billing').style.background=ValidColor;
		}

	}
	
	
	if (document.checkout.payment_type == null || document.checkout.payment_type[0].checked) {
		
		// CARD INFO
	
		// cc_cardholder
		if(document.checkout.cc_cardholder.value =='') {
			document.getElementById('cc_cardholder').style.background=ErrorColor;
			submit = false;
		} else {
			document.getElementById('cc_cardholder').style.background=ValidColor;
		}
	
		// cc_card_no
		if(document.checkout.cc_card_no.value =='') {
			document.getElementById('cc_card_no').style.background=ErrorColor;
			submit = false;
		} else {
		
			// делаем проверку мастер кард
			if ($('cc_card_no').value[0] == 5 && $('no_mc').value == 1) {
				document.getElementById('cc_card_no').style.background=ErrorColor;
				submit = false;
				alert('Sorry, we can not accept your card (Master Card) at this moment because of online banking issues. Please use Visa card instead or contact our support.');
			}
		
			$('cc_card_no').style.background=ValidColor;
			
		}
	
		// cc_exp_m
		if(document.checkout.cc_exp_m.value =='') {
			document.getElementById('cc_exp_m').style.background=ErrorColor;
			submit = false;
		} else {
			document.getElementById('cc_exp_m').style.background=ValidColor;
		}
	
		// cc_exp_y
		if(document.checkout.cc_exp_y.value =='') {
			document.getElementById('cc_exp_y').style.background=ErrorColor;
			submit = false;
		} else {
			document.getElementById('cc_exp_y').style.background=ValidColor;
		}
	
		// cc_cvc
		if(document.checkout.cc_cvc.value =='') {
			document.getElementById('cc_cvc').style.background=ErrorColor;
			submit = false;
		} else {
			document.getElementById('cc_cvc').style.background=ValidColor;
		}

	} else {
	
		if ($('check_you_name').value == '') {
			$('check_you_name').style.background=ErrorColor;
			submit = false;
		} else {
			$('check_you_name').style.background=ValidColor;
		}	
		
		if ($('check_bank_name').value == '') {
			$('check_bank_name').style.background=ErrorColor;
			submit = false;
		} else {
			$('check_bank_name').style.background=ValidColor;
		}		
		
		if ($('check_account_number').value == '') {
			$('check_account_number').style.background=ErrorColor;
			submit = false;
		} else {
			$('check_account_number').style.background=ValidColor;
		}		
		
		if ($('check_routing_number').value == '') {
			$('check_routing_number').style.background=ErrorColor;
			submit = false;
		} else {
			$('check_routing_number').style.background=ValidColor;
		}	
		
		if ($('check_reference_number').value == '') {
			$('check_reference_number').style.background=ErrorColor;
			submit = false;
		} else {
			$('check_reference_number').style.background=ValidColor;
		}			
		
	
	}
	
	if (submit == true) {
		document.checkout.submit();
	} 

}


// FUNCTION open/close Billing div
function openBillingDiv() {
	
	if ($('ship_eq').checked == true) {

		document.getElementById('billing_div1').style.display = '';
		document.getElementById('billing_div2').style.display = '';
		
	} else {
	
		document.getElementById('billing_div1').style.display = 'none';
		document.getElementById('billing_div2').style.display = 'none';
	
	}

}

// FUNCTION open/close phone div
function openPhoneDiv() {

	if (document.checkout.openphonediv.checked == true) {

		document.getElementById('phonediv').style.display = '';
		
	} else {
	
		document.getElementById('phonediv').style.display = 'none';
	
	}

}

// FUNCTION swap order type layer
function swapOrderType() {

	if (document.checkout.payment_type[0].checked) {

		$('card_layer').style.display = '';
		$('check_layer').style.display = 'none';
		
	} else {

		$('card_layer').style.display = 'none';
		$('check_layer').style.display = '';	

	}

}



//--------------------------------------------------------------------------------
//	Menu functions
//--------------------------------------------------------------------------------

var openGroupId = 'noshow';

// FUNCTION hide/shop menu groups
function left_menu(product_id){
	
	if (document.getElementById('a_' + product_id).style.display){
	
		document.getElementById('a_' + product_id).style.display = "";
		document.getElementById('a_' + openGroupId).style.display = "none";
		openGroupId = product_id;

	} else {
	
		document.getElementById('a_' + product_id).style.display = "none";
		openGroupId = 'noshow';
		
	}
	
}

//--------------------------------------------------------------------------------
//	Other function
//--------------------------------------------------------------------------------

function locateDialog(text, link) {

	if (confirm(text)) location.href=link; 

}


//--------------------------------------------------------------------------------
//	Other function
//--------------------------------------------------------------------------------

function reportError() {
 alert('error');
}


function locateDialog(text, link) {

	if (confirm(text)) location.href=link; 

}

function showhint(obj, element) {

	var div = document.getElementById(obj);
	div.style.display = "block";
	
	var url    = 'ajax.php';  					// Url на который следует посылать запрос
	var params = 'element=' + element; 		// Параметры запроса, напр. "?zip=XXXXX&foo=1"
	var ajax   = new Ajax.Updater(  			// Создаем AJAX вызов
				{success: ''},  					// Ответ сервера записать в div 
				url,  
				{method: 'get', 					// метод запроса - GET
				parameters: params} 				// строка с параметрами

	);

}

function hidehint(obj) {
	var div = document.getElementById(obj);
	div.style.display = "none";
}


-->

