String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
} // -------------------------------------------------------------------------------------------

function truncateForm( form ) {
    for( i = 0 ; i < form.length ; i++ )
    {
        if( form.elements[i].type == 'text' || form.elements[i].type == 'textarea' )
            form.elements[i].value = form.elements[i].value.trim();
    };
}


function searchFormSubmit() {

    var form = document.searchform;
    truncateForm(form); 

    if (form.keyword.value=="") {
        alert("Lúðöøªõ, ÿþöðûºù¸ªð, ¸ûþòþ ôû  ÿþø¸úð!");
        form.keyword.focus();
        return false;
    }

    return true;
    //document.searchform.submit();
}

function openWinnn(x,title,wid,hei) {
  myWin= open("", "_blank", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width="+wid+",height="+hei);
  myWin.document.open();
  myWin.document.write("<html><head><title>"+title+"</title></head>");
  myWin.document.write("<body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>");
  myWin.document.write("<img src='"+x+"' width='"+wid+"' height='"+hei+"'>");
  myWin.document.write("</body></html>");
  myWin.document.close();  
}

function isNumber( value ) {
    return !isNaN(value);
}


function checkItem(id,status) {
    document.getElementById('count'+id).disabled    = status;
    
}

function checkProductsForm() {
    var form = document.productForm;
    //truncateForm(form); 
    

    for(var i=0;i<form.length;i++) {
        
        if( (form.elements[i].type == 'text') && (!form.elements[i].disabled) && (!isNumber(form.elements[i].value) || (form.elements[i].value==0)) ){
            alert(o2);
            form.elements[i].focus();
            return false;
        }
    };
    
    return checkForm('pr[]',o1);
}

                
function checkBasketForm() {
    var form = document.basketform;
    truncateForm(form); 
    


    for(var i=0;i<form.length;i++) {
        if( (form.elements[i].type == 'text') && (!isNumber(form.elements[i].value) || (form.elements[i].value==0)) ){
            if (document.getElementById('c'+form.elements[i].id.replace("count","")).checked) continue;
                alert("Ïîæàëóéñòà, ââåäèòå êîððåêòíûå çíà÷åíèÿ êîëè÷åñòâà òîâàðîâ!");
                form.elements[i].focus();
                return false;
        }
    };

    return true;//checkForm('pr[]','¦¦¡¨v¦•¬ê¨, ¦·¨¡°ê¿ ê¦ª¨èv ¯và ¦¯¨v¿¤°à!');;
}

function setCheck(id,checked,bgcolor) {
    document.getElementById('count'+id).disabled=!checked;              
    //document.getElementById('line'+id).style.backgroundColor = (!checked)?bgcolor:"#FFFDE6";
    if (checked && document.getElementById('count'+id).value==0) document.getElementById('count'+id).value = 1;
}                 


function checkForm(elName,msg,flag)
{
    if ( arguments.length < 3 ) flag = true;
    var elm = document.all[elName];
    if(elm.length>0)
    {
        for(var i=0;i<elm.length;i++)
            if (elm[i].checked) return true;
    }
    else
    {
        if(elm.checked) return true;
    }
    if (flag) alert(msg);
    return false;
} // -------------------------------------------------------------------------------------------


function checkFeedForm() {  
    
    truncateForm(document.sendform);
    
    /*if (document.sendform.name.value=="") {
        alert('Ïîæàëóéñòà, óêàæèòå ñâîå èìÿ!');
        document.sendform.name.focus();
        return false;
    }*/
    
    if (document.sendform.email.value!="" && !isEmail(document.sendform.email.value)) {
        alert('Ïîæàëóéñòà, óêàæèòå ñâîé E-Mail!');
        document.sendform.email.focus();
        return false;
    }
    

    if (document.sendform.message.value=="") {
        alert('Èçâèíèòå, Âû íå ìîæåòå îòîñëàòü ïóñòîå ñîîáùåíèå!');
        document.sendform.message.focus();
        return false;
    }

}

function isEmail( str ) {
    var supported = 0;

    if (window.RegExp) 
    {
        var tempStr = "a";
        var tempReg = new RegExp(tempStr);
        if (tempReg.test(tempStr)) supported = 1;
    }
    if (!supported) 
        return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
    var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
    var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
    str = str.replace(/ /,'');
    return (!r1.test(str) && r2.test(str));
}


function _el (id){
return document.getElementById(id);
}


xmlhttp = false;

function escapeParam( val ) {
    return escape(encodeURIComponent(val)).replace(/\+/g,'%2B');
}

function initRequest(){

    var xmlhttptemp = false;

    if(window.XMLHttpRequest) {
        try {
            xmlhttptemp = new XMLHttpRequest();
        } catch(e) {
            xmlhttptemp = false;
        }
    } else if(window.ActiveXObject) {
        try {
            xmlhttptemp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(e) {
            try {
                xmlhttptemp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch(e) {
                xmlhttptemp = false;
            }
        }
    }
    return xmlhttptemp;
}

function escapeParam( val ) {
    return escape(encodeURI(val)).replace(/\+/g,'%2B');
}



function makeRate(from) {
    xmlhttp = initRequest();
    xmlhttp.onreadystatechange=makeRate_results;
    
    var sel = 1;
    if (_el('r5').checked) sel = 1;
    if (_el('r4').checked) sel = 2;
    if (_el('r3').checked) sel = 3;
    if (_el('r2').checked) sel = 4;
    if (_el('r1').checked) sel = 5;

    var url = siteurl + '/' + lang + '/makeRate/?'
        +'id='+escape(_el('product_id').value).replace(/\+/g,'%2B')
        +'&rate='+escape(sel).replace(/\+/g,'%2B');

    xmlhttp.open("GET", url
        , true);


    xmlhttp.send(null);
}
function makeRate_results()
{
    if (xmlhttp.readyState==4){
        if (xmlhttp.status == 200) {
            _el('p1').innerHTML = xmlhttp.responseText;
            _el('ratetable').style.display = 'none';
        } else {
            alert("There was a problem retrieving the XML data:\n" + xmlhttp.statusText);
        }
    }
}
