var phoneChara = /^[0-9\s.-]+$/;
var err = '';
var oldCheck = null;
window.onload = base;

function base(){
	btnBG();
	$('input').each(function(){$(this).focus(function (){displayBlock();})});
	$('textarea').each(function(){$(this).focus(function (){displayBlock();})});
	$('#location input').each(function(){$(this).click(function(){checkOne($(this));});});
	if(url('sent')) {$('#ms').css('display','block');}
	if(url('sent-p')) {$('#ms').css('display','block');}
	}

function displayBlock(){
	$('#ms').css('display','none');
}

function btnBG(){
	$('#content_in_left_company a').each(function(){
		if(url($(this).attr('href')) == true){
		$(this).css('background-position','right -50px');	
		}
	});
	}

function checkOne(obj){
		if(oldCheck) oldCheck.attr('checked',false);
		oldCheck = obj;
	}

function boxCheck(){
	err = '';
	var trueNum = 0;
	$('#location input').each(function(){ if($(this).attr('checked') == true){trueNum += 1;}})
	if(trueNum == 0) alert('Please check one selecter');//err += 'Please check one selecter\n';
	}
	
function checkform(){
		if ($('#location input:checkbox').length){
			boxCheck();
		}
		var form1 = $('#form_box input');
		form1.each(function(){
			if($(this).val() == ''){
				
				err += $(this).attr('name')+' is required\n';
				$(this).css('background','#f9d8ec');
				
			}else{$(this).css('background','#F8F8EC');}
				
			if($(this).attr('name') == 'phone' && $(this).val() != ''){
				if(!$(this).val().match(phoneChara)){$(this).val("phone must be number"); $(this).css('background','#f9d8ec');}
				else{$(this).css('background','#F8F8EC');}
				}
		});
		
		if($('#message').val() == ''){err += "message is required"; $('#message').css('background','#f9d8ec');}
		else{$('#message').css('background','#F8F8EC');}
		
		if($('#describe').val() == ''){err += "message is required"; $('#describe').css('background','#f9d8ec');}
		else{$('#describe').css('background','#F8F8EC');}
		
		if(err != ''){return false;}
		else{return true;}
	}
	
function url(pageName){
	var objURL = new Object();
	if(document.URL.indexOf(pageName)>-1){
		return objURL = true;
		}else{
			return objURL = false;
			}
	}
