$(document).ready(function(){
	noNavLinks = $('#page-nav li').length;
	$('#page-nav li:eq('+(noNavLinks-1)+')').addClass('last');
	
	maxListItemHeight = 0;
	$('.product-list-item .title').each(function(){
		if ($(this).height() > maxListItemHeight){
			maxListItemHeight = $(this).height();
		}
	});
	$('.product-list-item .title').css({'height':maxListItemHeight+'px'});
	
	$('.opt-size .inner').each(function(){
		$(this).css({'padding-top': $(this).parent().height()/2 - $(this).height()/2});
	})
	$('.opt-size-long .inner').each(function(){
		$(this).css({'padding-top': $(this).parent().height()/2 - $(this).height()/2});
	})

})

function validateFormArr(vfields){
	var errorField = '';
	$('.error-require').removeClass('error-require');
	checkField = true;
	for(i=0;i<vfields.length;i++){
		if(vfields[i]['type']=='text' && $('input[@name='+vfields[i]['field']+']').attr('value')==''){
			$('input[@name='+vfields[i]['field']+']').addClass('error-require');
			errorField+=vfields[i]['field'];
			checkField = false;
		}
		if(vfields[i]['type']=='text' && $('textarea[@name='+vfields[i]['field']+']').attr('value')==''){
			$('textarea[@name='+vfields[i]['field']+']').addClass('error-require');
			errorField+=vfields[i]['field'];
			checkField = false;
		}
		if(vfields[i]['type']=='number' && ($('input[@name='+vfields[i]['field']+']').attr('value')=='' || isNaN($('input[@name='+vfields[i]['field']+']').attr('value')))){
			$('input[@name='+vfields[i]['field']+']').addClass('error-require');
			errorField+=vfields[i]['field'];
			checkField = false;
		}
		if(vfields[i]['type']=='number' && !isNaN($('input[@name='+vfields[i]['field']+']').attr('value')) && vfields[i]['min']!=''){
			if (parseInt($('input[@name='+vfields[i]['field']+']').attr('value')) <  vfields[i]['min']){
				$('input[@name='+vfields[i]['field']+']').addClass('error-require');
				errorField+=vfields[i]['field'];
				checkField = false;
			}
		}
		if(vfields[i]['type']=='select-number' && ($('select[@name='+vfields[i]['field']+']').val()=='' || $('select[@name='+vfields[i]['field']+']').val()=='0' || isNaN($('select[@name='+vfields[i]['field']+']').val()))){
			$('select[@name='+vfields[i]['field']+']').addClass('error-require');
			errorField+=vfields[i]['field'];
			checkField = false;
		}
		if(vfields[i]['type']=='select' && $('input[@name='+vfields[i]['field']+']').attr('value')==''){
			$('select[@name='+vfields[i]['field']+']').addClass('error-require');
			errorField+=vfields[i]['field'];
			checkField = false;
		}
		if(vfields[i]['type']=='checkbox-required'){
			chkError = true;
			$('input[@name='+vfields[i]['field']+']').each(function(){
				if($(this).attr('checked')==true){
					chkError = false;
				}
			})
			if (chkError){
				$('input[@name='+vfields[i]['field']+']').parent('label').addClass('error-require');
				errorField+=vfields[i]['field'];
				checkField = false;
			}
		}
		
		if(vfields[i]['type']=='text-email'){
			str = $('input[@name='+vfields[i]['field']+']').attr('value');
			at="@"; dot="."; lat=str.indexOf(at); lstr=str.length; ldot=str.indexOf(dot);
			if (str == '' || str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr || str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr || str.indexOf(at,(lat+1))!=-1 || str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot || str.indexOf(dot,(lat+2))==-1 || str.indexOf(" ")!=-1){
				$('input[@name='+vfields[i]['field']+']').addClass('error-require');
			errorField+=vfields[i]['field'];
				checkField = false;
			}
		}

}
	if (!checkField){
		alert('Please fill the required fields.');
		return false;
	}

	return checkField;
}
