var swapped = 0;

function eml(email, domain, subj) {
	address = email + '@' + domain;
	if (address == 'terrainc' + '@' + 'svitonline.com') {
		address = 'sklad'+'@'+'terraincognita.ua';
	}
	if (typeof subj === 'undefined') {
		var subj = '';
	} else {
		if (subj) {
			subj = '?Subject=' + subj;
		} else {
			subj = '';
		}
	}
	document.write("<a href=\"ma" + "i" + "lto:" + address + subj + "\">" + address + "</a>");
}

function paintitem(itm_url, new_color) {
	var paintmeimg=document.getElementById('paintme');
	var path=paintmeimg.src.substr(0,paintmeimg.src.lastIndexOf('/')+1);
	paintmeimg.src=path+itm_url+'_'+new_color+'.jpg';

	var link = document.getElementById('largecolor');
	link.href = path.substr(0,path.length-6)+'big/'+itm_url+'_'+new_color+'.jpg';

	var i=0;
	var j=0;
	for(i=0;i<all_colors.length;i++) {
		for (j=1;j<=columns;j++) {
			obj = document.getElementById(all_colors[i] + j);
			if (obj == null) continue;
			if (all_colors[i] == new_color) {
				obj.src = '/img/icons/colors/' + all_colors[i] + '_checked.gif';
			} else {
				obj.src = '/img/icons/colors/' + all_colors[i] + '.gif';
			}
		}
	}

}

function swapimage(curr_id, max_id) {
	var modulus = (curr_id + swapped) % max_id;
	curr_id = modulus + 1;
	curr_id_str = '' + curr_id;
	while (curr_id_str.length < 3) curr_id_str = '0' + curr_id_str;
 	var new_image = '/img/nature/terra_nature_' + curr_id_str + '.jpg';
	document.getElementById('nature').style.backgroundImage = "url('" + new_image + "')";
	swapped++;
	var value = curr_id;
	var last_pics = getCookie('lastpics');
	if (last_pics) {
		last_pics = curr_id + ',' + last_pics;
		var last_images_arr = last_pics.split(',', 3);
		var value = last_images_arr.join(',');
	}
	setCookie('lastpics', value, 30, '/');
}

function setCookie(name, value, expires, path, domain, secure) {
	var today = new Date();
	today.setTime(today.getTime());
	if (expires) {
		expires = expires * 24 * 60 * 60 * 1000;
	}
	var expires_date = new Date(today.getTime() + (expires));
	document.cookie = name + "=" + escape(value) +
		((expires) ? ";expires=" + expires_date.toUTCString() : "") +
		((path) ? ";path=" + path : "") +
		((domain) ? ";domain=" + domain : "") +
		((secure) ? ";secure" : "");
}

function getCookie(check_name) {
	var a_all_cookies = document.cookie.split(';');
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false;
	for (var i = 0; i < a_all_cookies.length; i++) {
		a_temp_cookie = a_all_cookies[i].split('=');
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		if (cookie_name == check_name) {
			b_cookie_found = true;
			if (a_temp_cookie.length > 1) {
				cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
			}
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if (!b_cookie_found) {
		return null;
	}
}

