var preloadedImages = new Array();

function preloadImages(locationFolder) {
    if(document.images) {
            var i, args = preloadImages.arguments; 
            for(i=1; i<args.length; i++) {
                preloadedImages[args[i]]     = new Image(); 
                preloadedImages[args[i]].src = locationFolder + args[i] + '.gif';
            }
    }
}


function rollOn(imageName) {
    if(document.images && preloadedImages[imageName + "_over"]) {
    	document.images[imageName].src = preloadedImages[imageName + "_over"].src;
    }
}


function rollOff(imageName) {
    if(document.images && preloadedImages[imageName + "_over"])
	document.images[imageName].src = preloadedImages[imageName + "_normal"].src;
}
//------------------------------------
// Установка куки
function setCookie(name, value, expires, path, domain, secure) {
		var caution;
        var curCookie = name + "=" + escape(value) +
                ((expires) ? "; expires=" + expires.toGMTString() : "") +
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                ((secure) ? "; secure" : "")
        if (!caution || (name + "=" + escape(value)).length <= 4000)
                document.cookie = curCookie
        else
                if (confirm("Cookie превышает 4KB и будет вырезан !"))
                        document.cookie = curCookie;
		return true;
}

//------------------------------------
// получение  куки
function getCookie(name) {
		var cname="";
        var prefix = name + "="
        var cookieStartIndex = document.cookie.indexOf(prefix)
        if (cookieStartIndex == -1)
                return cname
        var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
        if (cookieEndIndex == -1)
                cookieEndIndex = document.cookie.length
        var cname = unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
		
		return cname
}

//------------------------------------

//window.onload = init();
//document.onload = loadform();


function init() {

  var product1="";
   var tab = document.getElementById('catalogue_tbl');
   if(!tab) {
   //alert("NO");
      return;
   }
   for(var i=tab.rows.length-1; i>=0; i--) {
      tab.rows[i].ondblclick = rowClick;
   }
   function rowClick() {
 //this.className = this.className == "highlight" ? "" : "highlight";
 row = this;
		for(var i=0; i<=row.cells.length-1; i++) {
		product1 += row.cells[i].innerHTML + " ";
		}
	document.getElementById("products").value += "'" + product1 + "'\n";
	product1 = "";
	saveform();
	}
}

// сохранение данных формы
function saveform()
{	 var company_name = document.getElementById("company_name").value;
	 setCookie("company_name",company_name);	 
	 var contact_name = document.getElementById("contact_name").value;	 
	 setCookie("contact_name",contact_name);
	 var phone = document.getElementById("phone").value;
	 setCookie("phone",phone);
	 var email = document.getElementById("email").value;
	 setCookie("email",email);
	 var products = document.getElementById("products").value;
	 setCookie("products",products);
    return true;
}

//------------------------------------
// загрузка данных формы
function loadform()
{	 
	//name1 = ;
	document.getElementById("company_name").value = getCookie("company_name");
	document.getElementById("contact_name").value = getCookie("contact_name");
	document.getElementById("phone").value = getCookie("phone");
	document.getElementById("email").value = getCookie("email");
	document.getElementById("products").value = getCookie("products");
	
	//alert("company name: " + name1);
    return true;
}

//------------------------------------
// не используется

function writepagenum(num)
{	 
	if (document.getElementById) {    
  	target = document.getElementById('hdnfrm');
	target.value = num;
	}
    return false;
}

function post(varHash) { //по-моему, передавать аргументы хешем удобнее, чем массивом
    var form = document.createElement("form"), tmp;
    form.action = self.location;
    form.method = "post";
    form.id = "tmp_form_for_post_submit";
    for (var param in varHash) {
      tmp = document.createElement("input");
      tmp.type = "hidden";
      tmp.name = param;
      tmp.value = varHash[param];
      form.appendChild(tmp);
    }
    document.body.appendChild(form);
    //form.submit();
  return false;	
}

var currentlyActiveInputRef = false;
var currentlyActiveInputClassName = false;
 
function highlightActiveInput()
{
    if(currentlyActiveInputRef){
        currentlyActiveInputRef.className = currentlyActiveInputClassName;
    }
    currentlyActiveInputClassName = this.className;
    this.className = 'inputHighlighted';
    currentlyActiveInputRef = this;
    
    
}
 
function blurActiveInput()
{
    this.className = currentlyActiveInputClassName;
    
    
}
 
 
function initInputHighlightScript()
{
    var tags = ['INPUT','TEXTAREA'];
    
    for(tagCounter=0;tagCounter<tags.length;tagCounter++){
        var inputs = document.getElementsByTagName(tags[tagCounter]);
        for(var no=0;no<inputs.length;no++){
            if(inputs[no].className && inputs[no].className=='doNotHighlightThisInput')continue;
            
            if(inputs[no].tagName.toLowerCase()=='textarea' || 
            (inputs[no].tagName.toLowerCase()=='input' && inputs[no].type.toLowerCase()=='text')){
                inputs[no].onfocus = highlightActiveInput;
                inputs[no].onblur = blurActiveInput;
            }
        }
    }
}

