jQuery(document).ready(function(){

		var url = window.location.href;
		if(url.indexOf('registercustomer')!=-1){
			makeDefaultChecked();
		}
		
		function makeDefaultChecked(){
			var locale = jQuery('#locale').val();
			var countryCode = locale.split("_");
			var upperCaseCountryCode = countryCode[1].toUpperCase();
			if(upperCaseCountryCode == 'SG'){
				var subscription = document.getElementsByName("subscription");
				var newsLetterWithSubCategory = document.getElementsByName("newsLetterWithSubCategory");
				for (var i=0 ; i<subscription.length ; i++){
					subscription[i].checked=true;
				}
				for (var i=0 ; i<newsLetterWithSubCategory.length ; i++){
					newsLetterWithSubCategory[i].checked=true;
				}	
			}
		}	
}
);


function openArchiveWindow(index){
	if(index.value != ""){
		window.open(index.value);
	}
	
}

function submitMysonyPostLoginNewsletter(){
	
	if(document.getElementById("submitNewsletter") != null){	
		document.newsletterForm.action=document.getElementById("submitNewsletter").value;
				
		document.newsletterForm.submit();
	}
}

function uncheckSubCategory(element){
	if(element.checked==false){
		var categoryValue = element.value;
		var subscription = document.getElementsByName("subscription");
		for (var i=0 ; i<subscription.length ; i++){
			if(subscription[i].checked==true){
				var subscriptionValue = subscription[i].value;
				if(subscriptionValue.match(categoryValue)){
					subscription[i].checked=false;
				}
			}
		}
	}
}

function submitnonMySonyNewsletterForm(){
	
	if(document.getElementById("submitNonMySonyNewsletter") != null){	
		document.nonMysonyNewsletterForm.action=document.getElementById("submitNonMySonyNewsletter").value;
		document.nonMysonyNewsletterForm.action = document.nonMysonyNewsletterForm.action;		
		document.nonMysonyNewsletterForm.submit();
	}
}

function submitNonMysonyNewsletter(){

if(document.getElementById("submitNewsletter") != null){		
		document.nonMysonyNewsletterForm.action=document.getElementById("submitNewsletter").value;
		document.nonMysonyNewsletterForm.action = document.nonMysonyNewsletterForm.action+"&action=subscribenonmysonynewsletter";		
		document.nonMysonyNewsletterForm.submit();
	}
}

function submitOnEnterNewsLetterSignUp(event) {
	if (event.keyCode == 13) { // No need to do browser specific checks. It is always 13.  
          document.sonyStylePromotionForm.action = document.getElementById('signUpSubmitURL').value;
          document.sonyStylePromotionForm.submit();  
    	return false;
    }  
    else {
    	return true;
    }
}

function submitNewsLetterSignUp() {
	document.sonyStylePromotionForm.action = document.getElementById('signUpSubmitURL').value;
	document.sonyStylePromotionForm.submit();
}

function submitSubscriptionNonMysonyNewsletter() {
	document.subscribeNonMysonyNewsletterForm.action = document.getElementById('submitSubscriptionNonMySonyNewsletter').value;
	document.subscribeNonMysonyNewsletterForm.action = document.subscribeNonMysonyNewsletterForm.action+"&action=subscribenonmysonynewsletter";
	document.subscribeNonMysonyNewsletterForm.submit();
}

function submitNonMySonyPersonalDetailsForm(){
	document.nonMySonyPersonalDetailsForm.action = document.getElementById('submitNonMySonyPersonalDetailsForm').value;
	document.nonMySonyPersonalDetailsForm.action = document.nonMySonyPersonalDetailsForm.action+"&action=submitNonMySonyPersonalDetails";	
	document.nonMySonyPersonalDetailsForm.submit();
}
function submitSubscribeNLPersonalDetails() {
	document.subscribeNonMysonyNewsletterForm.action = document.getElementById('submitUrl').value;	
	document.subscribeNonMysonyNewsletterForm.submit();
}

function unSubscribeAll(){
	var allCheckBox = document.getElementsByName("subscription");
	for(var j=0 ; j<allCheckBox.length ; j++){
		allCheckBox[j].checked=false;
	}
}

function checkMainCategory(element){
	if(element.checked==true){
		var subValue = element.value;
		var splitSubValue = subValue.split("_");
		var checkBoxNewsLetterWithSubCategoryTypeId = document.getElementsByName("newsLetterWithSubCategory");
		for (var i=0 ; i<checkBoxNewsLetterWithSubCategoryTypeId.length ; i++){
			if(checkBoxNewsLetterWithSubCategoryTypeId[i].value==splitSubValue[0]+"_"){
				checkBoxNewsLetterWithSubCategoryTypeId[i].checked=true;
			}
		}
	}
}