var printtext=" ";
 
if (document.images)
{
	var b1=new Image();
	b1.src="images/menu/b1.gif";
	var b1on=new Image();
	b1on.src="images/menu/b1on.gif";
	
	var b2=new Image();
	b2.src="images/menu/b2.gif";
	var b2on=new Image();
	b2on.src="images/menu/b2on.gif";
	
	var b3=new Image();
	b3.src="images/menu/b3.gif";
	var b3on=new Image();
	b3on.src="images/menu/b3on.gif";
	
	var b4=new Image();
	b4.src="images/menu/b4.gif";
	var b4on=new Image();
	b4on.src="images/menu/b4on.gif";
	
	var b5=new Image();
	b5.src="images/menu/b5.gif";
	var b5on=new Image();
	b5on.src="images/menu/b5on.gif";

	var b6=new Image();
	b6.src="images/menu/b6.gif";
	var b6on=new Image();
	b6on.src="images/menu/b6on.gif";	

	var b7=new Image();
	b7.src="images/menu/b7.gif";
	var b7on=new Image();
	b7on.src="images/menu/b7on.gif";
}

function act(imgName) {
	if (document.images){
		document[imgName].src=eval(imgName+'.src');
		}
	}


function inact(imgName) {
	if (document.images){
		document[imgName].src=eval(imgName+'on.src');
		}
	}
    
// confirm

function emailCheck(str) {
  var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
//  window.alert(str);
//  window.alert(filter.test(str));
  return (filter.test(str));
}
    
function confirmAction(objectid, actionDesc) {
    var formname=document.getElementById(objectid);
    b=window.confirm(actionDesc);
    if (b) {
        
        formname.submit();
    } else {
        return false;
    } 
    }

function formSubmit(objectid) {
    var formname=document.getElementById(objectid);
//     window.alert(formname);
//     b=window.confirm(actionDesc);
//     if (b) {
        
    formname.submit();
//     } else {
//         return false;
//     } 
}
    
// focus by object id (use after inputfield is initialized)
function setFocus(objectid) 
{
    var inputfield=document.getElementById(objectid);
    inputfield.focus();
}

// SEARCH functions
function hide(objectid)
{
        var box=document.getElementById(objectid);
        box.className = 'box-hidden';
}

function show(objectid)
{
        var box=document.getElementById(objectid);
        box.className = 'box-show';
}

function showhide(objectid) 
{
    var box=document.getElementById(objectid);
    if (box.className == 'box-show') {
        box.className = 'box-hidden';
    } else {
        box.className = 'box-show';   
    }
    
}

function switchColor(objectid) {
        var box=document.getElementById(objectid);
        var boxImage=document.getElementById(objectid+'_pic');

        if (box.className == 'box-show') {
                box.className = 'box-hidden';
                boxImage.src='/img/msgdown.gif';
        } else {
                box.className = 'box-show';
                boxImage.src='/img/msgup.gif';
        }
}

function productinfo(address,windowheight) {
            var NewRemote = window.open("","Tuote","toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,width=650,height="+windowheight);
            NewRemote.location=address;
        }

function popupWrite(ptitle,txt,windowheight) {
            var NewRemote = window.open("",ptitle,"toolbar=yes,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=650,height="+windowheight);
            NewRemote.document.write(txt);
//             NewRemote.document.bgColor="lightblue"
            NewRemote.document.close();
        }
        
function addOne2Cart(ID) {
         if (document.getElementById(ID).value=='') {
                document.getElementById(ID).value=1;
                }
        }

function add2Cart(ID) {
                if (document.getElementById(ID).value=='') {
                        start=0;
                        }
                        else
                        {
                        start=parseInt(document.getElementById(ID).value);
                        }
                document.getElementById(ID).value=start+1;

        }



//SEARCH functions end

        
// ORDER CHECK

function checkorder() {
        var d = document.order;
        var a=true;
        var b=true;
        var t='';

           // tarkista laskutus

//        if (document.getElementById('cgidata.order.vastuualue').value == '') {t=t+'Vastuualue puuttuu!\n'; b= false;}
//        if (document.getElementById('cgidata.order.yksikko').value == '') {t=t+'Yksikko puuttuu!\n'; b= false;}
//        if (document.getElementById('cgidata.order.destination.name').value == '') {t=t+'Vastaanottajan nimi puuttuu!\n'; b=false;}
//        if (document.getElementById('cgidata.order.name').value == '') {t=t+'Testing nimi puuttuu!\n'; b=false;}
//        if (document.getElementById('cgidata.order.email').value == '') {t=t+'Testing email puuttuu!\n'; b=false;}
//        if (document.getElementById('cgidata.order.destination.company').value == '') {t=t+'Toimipaikan nimi puuttuu!\n'; b=false;}
//        if (document.getElementById('cgidata.order.destination.address').value == '') {t=t+'Toimipaikan osoite puuttuu!\n'; b=false;}
//        if (document.getElementById('cgidata.order.destination.zip').value == '') {t=t+'Toimipaikan postinumero puuttuu!\n'; b=false;}
//        if (document.getElementById('cgidata.order.destination.city').value == '') {t=t+'Toimipaikan kaupunki puuttuu!\n'; b=false;}
//        if (document.getElementById('cgidata.order.destination.phone').value == '') {t=t+'Toimipaikan puhelin puuttuu!\n'; b=false;}

        if (document.getElementById('cgidata.order.accept').checked == false) {t=t+'Oletko hyväksynyt toimitusehdot?\n'; b=false;}

        if (!b) {window.alert('Lomakkeessa havaittiin puutteita:\n\n'+t); return  false}
}

// ORDER CHECK end

function formSubmitPubOrder(objectid, callerfunction) {
    var formname=document.getElementById(objectid);
//     window.alert(callerfunction);
//     return false;
    if (callerfunction == "paymentmethod") {
        if ((document.getElementById('cgidata.order.paymentmethod').value == 'postiennakko') && (document.getElementById('cgidata.order.payment').value != 'postiennakko')) {window.alert('Toimitustapa vaihdettu postiennakoksi!\n'); document.getElementById('cgidata.order.payment').value = 'postiennakko'; }
    }
    
    document.getElementById('cgidata.order.deliverygroup').value = document.getElementById('cgidata.order.payment').value;
    
    if (document.getElementById('cgidata.order.payment').value == 'postiennakko') {
        document.getElementById('cgidata.order.paymentmethod').value = 'postiennakko' ;
    } else {
        if (document.getElementById('cgidata.order.paymentmethod').value == 'postiennakko') {
            document.getElementById('cgidata.order.paymentmethod').value = 'valitse' ;
        }
    }
//     window.alert(formname);
//     b=window.confirm(actionDesc);
//     if (b) {
        
    formname.submit();
//     } else {
//         return false;
//     } 
}


// ORDER CHECK PUBLIC


function checkorder_public() {
        var d = document.order;
        var a=true;
        var b=true;
        var t='';
   
        if (((document.getElementById('cgidata.order.payment').value == 'postiennakko') && (document.getElementById('cgidata.order.paymentmethod').value != 'postiennakko')) || ((document.getElementById('cgidata.order.payment').value != 'postiennakko') && (document.getElementById('cgidata.order.paymentmethod').value == 'postiennakko'))) { t=t+'Maksutapa ja toimitustapa yhdistelmä ei ole mahdollinen!\n'; b=false; }
            
        // tarkista laskutus

//         if (document.getElementById('cgidata.order.vastuualue').value == '') {t=t+'Vastuualue puuttuu!\n'; b= false;}
//         if (document.getElementById('cgidata.order.yksikko').value == '') {t=t+'Yksikko puuttuu!\n'; b= false;}

//         if (document.getElementById('cgidata.order.destination.name').value == '') {t=t+'Vastaanottajan nimi puuttuu!\n'; b=false;}
        
          if (document.getElementById('cgidata.order.name').value == '') {t=t+'Tilaajan nimi puuttuu!\n'; b=false;}
        
//           if (document.getElementById('cgidata.order.email').value == '') {t=t+'Tilaajan email ei ole käypä!\n'; b=false;}
           if (!emailCheck(document.getElementById('cgidata.order.email').value)) {t=t+'Tilaajan e-mail ei ole käypä!\n'; b=false;}
        
//         if (document.getElementById('cgidata.order.destination.company').value == '') {t=t+'Toimipaikan nimi puuttuu!\n'; b=false;}
        
        
        if (document.getElementById('cgidata.order.destination.address').value == '') {t=t+'Toimipaikan osoite puuttuu!\n'; b=false;}
        
        
        if (document.getElementById('cgidata.order.destination.zip').value == '') {t=t+'Toimipaikan postinumero puuttuu!\n'; b=false;}
        
        if (document.getElementById('cgidata.order.destination.city').value == '') {t=t+'Toimipaikan kaupunki puuttuu!\n'; b=false;}
        
        
         if (document.getElementById('cgidata.order.destination.phone').value == '') {t=t+'Toimipaikan puhelin puuttuu!\n'; b=false;}

         if (document.getElementById('cgidata.order.accept').checked == false) {t=t+'Oletko hyväksynyt toimitusehdot? \n'; b=false;}
         
         if (document.getElementById('cgidata.order.payment').value == 'valitse') {t=t+'Toimitustapa pitää valita! \n'; b=false;}

         if (document.getElementById('cgidata.order.payment').value == '') {t=t+'Toimitustapa pitää valita! \n'; b=false;}
         
         if (document.getElementById('cgidata.order.paymentmethod').value == 'valitse') {t=t+'Maksutapa pitää valita! \n'; b=false;}

         if (document.getElementById('cgidata.order.paymentmethod').value == '') {t=t+'Maksutapa pitää valita! \n'; b=false;}
         

        if (!b) {window.alert('Lomakkeessa havaittiin puutteita:\n\n'+t); return  false}
}

// ORDER CHECK PUBLIC end

