﻿window.onload = f_Init;

function f_FidProductsChange(x){

    if(x==1){
        document.getElementById('fid_branch').selectedIndex=0;
        document.getElementById('fid_application').selectedIndex=0;
        document.getElementById('fid_chemicalgroup').selectedIndex=0;
    }
    document.forms['fprods'].submit()
}
function f_ShowProductDocuments(id){
    document.getElementById('fid_showdocuments').value=id;
}
function f_Init()
{
    if(xAlert!='') alert(xAlert);
    document.TabGen=document.getElementById('mTabGen');
    document.onmousemove=f_MouseMove;
    if(document.getElementById('map')!=null) f_LoadMap();
}
function f_MouseMove(e)
{
    var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	
	posx=e.clientX-document.TabGen.offsetLeft;
	posy=e.clientY-document.TabGen.offsetTop+getScrollHeight();
	
	if(posy<116 || posy>204 || posx<0 || posx>777) f_ShowSubMenu(0);
    else if(posx<129 && posy<172) f_ShowSubMenu(1);
    else if(posx<261 && posy<172) f_ShowSubMenu(2);
    else if(posx<392 && posy<172) f_ShowSubMenu(3);
    else if(posx<522 && posy<172) f_ShowSubMenu(4);
    else if(posx<587 && posy<172) f_ShowSubMenu(5);

}
function getScrollHeight()
{
   var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;
           
   return h ? h : 0;
}
function f_ShowSubMenu(id)
{
    var e,speed = 3,timer = 0;
    
    for(i=1;;i++)
    {
        e=document.getElementById('mSubMenu'+i);
        if(!e) return;
        e=e.style;
        if(i==id) e.display='block';
        else e.display='none'
    }
}
function f_ChangeOpac(opacity, obj) {
    var style=obj.style;
    style.opacity = (opacity / 100);
    style.MozOpacity = (opacity / 100);
    style.KhtmlOpacity = (opacity / 100);
    style.filter = "alpha(opacity=" + opacity + ")";
}
function f_OpacityArrayGet(id)
{
    if(document.OpacityArrayStatus==null)
        document.OpacityArrayStatus=new Array(0);
    
    for(i=0;i<document.OpacityArrayStatus.length;i++)
        if(document.OpacityArrayStatus[i].obj.id==id)
            return document.OpacityArrayStatus[i];
            
    obj=new Object();
    obj.obj=document.getElementById(id);
    obj.opacityStatus=0;
    obj.opacity=50;
    
    document.OpacityArrayStatus.push(obj);
    return obj;
}
function f_BoxOpacity()
{
    var f=0,el;
    
    for(i=0;i<document.OpacityArrayStatus.length;i++)
    {
        el=document.OpacityArrayStatus[i];
        
        if(el.opacityStatus==1){
            if (el.opacity==100) 
                el.opacityStatus=0;
            else{
                el.opacity++;
                f_ChangeOpac(el.opacity,el.obj);
                f=1;}
            }
        else if(el.opacityStatus==-1){
            if (el.opacity==50) 
                el.opacityStatus=0;
            else{
                 el.opacity--;
                 f_ChangeOpac(el.opacity,el.obj);
                 f=1;}
            }
    }
    
    if(f==1) setTimeout("f_BoxOpacity()",30);
}
function f_BoxIn(id)
{
    f_OpacityArrayGet(id).opacityStatus=1;
    f_BoxOpacity();
}
function f_BoxOut(id)
{
    f_OpacityArrayGet(id).opacityStatus=-1;
    f_BoxOpacity();
}
function f_MenuImagesSplit(obj,img)
{
    obj.src=img;
}
function f_ValidateStandardForm()
{
    var el,elh;
    
    for(i=0;;i++){
    
        el=document.getElementById('fid_sci'+i);
        if(el==null) return true;
        
        elh=document.getElementById('fid_scih'+i);
        if(elh==null) continue;
        
        if(el.value!='') continue; 
        
        alert(elh.value);
        return false;
    }
    
}
function f_CheckPassword(password) {
    if(password.length<6) return false;
    return true;
}
function f_CheckEmail(email) {

    var valid = "y";

    if (email != "") {
        if (email.length<7 || email.indexOf("@.") != -1 || email.indexOf("-.") != -1 || email.indexOf("_.") != -1 ||
                email.indexOf("..") != -1 || email.indexOf("._") != -1 || email.indexOf(".-") != -1 || 
                email.indexOf(".@") != -1 || email.indexOf("@-") != -1 || email.indexOf("@_") != -1 ||
                email.indexOf("@") != email.lastIndexOf("@") || email.indexOf("@") == -1 || email.indexOf(".") == -1 ||
                (email.length - (email.lastIndexOf(".") + 1)) < 2) 
            return false;
        else {
            a = "abcdefghijklmnopqrstuvwxyz0123456789@-_.";
            b = 0;
            while (b < email.length) {
                if (a.indexOf(email.charAt(b)) == -1) return false;
                b = b + 1;
            }
        }
    }

    rx = /^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.[a-z][a-z]$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.aero$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.biz$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.coop$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.com$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.edu$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.gov$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.info$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.int$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.mil$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.museum$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.name$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.net$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.org$|^[a-z0-9\._]*[a-z0-9_]@[a-z0-9][a-z0-9\-\.]*[a-z0-9]\.pro$/i;
    if (rx.test(email)) {
        rx = /^[a-z0-9_]/i;
        if((rx.test(email))) return true;
    }
    
    return false;
}
