var dragObj = "";
var windows = new Array();
var objIndex = 10000;
var mainZIndex = 1;

function showAlert2(alertID, title, msg, subtitle, width, height) {
	width = typeof(width) != 'undefined' ? width : '600';
	height = typeof(height) != 'undefined' ? height : '300';
        if (alertID == 0) mainZIndex ++;
        makeAllTransparent(15);
        //el = document.getElementById("pagecell1");

        if (!alertID)
        {
                alertID = generateID();
                alertTxt = '<table border="0" cellpadding="0" cellspacing="0" id="divAlertID_'+alertID+'_innerTable">'+
                                                '        <tr>'+
                                                '                <td align="left" id="divAlertID_'+alertID+'_firstTD" height="20"><img id="alertTitle_'+alertID+'" src="images/poptab_'+title+'.gif" ></td>'+
                                                '                <td width="5" rowspan="2" align="right" valign="bottom" height="95%">'+
                                                '                        <table width="5" height="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#eeeeee">'+
                                                '                                <tr>'+
                                                '                                        <td><img src="images/transparent.gif" width="5" height="1"></td>'+
                                                '                                </tr>'+
                                                '                        </table>'+
                                                '                </td>'+
                                                '        </tr>'+
                                                '        <tr>'+
                                                '                <td id="divAlertID_'+alertID+'_secondTD" align="left" valign="top" bgcolor="#FFFFFF" class="popborder">'+
                                                '                        <table border=0 height='+height*0.95+' width='+width+' id="divAlertID_'+alertID+'_mainTable">'+
                                                '                                <tr>'+
                                                '                                        <td id="alertSubTitle_'+alertID+'">'+subtitle+'</td>'+
                                                '                                        <td align="right"><a href="#self" onclick="hideAlert2('+alertID+');"><img border="0" src="images/bttn_close_up.gif" name="bttnclose" width="13" height="13" id="bttnclose" onMouseOver="MM_swapImage(\'bttnclose\',\'\',\'images/bttn_close_over.gif\',0)" onMouseOut="MM_swapImgRestore()"></a</td>'+
                                                '                                </tr>'+
                                                '                                <tr>'+
                                                '                                        <td colspan=2 class="alert" id="alertBody_'+alertID+'" width='+width+' height='+height+'>' + msg + '</td>' +
                                                '                                <tr>'+
                                                '                        </table>'+
                                                '                </td>'+
                                                '        </tr>'+
                                                '        </tr>'+
                                                '                <td height="5" colspan="2" align="right" valign="top">'+
                                                '                        <table width="95%" height="5" border="0" cellpadding="0" cellspacing="0" bgcolor="#eaeaea">'+
                                                '                                <tr>'+
                                                '                                 <td width="100%" bgcolor="#eaeaea"><img src="images/transparent.gif" width="1" height="5"></td>'+
                                                '                                </tr>'+
                                                '                        </table>'+
                                                '                </td>'+
                                                '        </tr>'+
                                                '</table>';

                el = document.createElement("div");
                el.id = "divAlert_" + alertID;
                el.style.position =  'absolute';
                el.style.zIndex =  10;
                el.innerHTML = alertTxt;

                bdy = document.getElementsByTagName("body");
                bdy[0].appendChild(el);
        } else {
                if (title)
                {
                        x = document.getElementById("alertTitle_" + alertID);
                        x.src = 'images/poptab_'+title+'.gif';
                }
                x = document.getElementById("alertBody_" + alertID);
                x.innerHTML = msg;
                if (subtitle)
                {
                        x = document.getElementById("alertSubTitle_" + alertID);
                        x.innerHTML = subtitle;
                }
        }

		if (el)
		{
			el.style.display='block';
			el.style.zIndex = mainZIndex ;

			h = el.offsetHeight;
			w = el.offsetWidth;
			
			y=getScrollLength("top") + document.documentElement.clientHeight / 2 - (h/2);
			x=getScrollLength("left") + document.documentElement.clientWidth /2 -(w/2);

			el.style.top = Math.max(0, y) + "px";
			el.style.left = Math.max(0, x) + "px";
		}
        
        return alertID;
}

function hideAlert2(id) {

        el = document.getElementById("divAlert_" + id);
        el.style.display='none';

        mainZIndex --;
        if (mainZIndex <= 1) setOpacity(100);
}


function getWaitIcon() {
      return "<center> ... please wait ... <br /><br /><img src='images/logo.gif'></center>";   
}


//PHP:
///** comment here */
//function showPrivacy() {
//          $vPage = new CPage("privacy");
//          $txt = '<div style="width:620px; height:350px;  ">'.$vPage->mRowObj->Txt.'</div>';
//          $xml = "<content>".xmlentities($txt) . "</content>";
//          Return xml($xml);

//}

function generateID() {
        objIndex = objIndex + 1;
        return objIndex;
}

function getScrollLength(orientation) {
        if (BrowserDetect.browser == "Explorer" || BrowserDetect.browser == "Firefox")
        {
                if (orientation == "top") return document.documentElement.scrollTop;
                if (orientation == "left") return document.documentElement.scrollLeft;
        } else {
                if (orientation == "top") return document.body.scrollTop;
                if (orientation == "left") return document.body.scrollLeft;
        }
}



var BrowserDetect = {
        init: function () {
                this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
                this.version = this.searchVersion(navigator.userAgent)
                        || this.searchVersion(navigator.appVersion)
                        || "an unknown version";
                this.OS = this.searchString(this.dataOS) || "an unknown OS";
        },
        searchString: function (data) {
                for (var i=0;i<data.length;i++)        {
                        var dataString = data[i].string;
                        var dataProp = data[i].prop;
                        this.versionSearchString = data[i].versionSearch || data[i].identity;
                        if (dataString) {
                                if (dataString.indexOf(data[i].subString) != -1)
                                        return data[i].identity;
                        }
                        else if (dataProp)
                                return data[i].identity;
                }
        },
        searchVersion: function (dataString) {
                var index = dataString.indexOf(this.versionSearchString);
                if (index == -1) return;
                return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
        },
        dataBrowser: [
                {         string: navigator.userAgent,
                        subString: "OmniWeb",
                        versionSearch: "OmniWeb/",
                        identity: "OmniWeb"
                },
                {
                        string: navigator.vendor,
                        subString: "Apple",
                        identity: "Safari"
                },
                {
                        prop: window.opera,
                        identity: "Opera"
                },
                {
                        string: navigator.vendor,
                        subString: "iCab",
                        identity: "iCab"
                },
                {
                        string: navigator.vendor,
                        subString: "KDE",
                        identity: "Konqueror"
                },
                {
                        string: navigator.userAgent,
                        subString: "Firefox",
                        identity: "Firefox"
                },
                {
                        string: navigator.vendor,
                        subString: "Camino",
                        identity: "Camino"
                },
                {                // for newer Netscapes (6+)
                        string: navigator.userAgent,
                        subString: "Netscape",
                        identity: "Netscape"
                },
                {
                        string: navigator.userAgent,
                        subString: "MSIE",
                        identity: "Explorer",
                        versionSearch: "MSIE"
                },
                {
                        string: navigator.userAgent,
                        subString: "Gecko",
                        identity: "Mozilla",
                        versionSearch: "rv"
                },
                {                 // for older Netscapes (4-)
                        string: navigator.userAgent,
                        subString: "Mozilla",
                        identity: "Netscape",
                        versionSearch: "Mozilla"
                }
        ],
        dataOS : [
                {
                        string: navigator.platform,
                        subString: "Win",
                        identity: "Windows"
                },
                {
                        string: navigator.platform,
                        subString: "Mac",
                        identity: "Mac"
                },
                {
                        string: navigator.platform,
                        subString: "Linux",
                        identity: "Linux"
                }
        ]

};

function goUrl(url){
        location.href=url;
}

//function updateButtonImg() {
//        document.getElementById('menu_button1').style.visibility="hidden";
//        document.getElementById('menu_button1').src = 'images/button02_on.gif';

//        showAlert2(0, 'about', getWaitIcon(),"");
//        document.getElementById(button_id).src = 'images/button02_on.gif';
//        return btn_image;
//function showstuff(boxid){
//   document.getElementById(boxid).style.visibility="visible";
//}

//function hidestuff(boxid){
//   document.getElementById(boxid).style.visibility="hidden";
//}
//}


function showArticle(article_id) {
        el = document.getElementById("pagecell1");
        stdAlertID = showAlert2(0, 'about', getWaitIcon(),"");
        url = "index.php?n=Articles&o=show&id=" + article_id;
        initObj();
        if (xmlhttp!=null) {
          xmlhttp.onreadystatechange=_showArticle;
          xmlhttp.open("GET",url,true);
          xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
          xmlhttp.send(null);
        }
}
function _showArticle() {
  if(checkReadyState(xmlhttp)) {
        var response = xmlhttp.responseXML.documentElement;
        response.normalize;
        x=response.getElementsByTagName("content");
        y= x[0].firstChild.data;
        showAlert2(stdAlertID, 'about', y, "");
  }
}

function showPrivacy() {
        el = document.getElementById("pagecell1");
        txt =  "Nulla tincidunt facilisis justo. Donec auctor. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed posuere nulla sollicitudin purus. Etiam consectetuer bibendum orci. Nulla convallis dolor eget arcu. Etiam ante enim, volutpat at, condimentum quis, euismod sit amet, tortor. Fusce fermentum purus ac nunc ullamcorper adipiscing. Duis elit quam, condimentum quis, varius eget, scelerisque in, orci. Proin dapibus purus vel tellus lacinia sagittis. Donec convallis. Etiam mollis dui at neque. Praesent placerat tellus ut dolor. Sed sem erat.";
        stdAlertID = showAlert2(0, 'about', txt, "", '600', '300');
}

// LOGIN pop up box
function displayLogin(question_id) {
        el = document.getElementById("pagetitle2");
        stdAlertID = showAlert2(0, 'about', getWaitIcon(),"", '300', '150');
        url = "index.php?n=User&o=showLogin";
        initObj();
        if (xmlhttp!=null) {
          xmlhttp.onreadystatechange=_displayLogin;
          xmlhttp.open("GET",url,true);
          xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
          xmlhttp.send(null);
        }
}
function _displayLogin() {
  if(checkReadyState(xmlhttp)) {
        var response = xmlhttp.responseXML.documentElement;
        response.normalize;
        x=response.getElementsByTagName("content");
        y= x[0].firstChild.data;
        showAlert2(stdAlertID, 'about', y, "");
  }
}

// ABOUT US pop up box
function displayAbout() {
//        el = document.getElementById("pagetitle2");
        stdAlertID = showAlert2(0, 'about', getWaitIcon(),"", '620', '320');
        url = "index.php?n=Home&o=xmlPage&id=about";
        initObj();
        if (xmlhttp!=null) {
          xmlhttp.onreadystatechange=_displayAbout;
          xmlhttp.open("GET",url,true);
          xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
          xmlhttp.send(null);
        }
}
function _displayAbout() {
  if(checkReadyState(xmlhttp)) {
        var response = xmlhttp.responseXML.documentElement;
        response.normalize;
        x=response.getElementsByTagName("content");
        y= x[0].firstChild.data;
        showAlert2(stdAlertID, 'about', y, "");
  }
}

// PRIVACY POLICY pop up box
function displayPrivacy() {
//        el = document.getElementById("pagetitle2");
        stdAlertID = showAlert2(0, 'privacy', getWaitIcon(),"", '620', '320');
        url = "index.php?n=Home&o=xmlPage&id=privacy";
        initObj();
        if (xmlhttp!=null) {
          xmlhttp.onreadystatechange=_displayPrivacy;
          xmlhttp.open("GET",url,true);
          xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
          xmlhttp.send(null);
        }
}
function _displayPrivacy() {
  if(checkReadyState(xmlhttp)) {
        var response = xmlhttp.responseXML.documentElement;
        response.normalize;
        x=response.getElementsByTagName("content");
        y= x[0].firstChild.data;
        showAlert2(stdAlertID, 'privacy', y, "");
  }
}

// TERMS OF USE pop up box
function displayTerms() {
//        el = document.getElementById("pagetitle2");
        stdAlertID = showAlert2(0, 'terms', getWaitIcon(),"", '620', '320');
        url = "index.php?n=Home&o=xmlPage&id=terms";
        initObj();
        if (xmlhttp!=null) {
          xmlhttp.onreadystatechange=_displayTerms;
          xmlhttp.open("GET",url,true);
          xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
          xmlhttp.send(null);
        }
}
function _displayTerms() {
  if(checkReadyState(xmlhttp)) {
        var response = xmlhttp.responseXML.documentElement;
        response.normalize;
        x=response.getElementsByTagName("content");
        y= x[0].firstChild.data;
        showAlert2(stdAlertID, 'terms', y, "");
  }
}

// CONTACT US pop up box
var contactAlertID = 0;
function displayContact() {
//        el = document.getElementById("mastheadContainer");
		setOpacity(10);
        stdAlertID = showAlert2(0, 'contact', getWaitIcon(),"", '620', '520');
        url = "index.php?n=Home&o=showContact";
        initObj();
        if (xmlhttp!=null) {
          xmlhttp.onreadystatechange=_displayContact;
          xmlhttp.open("GET",url,true);
          xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
          xmlhttp.send(null);
        }
}
function _displayContact() {
  if(checkReadyState(xmlhttp)) {
        var response = xmlhttp.responseXML.documentElement;
        response.normalize;
        x=response.getElementsByTagName("content");
        y= x[0].firstChild.data;
        contactAlertID = showAlert2(stdAlertID, 'contact', y, "");
  }
}
                                                    

// SEND TO FRIEND pop up box
var friendAlertID = 0;
function displaySendFriend() {
//        el = document.getElementById("mastheadContainer");
		setOpacity(10);
        stdAlertID = showAlert2(0, 'sendtofriend', getWaitIcon(),"", '620', '320');
        url = "index.php?n=Home&o=showSendFriend&link=" + encodeURIComponent(window.location);
        initObj();
        if (xmlhttp!=null) {
          xmlhttp.onreadystatechange=_displaySendFriend;
          xmlhttp.open("GET",url,true);
          xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
          xmlhttp.send(null);
        }
}
function _displaySendFriend() {
  if(checkReadyState(xmlhttp)) {
        var response = xmlhttp.responseXML.documentElement;
        response.normalize;
        x=response.getElementsByTagName("content");
        y= x[0].firstChild.data;
        friendAlertID = showAlert2(stdAlertID, 'sendtofriend', y, "");
  }
}

function submitSendToFriend() {
        el=document.getElementById('Name');        name = el.value;
        err = 0;
        
        el=document.getElementById('sendFriendNameErr');        
        if (name == " " || name == "")
        {
                el.innerHTML = "name is required<br>";
                err=1;
        } else {
                el.innerHTML = "";
        }

        el=document.getElementById('ToEmail');        email2 = el.value;
        el=document.getElementById('sendFriendEmail2Err');        
        if (email2 == "")
        {
                el.innerHTML = "Email address is required<br>";
                err=1;
        } else {
                el.innerHTML = "";
        }

        el=document.getElementById('Email');        email = el.value;
        el=document.getElementById('sendFriendEmailErr');        
        if (email == "")
        {
                el.innerHTML = "Email address is required<br>";
                err=1;
        } else {
                el.innerHTML = "";
        }
        
        el=document.getElementById('Subject');        subject = el.value;
        el=document.getElementById('sendFriendSubjectErr');        
        if (subject == "")
        {
                el.innerHTML = "Subject is required<br>";
                err=1;
        } else {
                el.innerHTML = "";
        }        
        
        if (err == 1)
        {
                return false;
        } 
        el=document.getElementById('Message');        msg = el.value;

        getWaitIcon();

        url = "index.php?n=Home&o=dosendfriend&Name=" + name + "&ToEmail=" + email2 + "&Email=" + email + "&Subject="             + subject + "&Message=" + msg + "&link=" + encodeURIComponent(window.location);
        hideAlert2(friendAlertID);
        initObj();
        if (xmlhttp!=null) {
          xmlhttp.onreadystatechange=_submitSendToFriend;
          xmlhttp.open("GET",url,true);
          xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
          xmlhttp.send(null);
        }
        goUrl("index.php?n=Home&o=thank_you");
}

function _submitSendToFriend() {
  if(checkReadyState(xmlhttp)) {
        var response = xmlhttp.responseXML.documentElement;
        response.normalize;
        x=response.getElementsByTagName("result");
        y= x[0].firstChild.data;
        showAlert2(friendAlertID, 'sendfriend', y, "", '320', '220');
        friendAlertID = 0;
  }
}

function submitContactUs() {
        err = 0;

        el=document.getElementById('Name');        name = el.value;
        el=document.getElementById('submitContactNameErr');        
        if (name == " " || name == "")
        {
                el.innerHTML = "name is required<br>";
                err=1;
        } else {
                el.innerHTML = "";
        }

        el=document.getElementById('Email');        email = el.value;
        el=document.getElementById('submitContactEmailErr');        
        if (email == "")
        {
                el.innerHTML = "Email address is required<br>";
                err=1;
        } else {
                el.innerHTML = "";
        }

        el=document.getElementById('Subject');        subject = el.value;
        if (subject == "")  subject = "Contact request from Cesaroni website";

        el=document.getElementById('Message');        message = el.value;
        el=document.getElementById('submitContactMessageErr');        
        if (email == "")
        {
                el.innerHTML = "Message text is required<br>";
                err=1;
        } else {
                el.innerHTML = "";
        }

        if (err == 1)
        {
                return false;
        } 
        el=document.getElementById('Message');        msg = el.value;

        getWaitIcon();

        url = "index.php?n=Home&o=docontactus&Name=" + name + "&Email=" + email + "&Subject=" + subject + "&Message=" + message ;
        hideAlert2(contactAlertID);
        initObj();
        if (xmlhttp!=null) {
          xmlhttp.onreadystatechange=_submitContactUs;
          xmlhttp.open("GET",url,true);
          xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
          xmlhttp.send(null);
        }

        goUrl("index.php?n=Home&o=thank_you");
}

function _submitContactUs() {
	setOpacity(100);
  if(checkReadyState(xmlhttp)) {
        var response = xmlhttp.responseXML.documentElement;
        response.normalize;
        x=response.getElementsByTagName("result");
        y= x[0].firstChild.data;
        showAlert2(friendAlertID, 'contact', y, "", '320', '220');
        friendAlertID = 0;
  }
}


function setOpacity(level) {
	el = document.getElementById("homeBody");
	el.style.filter = "alpha(opacity=" + level +")";
	el.style.opacity = level / 100;
}