
// what does browser understand
var isDHTML=0;
var isLayers=0;
var isAll=0;
var isID=0;
if (document.getElementById) {isID=1; isDHTML=1;}
else if(document.all) {isAll=1;  isDHTML=1;}
else{
	browserVersion=parseInt(navigator.appVersion);
	if((navigator.appName.indexOf('Netscape')!=-1) &&(browserVersion==4)){isLayers=1;  isDHTML=1;}
	}
	
	
//finding the way to the object
function findDOM(objectID, withStyle)
{	
	if(withStyle==1)
	{
		if(isID) {var obj = document.getElementById(objectID).style;}
		else if(isAll) {obj = document.all[objectID].style;} 
		else {obj = document.layers[objectID];}   
	 }
	 else
	 {
		if(isID) {obj=document.getElementById(objectID);} 
		else if(isAll) {obj=document.all[objectID];} 
		else {obj=document.layers[objectID];}  
	 }
	 return obj;
}
	
//  Podskazki
function findLivePageWidth()
{
	if(window.innerWidth!=null) return window.innerWidth;
	if(document.body.clientWidth!= null) return document.body.clientWidth;
	return (null);
}


  //функция getInsideWindowHeight() возвращает высоту доступного в окне браузера пространства
function getInsideWindowHeight(){
	if (window.innerHeight){
	return window.innerHeight;
	} else if (document.compatMode&&document.compatMode.indexOf("CSS1")>=0){  // проверяем не IE6 ли это
	return document.body.parentElement.clientHeight // измеряем clietnHeight элемента html
	} else if(document.body&&document.body.clientHeight){
	return document.body.clientHeight;
	}
	return 0;
}

function setSizes(){
	var theTableDom=findDOM('set_height',1);
	var theHeight=getInsideWindowHeight();
	theTableDom.height=theHeight+'px';
}


// Функция проверки включена ли у пользователя функция  Сookie
function cookieVkl(){
  return (navigator.cookieEnabled)? true:false;
}
// Добавляем товар в корзину
function add_to_basket(model_name, objID){
	 if(cookieVkl())
	 {
	  var user_basket=get_cookie('tovar_v_korzine');
	  if(!user_basket){user_basket="";}
	  user_basket+=escape(model_name)+ '&';
	  set_cookie('tovar_v_korzine',user_basket);
	  see_tov();
	  domStyle = findDOM(objID,1);
	  domStyle.visibility='visible';		
	  setTimeout('domStyle.visibility="hidden"',1000);//time is  over

	 }
	 else{
		alert('Уважаемый  покупатель, для полноценной  работы нашего магазина, небходимо вклsчить функция "СOOKIE" Вашего бgаузеgа!\n  Надеемся, что  iто  неудобство не доставит  Вам много  хопот.');
		window.location='forma_bez_cookie.htm';
		}
}




function set_cookie(cookie_name, cookie_value, cookie_expire, cookie_path, cookie_domain, cookie_secure) {

	var hidden_cookie_value=cookie_value;
	// Begin the cookie parameter string
	var cookie_string = cookie_name + "=" +hidden_cookie_value;
	
	// Add the expiration date, if it was specified
	if (cookie_expire) {
		var expire_date = new Date()
		var ms_from_now = cookie_expire * 24 * 60 * 60 * 1000
		expire_date.setTime(expire_date.getTime() + ms_from_now)
		var expire_string = '';
		cookie_string += "; expires=" + expire_string
	}
// Add the path, if it was specified
	cookie_path='/';
		cookie_string += "; path=" + cookie_path
	// Add the domain, if it was specified
	if (cookie_domain) {
		cookie_string += "; domain=" + cookie_domain
	}
	
	// Add the secure boolean, if it's true
	if (cookie_secure) {
		cookie_string += "; true"
	}
	
	// Set the cookie
	document.cookie = cookie_string

}

function get_cookie(name_to_get) {

	var cookie_pair;
	var cookie_name;
	var cookie_hidden_value;

	// Split all the cookies into an array
	var cookie_array = document.cookie.split("; ")
	
	// Run through the cookies
	for (var counter = 0; counter < cookie_array.length; counter++) {
	
		// Split the cookie into a name/value pair
		cookie_pair = cookie_array[counter].split("=")
		cookie_name = cookie_pair[0]
		cookie_hidden_value = cookie_pair[1]
		
		// Compare the name with the name we want
		if (cookie_name == name_to_get) {
		
			// If this is the one, return the value
			return unescape(cookie_hidden_value);
		}
	}
	
	// If the cookie doesn't exist, return null
	return null
}

function delete_cookie(cookie_name) {
	 set_cookie(cookie_name, "", -1,"/")
}

//  Кодирование  Cookie
function encode_cookie(cookie_value){
	// Эта переменная содержит закодированные символы
	var coded_string="";
	
	for (var counter=0; counter<cookie_value.length;counter++){
		// Шифруем
		coded_string+=cookie_value.charCodeAt(counter);
		
		//Разделение каждого кода  знаком +
		if(counter<cookie_value.length-1){coded_string+="+";}
	}
	return coded_string;
}

//  Кодирование  Cookie
function decode_cookie(coded_string){
	// Эта переменная содержит декодированное значение
	var cookie_value='';
	// разделяем  строку по плюсам
	var code_array=coded_string.split('+');
	// просмотр массива
	for(var counter=0; counter<code_array.length; counter++){cookie_value+=String.fromCharCode(code_array[counter])}
	return cookie_value;
}

	
function see_tov(){
	 user_basket=get_cookie('tovar_v_korzine');
	  if(!user_basket){document.bus.tov.value=0;}
	   var full_basket=unescape(get_cookie('tovar_v_korzine'));
   // разлагаем на строки по каждой позиции
   var pseudo_cookie=full_basket.split('&');
	document.bus.tov.value=pseudo_cookie.length-1;
}	


 function mandatory_fields_completed() 
{
	
	var missing_fields = new Array();
	var total_missing = 0;
	
	// Loop through all the form elements
	for (var counter = 0; counter < document.otpravit.length; counter++)
	{	
		// Is this a visible text field that's mandatory?
		if ( document.otpravit[counter].type == "text" || document.otpravit[counter].type == "textarea" )
		{			  
		   if (its_empty(document.otpravit[counter].value)) {missing_fields[total_missing] = document.otpravit[counter]; total_missing++; }
		}
	}

	// Were there any fields missing?
	if (total_missing > 0)
	{	
		 alert("Извините, но  все поля формы должны быть  заполнены");		
		// For emphasis, put the focus on the first missing field
		missing_fields[0].focus();	   
		return false;
	}
	else {return true;}
}


 
function its_empty(string_value) {

	// Check for the empty string and null
	if (string_value == "" || string_value == null) {
	
		// If either, it's empty so return true
		return true
	}
	
	// Otherwise, it's not empty so return false
	return false
}


function ch_form(){
	if (!vse_zapolneno()) {return;}
	// Is the email address valid?
	if (!valid_email(document.pochta_form.pochta.value))
	 {
		alert("Пожалуйста,  введите  правильный электронный  адрес")
		document.pochta_form.pochta.focus(); document.pochta_form.pochta.select();
	 }
     //
	document.pochta_form.submit();
}

 function vse_zapolneno() 
{
	var missing_fields = new Array();
	var total_missing = 0;
	var the_form = document.pochta_form;
	// Loop through all the form elements
	for (var counter = 0; counter < the_form.length; counter++)
	{	
		// Is this a visible text field that's mandatory?
		if ( the_form[counter].type == "text" || the_form[counter].type == "textarea" )
		{			  
		   if (its_empty(the_form[counter].value)) {missing_fields[total_missing] = the_form[counter]; total_missing++; }
		}
	}

	// Were there any fields missing?
	if (total_missing > 0)
	{	
		 alert("Извините, но  все поля формы должны быть  заполнены");		
		// For emphasis, put the focus on the first missing field
		missing_fields[0].focus();	   
		return false;
	}
	else {return true;}
}

function valid_email(email_address) {

	// Check the length
	if (email_address.length < 5) {
		return false
	}

	// Check @ and .
	at_location = email_address.indexOf("@")
	dot_location = email_address.lastIndexOf(".")

	if (at_location == -1 || dot_location == -1 || at_location > dot_location ) {
		return false
	}

	// Is there at least one character before @?
	if (at_location == 0) {
		return false
	}

	// Is there at least one character between @ and .?
	if (dot_location - at_location < 2 ) {
		return false
	}

	// Is there at least one character after .?
	if (email_address.length - dot_location < 2) {
		return false
	}

	// Otherwise, it's a valid address, so return true
	return true
}

function openMenu(objectID)
 {
 	domStyle=findDOM(objectID,1);
	if(domStyle.display=='block') domStyle.display='none';
	else domStyle.display='block';
 }


