/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/* FrameDex support functions
* @category   frontend Javascript functions
* @package    Framedex DBA
* @author     r0mk1n <framedex.support@gmail.com>
* @copyright  1986-2006 r0mk1n
* @version    CVS: $Id: framedex.js,v 1.3 2006/05/10 18:20:40 мышка Exp $
*/

var popUpWin=0;
var popUpDial=0;

function switch_image(path, title) {
    var _img = document.getElementById("gallerey_image");
    if ( _img ) {
        _img.src = path;
    }
    var _label = document.getElementById("gallerey_label");
    if ( _label ) {
        _label.value = title;
    }
    return false;
}

function image_galerey(link) {
  OpenWin=open("","","toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=500,height=500");
  OpenWin.document.open();
  OpenWin.document.write("<TITLE>"+imgName+"</TITLE>");
  OpenWin.document.write("<body bgcolor=#ffffff>");
  OpenWin.document.write("<CENTER>");
  OpenWin.document.write("<P style='Font-family:Arial,Helvetica; Font-weight: bold; color: white; Font-size: 1em; border-width:0; border-color:#000000; border-style:solid; background-color:#778888;' >"+imgName+"</P>");
  OpenWin.document.write("<img width=450 src="+imgName+" align='center' border='1' hspace='0' vspace='0' alt='Loading, please wait...'><br/><br/>");
  OpenWin.document.write("<FORM><INPUT style='display:block; width:100px; padding:0px 2px 0px 2px; color:#999; background-color: #FFF; border: 1px solid #999; text-decoration: none;' TYPE='button' VALUE='Close' onClick='window.close()'></FORM>");
  OpenWin.document.write("</CENTER>");
  OpenWin.document.write("</body>");
  OpenWin.document.close();
}

function print_content(link) {
    return popUpWindow(link, "Print", 0,0,500, 400);
}

function pdf_content(link) {
    return popUpWindow(link, "PDF", 0,0,500, 400);
}

function email_content(link) {
    return popUpDialog(link, "Email", 0,0,300, 130);
}

function back_content() {
    return history.go(-1);
}

function popUpWindow(URLStr, title, left, top, width, height) {
  popUpWin = open(URLStr, title, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function popUpDialog(URLStr, title, left, top, width, height) {
  popUpDial = open(URLStr, title, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function ChangeClass(item, newClass) {
    if (document.getElementById) {
        document.getElementById(item).className = newClass;
    }
}

function switchImage(image_name, image_path) {
    if (document.getElementById) {
        var img = document.getElementById(image_name);
        if (img) {
            img.src = image_path;
            return true;
        }
    }
    return false;
}

function emailCheck (emailStr) {
    var checkTLD=1;
    var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
    var emailPat=/^(.+)@(.+)$/;
    var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
    var validChars="\[^\\s" + specialChars + "\]";
    var quotedUser="(\"[^\"]*\")";
    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
    var atom=validChars + '+';
    var word="(" + atom + "|" + quotedUser + ")";
    var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
    var matchArray=emailStr.match(emailPat);

    if (matchArray==null) {
        alert("Email address seems incorrect (check @ and .'s)");
        return false;
    }
    var user=matchArray[1];
    var domain=matchArray[2];
    for (i=0; i<user.length; i++) {
        if (user.charCodeAt(i)>127) {
            alert("Ths username contains invalid characters.");
            return false;
        }
    }
    for (i=0; i<domain.length; i++) {
        if (domain.charCodeAt(i)>127) {
            alert("Ths domain name contains invalid characters.");
            return false;
        }
    }
    if (user.match(userPat)==null) {
        alert("The username doesn't seem to be valid.");
        return false;
    }
    var IPArray=domain.match(ipDomainPat);
    if (IPArray!=null) {
        for (var i=1;i<=4;i++) {
            if (IPArray[i]>255) {
                alert("Destination IP address is invalid!");
                return false;
            }
        }
        return true;
    }
    var atomPat=new RegExp("^" + atom + "$");
    var domArr=domain.split(".");
    var len=domArr.length;
    for (i=0;i<len;i++) {
        if (domArr[i].search(atomPat)==-1) {
            alert("The domain name does not seem to be valid.");
            return false;
        }
    }
    if (checkTLD && domArr[domArr.length-1].length!=2 &&  domArr[domArr.length-1].search(knownDomsPat)==-1) {
        alert("The address must end in a well-known domain or two letter " + "country.");
        return false;
    }
    if (len<2) {
        alert("This address is missing a hostname!");
        return false;
    }

// If we've gotten this far, everything's valid!
    return true;
}

