var FormWindow,EditForm,RemoveForm,GenNewWindow;
var is;

/******* Browser detection *********/
function Is (){
    var agt=navigator.userAgent.toLowerCase();
    this.major		= parseInt(navigator.appVersion);
    this.minor		= parseFloat(navigator.appVersion);
    this.nav		= ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    this.nav4		= (this.nav && (this.major == 4));
    this.nav6up		= (this.nav && (this.major >= 5));
    this.ie			= ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    this.ie4		= (this.ie && (this.major == 4) && (agt.indexOf("msie 5")==-1) );
    this.ie4up		= (this.ie && (this.major >= 4));
    this.mac		= (agt.indexOf("mac")!=-1);
}
is = new Is(); 
/******* End Browser detection ******/

function Popup(strURL, intWidth, intHeight)	
{
	var intLeft = (screen.width - intWidth) / 2;
	var intTop = (screen.height - intHeight - 35) / 2;
	NewChild = window.open(strURL,'_blank','toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=' + intWidth + ',height=' + intHeight + ',top=' + intTop + ',left=' + intLeft)
}


function openPlainWindow(url, width, height) 
{
	outsideWin = window.open(url, 'remote','RESIZABLE,SCROLLBARS=YES,width='+width+',height='+height+',left=50,top=50')
	//nextline allows focus to continue to go to the remote window
	outsideWin.focus(); 
}

function DoTest(){
alert("this is a test");

}

 function openWindow_banner(htm_file) {
    MyWindow = window.open(htm_file,"", 'width = 250, height = 265, scrollbars=false, toolbar=false,status=false, resizable=false');
    MyWindow.focus();   
} 


 function openWindowProduct(ProductImage) {
    MyWindow = window.open("","", 'width = 400, height = 400, scrollbars, resizable');
var newContent="<IMG SRC=" + ProductImage + ">";
    MyWindow.document.write(newContent);
	MyWindow.document.close(); //to close the stream
    MyWindow.focus();   
} 


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function doRollover(field){
//use this to change to purple
 field.style.color="purple";
}
function doMouseOut(field){
//use this to return to blue
  field.style.color="#003399";
}


function doRollover1(field){
//use this to change to pale blue
 field.style.color="#99CCFF";
}
function doMouseOut1(field){
//use this to return to white
  field.style.color="#ffffff";
}



function doRollover2(field){
//use this to change to red
 field.style.color="blue";
}
function doMouseOut2(field){
//use this to return to white
  field.style.color="#666666";
}
function doRollover3(field){
//use this to change to red
 field.style.color="663300";
}
function doMouseOut3(field){
//use this to return to black
  field.style.color="#000000";
}
function doRollover4(field){
//use this to change to blue
 field.style.color="blue";
}
function doMouseOut4(field){
//use this to return to brown
  field.style.color="#CC6600";
}
function doRollover5(field){
//use this to change to red
 field.style.color="orange";
}
function doMouseOut5(field){
//use this to return to yellow
  field.style.color="red";
}
function doRollover6(field){
//use this to change to red
 field.style.color="blue";
}
function doMouseOut6(field){
//use this to return to yellow
  field.style.color="purple";
}

//******************************************************
//  4th level  General functions for validating fields
//******************************************************

// complements the main one below
function EmailHasInvalidChars(value) {
//var value = document.form1.testString.value;
var RegExpr1 = /[\~\`\!\#\$\%\^\&\*\(\)\=\|\\\{\[\}\]\:\;\"\'\/\<\>\,\s]/;
var testResult = value.search(RegExpr1);
  if (testResult == -1){
    return false; // no odd characters
  }
  message = "Invalid e-mail";
  return true;	
}

function isFieldEmail(value) {
  var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
  var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z\-\_]{2,3}|[0-9]{1,6})(\]?)$/; // valid
                 
  if (!reg1.test(value) && reg2.test(value)) {
    return true;
  }
  message= "You entered an invalid e-mail!";
  return false;
}

//********************************************************************
// 2ndd level functions for specific form fields
//********************************************************************

// ------------------
function checkEmail(value){
  if (value == ""){
    message = "Your entry is not valid, it's empty";
  return false
  }
 if (isFieldEmail(value) == false){
   return false;
 } 
 if (EmailHasInvalidChars(value) == true){
  return false;
 }  
 return true;
}


//*************************************************************************
// 1st level function for calling specific form 1 field validation functions
//*************************************************************************
function validateForm1() {
var emptyFields = "";
//alert("this is validateForm1");
 //To validate e-mails
 if (!checkEmail(document.form1.EMail.value)){
  emptyFields += "\n E-mail --> " + message
 }
if (document.form1.Comment.value == "") {
  emptyFields += "\n Your comment --> You forgot your comment." 
 }
 if (emptyFields != "") {
   emptyFields = "Please correct the following fields: \n" 
   +             "---------------------------------------------------\n" 
   + emptyFields;
   alert(emptyFields);
   return false;
   
 }
 return true;
 
}
