/////////////////////////////
// Check for valid email  //
///////////////////////////
function emailCheck (emailStr) {
var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|bz|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("The username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("The 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 doesn't 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 code.");
return false;
}
if (len<2) {
alert("This address is missing a hostname.");
return false;
}
return true;
}

///////////////////////////////////////////
// Open Window in popup mode for login  //
/////////////////////////////////////////
function centerWindow(mylink,windowname) {
    if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.layers)
            var xMax = window.outerWidth, yMax = window.outerHeight;
        else
            var xMax = 800, yMax=600;

    var xOffset = (xMax - 200)/2, yOffset = (yMax - 200)/2;
    if (! window.focus)return true;
    var href;
    if (typeof(mylink) == 'string')
       href=mylink;
    else
       href=mylink.href;
    window.open(href,'popuplogin','width=230,height=125,scrollbars=no,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
return false;
}

///////////////////////////////////////////
// Open Window in popup mode for login  //
/////////////////////////////////////////
function loginWindow(mylink,windowname) {
    if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.layers)
            var xMax = window.outerWidth, yMax = window.outerHeight;
        else
            var xMax = 800, yMax=600;

    var xOffset = (xMax - 200)/2, yOffset = (yMax - 200)/2;
    if (! window.focus)return true;
    var href;
    if (typeof(mylink) == 'string')
       href=mylink;
    else
       href=mylink.href;
    window.open(href,'popuplogin','width=230,height=125,scrollbars=no,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
}

/////////////////////////////////
// Add to favorites function  //
///////////////////////////////
function addtofavorites(bookmarktitle, bookmarkurl){

var bookmarkurl = window.location.href;
var bookmarktitle = document.title;

if (document.all)
window.external.AddFavorite(bookmarkurl, bookmarktitle);
else if (window.sidebar)
window.sidebar.addPanel(bookmarktitle, bookmarkurl, "");
}

////////////////////////////////////
// Copyright Year Auto Increment //
//////////////////////////////////
today=new Date();
year=today.getFullYear();
copyrightmessage="Copyright © "+year+" Cepap. All rights reserved.";
copyrightmessage_EN="Copyright © "+year+" Cepap.";

/////////////////////////////////////
// Disable ability to right click //
///////////////////////////////////
var message="Copyright © "+year+" Cepap. All rights reserved.";
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}
function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}
if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}
document.oncontextmenu=new Function("alert(message);return false")

////////////////////////////////////////////
// Change between option in drop windows //
//////////////////////////////////////////
function Goto3(form) {
 var tempVal="";
 var myindex=form.select1.selectedIndex;
 for (i=0; i<2; i++){
   if (document.thisform.CurrencyOption[i].checked == true) {
   tempVal = document.thisform.CurrencyOption[i].value;}}
 if (form.select1.options[myindex].value != "0") {
 window.open(form.select1.options[myindex].value+"&CurrencyOption="+tempVal, target="_top");}
}


function Goto(form) {
 var myindex=form.select1.selectedIndex
 if (form.select1.options[myindex].value != "0") {
 window.open(form.select1.options[myindex].value, target="_top");}
}

//////////////////////////////
// Pop up Contents Windows //
////////////////////////////
function popupcontents(mylink,windowname) {
    if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.layers)
            var xMax = window.outerWidth, yMax = window.outerHeight;
        else
            var xMax = 800, yMax=600;

    var xOffset = (xMax - 200)/2, yOffset = (yMax - 200)/2;
    if (! window.focus)return true;
    var href;
    if (typeof(mylink) == 'string')
       href=mylink;
    else
       href=mylink.href;
    window.open(href,'popupcontents','width=600,height=800,scrollbars=no');
return false;
}

////////////////////////////
// Pop up Images Windows //
//////////////////////////
function popupimages(mylink,windowname) {
    if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.layers)
            var xMax = window.outerWidth, yMax = window.outerHeight;
        else
            var xMax = 800, yMax=600;

    var xOffset = (xMax - 200)/2, yOffset = (yMax - 200)/2;
    if (! window.focus)return true;
    var href;
    if (typeof(mylink) == 'string')
       href=mylink;
    else
       href=mylink.href;
    window.open(href,'popupimages','width=600,height=800,scrollbars=no');
return false;
}

////////////////////////////////
// Validate Shipping Address //
//////////////////////////////
function ShippingAddressCheck(){
alert("Please fill out required shipping address field")
return false
}

///////////////////
// Images Popup //
/////////////////
PositionX = 100;
PositionY = 100;
defaultWidth  = 2000;
defaultHeight = 1000;
var AutoClose = true;
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
function popImage(imageURL,imageTitle){
if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html><head><title>Cepap</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
writeln('width=100-(document.body.clientWidth-document.images[0].width);');
writeln('height=100-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
writeln('window.innerWidth=document.images["Cepap"].width;');writeln('window.innerHeight=document.images["Cepap"].height;}}');
writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<img name="Cepap" src='+imageURL+' style="display:block"></body></html>');
close();		
}}