var l = window.location.href.split("http://www.sjeurope.com");
$(".textexample_small").click(function() { 
	$("link").attr("href", "/App/data/styles/sompo.css");
	eraseCookie();
	/*var l = window.location.href.indexOf('/jp/');
	if (l != -1) { 
		setcookie("pickthestylesheet","japansompo",7);
	} else {*/
		setcookie("pickthestylesheet","sompo",7);
	//}
});
$(".textexample_medium").click(function() { 
	$("link").attr("href", "/App/data/styles/medium.css"); 
	eraseCookie();
	/*var l = window.location.href.indexOf('/jp/');
	if (l != -1) { 
		setcookie("pickthestylesheet","japanmedium",7);
	} else {*/
		setcookie("pickthestylesheet","medium",7);
	//}
});
$(".textexample_large").click(function() { 
	$("link").attr("href", "/App/data/styles/large.css"); 
	eraseCookie();
	/*var l = window.location.href.indexOf('/jp/');
	if (l != -1) { 
		setcookie("pickthestylesheet","japanlarge",7);
	} else {*/
		setcookie("pickthestylesheet","large",7);
	//}
});

$(document).ready(function() {
	var link = l[1];
	if (link == "/Default.aspx?page=contactusuk") { link = "/contactus/form"; }
	$("area#englishtext").attr("href","http://www.sjeurope.com"+link);
	$("area#japanesetext").attr("href","http://jpn.sjeurope.com"+link);
});

function setcookie(name,value,ndays) {
	var expires = new Date();
	expires.setTime(expires.getTime()+(ndays*24*60*60*1000));
	var exp = "; expires="+expires.toGMTString();
	document.cookie = name+"="+escape(value)+exp+"; path=/; domain=www.sjeurope.com";
}

function eraseCookie() {
	document.cookie = "stylesheet=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/";
	document.cookie = "pickthestylesheet=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/";
} 

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;
}
function checkCookie() {
	var x = readCookie("pickthestylesheet");
	if (x != "null") {
		eraseCookie();
		setcookie("pickthestylesheet",x,7);
	}
	switch (x) {
		case "sompo": $("link").attr("href", "/App/data/styles/sompo.css"); break;
		case "medium": $("link").attr("href", "/App/data/styles/medium.css"); break;
		case "large": $("link").attr("href", "/App/data/styles/large.css"); break;
		default: $("link").attr("href", "/App/data/styles/sompo.css"); break;
	}
}
$(document).ready(function(){ 
	checkCookie();
});

function selectenquiry(t) {
	if (t.value == "Other") {
		document.getElementById('enquiryother').style.display = "block";
	}
	else {
		document.getElementById('pageViwer_sompo_content_2_ctl00_fpcFormPresentation_ctl02_Input').value = t.value;
		document.getElementById('enquiryother').style.display = "none";
	}
}
function selecttitle(t) {
	if (t.value == "Other") {
		document.getElementById('titleother').style.display = "block";
	}
	else {
		document.getElementById('pageViwer_sompo_content_2_ctl00_fpcFormPresentation_ctl05_Input').value = t.value;
		document.getElementById('titleother').style.display = "none";
	}
}

var enq = 0;
var enqhtml = "";
var title = 0;
var titlehtml = "";
function checkstatus(t) {
	switch (t) {
		case 'otherenquiry': 
			var h = document.getElementById('enquiryother').innerHTML;
			var v = document.getElementById('pageViwer_sompo_content_2_ctl00_fpcFormPresentation_ctl02_Input').value;
			
			if (v == "") {
				var h1 = h;
				if (enq == 0) {
					enqhtml = h;
					if (!(h1.match("<br><span style='color: red;'>Please enter an enquiry</span>"))) {
						h1 += "<br><span style='color: red;'>Please enter an enquiry</span>"; 
						enq=1;
					}
				}
				document.getElementById('enquiryother').innerHTML = h1;
				document.getElementById('pageViwer_sompo_content_2_ctl00_fpcFormPresentation_ctl02_Input').value = "";
				//document.getElementById('pageViwer_sompo_content_2_ctl00_fpcFormPresentation_ctl02_Input').focus();
			}
			else {
				//var h1 = h.split("<br><span style='color: red;'>Please enter an enquiry</span>");
				if (enq > 0) {
					document.getElementById('enquiryother').innerHTML = enqhtml;
					document.getElementById('pageViwer_sompo_content_2_ctl00_fpcFormPresentation_ctl02_Input').value = v;
				}
			}
			break;
		case 'othertitle': 
			var h = document.getElementById('titleother').innerHTML;
			var v = document.getElementById('pageViwer_sompo_content_2_ctl00_fpcFormPresentation_ctl05_Input').value;
			
			if (v == "") {
				var h1 = h;
				if (title == 0) {
					titlehtml = h;
					if (!(h1.match('<br><span style="color: red;">Please enter a title</span>'))) {
						h1 += "<br><span style='color: red;'>Please enter a title</span>"; 
						title=1;
					}
				}
				document.getElementById('titleother').innerHTML = h1;
				document.getElementById('pageViwer_sompo_content_2_ctl00_fpcFormPresentation_ctl05_Input').value = "";
				//document.getElementById('pageViwer_sompo_content_2_ctl00_fpcFormPresentation_ctl05_Input').focus();
			}
			else {
				//var h1 = h.split('<br><span style="color: red;">Please enter a title</span>');
				if (title > 0) {
					document.getElementById('titleother').innerHTML = titlehtml;
					document.getElementById('pageViwer_sompo_content_2_ctl00_fpcFormPresentation_ctl05_Input').value = v;
				}
			}
			break;
		case 'agreecb':
			(document.getElementById('agreecb').checked) ? document.getElementById('formsubmitrow').style.display = "block" : document.getElementById('formsubmitrow').style.display = 'none';
			break;
	}
}

function checkemail(t) {
	var email = t.value;
	var hide = false;
	if (email == "") {
		document.getElementById('firstemail').style.display = 'block';
		document.getElementById('firstemail').innerHTML = '<br><span style="color:red">Please enter an email address</span>';
		document.getElementById('pageViwer_sompo_content_2_ctl00_fpcFormPresentation_ctl09_Input').focus();
	}
	else {
		var filter = /^([a-zA-Z0=9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(email)) { 
			document.getElementById('firstemail').style.display = 'block';
			document.getElementById('firstemail').innerHTML = '<br><span style="color:red">Please enter a valid email address</span>';
			document.getElementById('pageViwer_sompo_content_2_ctl00_fpcFormPresentation_ctl09_Input').focus();
		}
		else { hide = true; }
	}
	if (hide) {
		document.getElementById('firstemail').style.display = 'none';
	}
}

function confirmemail(t) {
	var email = t.value;
	var email1 = document.getElementById('pageViwer_sompo_content_2_ctl00_fpcFormPresentation_ctl09_Input').value;
	var hide = false;
	if (email == "") {
		document.getElementById('secondemail').style.display = 'block';
		document.getElementById('secondemail').innerHTML = '<br><span style="color:red">Please confirm your email address</span>';
		document.getElementById('pageViwer_sompo_content_2_ctl00_fpcFormPresentation_ctl10_Input').focus();
	}
	else {
		if (email != email1) {
			document.getElementById('secondemail').style.display = 'block';
			document.getElementById('secondemail').innerHTML = '<br><span style="color:red">Please ensure your email addresses match</span>';
			document.getElementById('pageViwer_sompo_content_2_ctl00_fpcFormPresentation_ctl10_Input').focus();
		}
		else { hide = true; }
	}
	if (hide) {
		document.getElementById('secondemail').style.display = 'none';
	}
}
