// JavaScript Document
$(document).ready(function() {
	blurLinks();

	//$('a.lightbox').lightBox();
});


function blurLinks() {
	links = document.getElementsByTagName("a");
	for(i=0; i<links.length; i++) {
		links[i].onfocus = unblur;
	}
	inputs = document.getElementsByTagName("input");
	for(i=0; i<inputs.length; i++) {
		if (inputs[i].type == 'button' || inputs[i].type == 'submit') {
			inputs[i].onfocus = unblur;
		}
	}
}

function unblur() {
	this.blur();
}

function resetForm() {
	$('#cartInformation textarea').val('');
	$('#cartInformation input:not(#clear, #submit)').val('');
	$('#company').attr("checked", "checked");
	return false;
}

function popUpPrint(URL) {
	window.open( URL, "myWindow", "status = 1, height = 600, width = 960, toolbar=no, scrollbars=yes, menubar=no, resizable = yes" )
}

function checkInt(evt){
	var charCode = evt.which
	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;
}


//select box manipulation
function selectOption(val, el) {
	$('#'+el).selectOptions(val,true);
}


function addMore(picid){
	var id = document.getElementById(picid).value;

	if(id<10){
		num = (id - 1) + 2;
		$("#photoContainer").append("<label>" + vars['image'] + num +"</label><input id='fileToUpload"+id+"' type='file' name='photo["+id+"]' class='file' /><span class='spacer'></span>");
		id = (id - 1) + 2;
		document.getElementById(picid).value = id;
	}
}


//empty input boxes
function emptyFormFields(el,val) {
	if (el.value == val ) {
		el.value = '';
	}
}

function fillFormFields(el,val) {
	if (el.value == '' ) {
		el.value = val;
	}
}


function addMoreOrders(el, addTo) {
	num = $('#order_count').val();
	num_new = (num-1)+2; //alert(num_new);
	$('#order_count').val(num_new);

	elId = 'orderRow_' + num;
	htmlData = '<div id="' + elId + '">' + $('#' + el).html() + ' <a href="#" onclick="removeOrderRow(\'' + elId + '\')" class="remove" title="' + vars['remove'] + '"></a><div class="clearSep"></div></div>';
	$('#' + addTo).append(htmlData);
}


function removeOrderRow(el) {
	$("#" + el).remove();
}


function fadeImgSrc(imgId, newImg) {
	$('#' + imgId).fadeTo(500,0,function() {
		$("#" + imgId).attr('src', newImg);
	}).fadeTo(500, 1);
}

function deleteOrderRow(rowId, orderId, langId) {
	var url = 'Ajax_0_' + orderId + '_' + langId + '.html';

	$.get(url,
	  function(data){
		$("#" + rowId).fadeTo(500,0,function() {
				$("#" + rowId).remove();
			}).fadeTo(500, 1);

		var exploded = data.split('::');

		$("#priceTotal").html(exploded[0]);
		$("#orderPriceLeft").html(exploded[0]);
		$("#orderCountLeft").html(exploded[1]);
		$("#discountPercent").html(exploded[2]);
	  });
}

function changeOrderCount(orderCount, orderId, langId, rowFullPrice, singlePrice) {
	var url = 'Ajax_1_' + orderId + '_' + orderCount + '_' + langId + '.html';

	$.get(url,
	  function(data){
		var exploded = data.split('::');
		$("#priceTotal").html(exploded[0]);
		$("#orderCountLeft").html(exploded[2]);
		$("#orderPriceLeft").html(exploded[0]);
		$("#" + rowFullPrice).html(exploded[1]);
		$("#discountPercent").html(exploded[3]);
	  });
}



