function  checkInIn(select){
	$('seriesInput').value = select.value;
}

function chechSeries() {
	var value = $('brandSearch').value;
	
	 $A($$('tr[class="brh"]')).each(function(tr) {  
	 		tr.style.display = "none";
     });
     if ($('sr'+value)) {
     	$('sr'+value).style.display = "table-row";
     }
	
}

function redirect(elem) {
	var url = base_url + 'catalog/';
	if(elem.value != '') url += 'manufacture'+elem.value+'/';
	
	location.href = url;
}

function changePage(elem) {
	var limit = elem.value;
	var loc = location.href ;
	var pos = loc.lastIndexOf('limit');
	if ( pos > -1) loc = loc.replace(/limit[0-9]+/, 'limit'+limit);
	else {
		if(loc.indexOf('?') > -1) {
			loc = loc.substr(0, loc.indexOf('?')) + 'limit' + limit + '/' + loc.substr(loc.indexOf('?'));
		}
		else loc = loc + 'limit'+limit+'/';
	}
	loc = loc.replace(/page[0-9]+/i, 'page1');
	
	location = loc;
}

function replaceInUrl(what, value) {
	var loc = location.href ;
	var pos = loc.lastIndexOf(what);
	
	var regex = new RegExp(what+"([0-9]+)?");
	
	if ( pos > -1) loc = loc.replace(regex, what + value);
	else {
		if(loc.indexOf('?') > -1) loc += '&' + what + value;
		else loc += '?' + what + value;
	}
	return loc;
}


function changeSort(sort, order, changeSort) {
	var loc;
	if(changeSort) {
		if(order == 0) {
			order = 1;
		} else {
			order = 0;
		}
		loc = replaceInUrl('orderBy=', order);
	} else {
		loc = replaceInUrl('sortBy=', sort);
	}
	//alert(loc);
	location = loc;
}

function checkFeedbackForm() {
	var required = {
		"name"		:	"Вы не ввели Ваше ФИО",
		"msg"		:	"Вы не ввели сообщение"
	};
	for (var i in required) {
		var el = document.getElementById(i);
		if (!el.value) {
			alert(required[i]);
			el.focus();
			return false;
		}
	}
	return true;
}



function checkEmail(email) {
	if(!email) return email;
	if(!email.match(/^[\w\.\-]+@[\w\.\-]+\.[a-zA-Z]{2,}$/i, "")) return false;
	return true;
}

function checkStrSearch(str) {
   if((str.length) < 3) {
        alert('Строка поиска должна быть не менее 3 символов');
        return false;
    } else return true;
}


function isInt(num, chara, event) {
	if(((num >= 48) && (num <= 57)) || num == 37 || num == 8)
	{
		return event.keyCode;
	}
	
	if(((chara >= 48) && (chara <= 57)) || chara == 37 || chara == 8) {
		return event.charCode;
	} else {
		return false;
	}
}

function checkForgetForm(){
	var elem = getElem('email_main');
	
	if (!checkEmail(elem.value)) {
		 alert('Введенный E-mail некорректен');
		 return false;
	}
	 else return true;
}

function checkRegistrationForm(form)
{
	if (!form)
		throw "Form is not specified";

	var required = {
		"name"		:	"Вы не ввели ваше Имя",
		"email"	:	"Вы не ввели ваш E-mail",
		"phone"	:	"Вы не ввели ваш Телефон",
//		"city"		:	"Вы не ввели ваш Город",
//		"address"		:	"Вы не ввели ваш Адрес",
		"password"	:	"Вы не ввели пароль",
		"password_rep"	:	"Вы не ввели подтверждение пароля"
	};
	for (var i in required) {
		var el = form.elements[i];
		if (!el.value) {
			alert(required[i]);
			el.focus();
			return false;
		}
	}
	return true;
}

function checkPasswordForm(form){
	var required = {
		"current_password"		:	"Вы не ввели текущий пароль",
		"password"				:	"Вы не ввели новый пароль",
		"password_r"			:	"Вы не ввели новый пароль (повторно)"
	};
	
	for (var i in required) {
		var el = form.elements[i];
		if (!el.value) {
			alert(required[i]);
			el.focus();
			return false;
		}
	}
	return true;
}

function checkOrder(form) {
	if (!form)
		throw "Form is not specified";

	var required = {
		"delivery"	:	"Выберите пожалуйста Доставку",
		"name"		:	"Укажите пожалуйста Ваше имя",
		"phone"		:	"Укажите пожалуйста Контактный телефон",
		"email"		:	"Укажите пожалуйста Е-мейл",
		"address"	:	"Укажите пожалуйста Адрес доставки"
	};

	for (var i in required) {
		var el = form.elements[i];
		if (!el.value || el.value == '0') {
			alert(required[i]);
			if (el.focus)
				el.focus();
			return false;
		}
	}
	return true;
}

function checkComment() {
	if (!$('comment').value) { 
		alert('Не заполнен комментарий');
		return false;
	} else {
		return true;
	}
}

function checkDiv(id) {
	if ($(id).style.display == 'none') {
		$(id).style.display = 'block';
	} else {
		$(id).style.display = 'none';
	}
}

function SetCookie(sName, sValue){
	var today = new Date();
	var expire = new Date();
	nDays=365;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = sName+"="+escape(sValue) + "; path=/; expires="+expire.toGMTString();
	//Cookie.set(sName, sValue);
	/*document.cookie = sName + "=" + escape(sValue) + ";expires=30 Dec 2999 23:59:59 UTC; path=/";*/
}


function checkCat(id) {
	switch(id) {
		case 1:
			$('catM').className = 'cat';
			$('brandM').className = 'brand';
			$('brand').style.display = "none";
			$('cat').style.display   = "block";
			SetCookie('cat_view', '1');
			SetCookie('brand_view', '');
		break;
		case 2:
			$('catM').className = 'cat2';
			$('brandM').className = 'brand2';
			$('brand').style.display = "block";
			$('cat').style.display   = "none";	
			SetCookie('cat_view', '');
			SetCookie('brand_view', '1');
		break;	
	}
}

// checks required auth fields in specified form
function checkAuthenticationForm(form) 
{
	if (!form)
		throw "Missing Argument: Authentication Form is not specified";
	
	var required = {
		"email"	 :	"Введите пожалуйста E-mail",
		"password":	"Введите пожалуйста пароль"
	};

	for (var i in required) 
	{
		var el = form.elements[i];
		if (!el.value || el.value == '0') 
		{
			alert(required[i]);
			el.focus();
			return false;
		}
	}
	return true;
}


function checkSearch() {
	var required = {
		"search_str_all" :	"Вы не ввели посиковую фразу"
	};
	for (var i in required) {
		var el = document.getElementById(i);
		if (!el.value || el.value == '0') {
			alert(required[i]);
			el.focus();
			return false;
		}
	}
	return true;
}


function getPageSizes () {
	
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		if (self.innerHeight) {	// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}
	
	
		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
		return arrayPageSize;
}
