function resizeOuterTo(w,h) {
 if (parseInt(navigator.appVersion)>3) {
   if (navigator.appName=="Netscape") {
    top.outerWidth=w;
    top.outerHeight=h;
   }
   else top.resizeTo(w,h);
 }
}
var pop='';
function MM_openBrWindow(theURL,winName,features) { //v2.0
   if (pop && !pop.closed) {
      pop.close();
   }

    pop=eval(window.open(theURL,'pop',features));
   if (!pop.opener) popUpWin.opener = self;
}

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; }
}


// JavaScript Document
var url="http://www.premiumorchid.com.sg/";
var title="Premium Orchids";

function bookmark()
{
    window.external.AddFavorite(url,title);
}


function changebg(row)
{
        row.className='rowHover';
}

function restorebg(row)
{
        row.className='row';
}

function goto(link){
    window.location.href=link;
}

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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}



function finalItemValid(chk1, prodType) {
    if (prodType=="S") {
        if (chktrim(chk1.itemCode.value).length==0) {
            alert("Enter Item Code !!");
            chk1.itemCode.focus();
            return false;
        }

   }
}
function chktrim(inputString) {
    if (typeof inputString != "string") { return inputString; }
    var retValue = inputString;
    var ch = retValue.substring(0, 1);
    while (ch == " ") {
       retValue = retValue.substring(1, retValue.length);
       ch = retValue.substring(0, 1);
    }
    ch = retValue.substring(retValue.length-1, retValue.length);
    while (ch == " ") {
       retValue = retValue.substring(0, retValue.length-1);
       ch = retValue.substring(retValue.length-1, retValue.length);
    }
    while (retValue.indexOf("  ") != -1) {
       retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
    }
    return retValue;
}

function openwin(nm,width,height) {
   var name=nm;
   if (pop && !pop.closed) {
      pop.close();
   }
   pop=eval("window.open('"+name+"','NewWIN','chrome[4],toolbar=no,left=5,top=5,width="+width+",height="+height+",directories=no,menubar=no,SCROLLBARS=yes,left=2,right=2')");
   if (!pop.opener) popUpWin.opener = self;
}
var pop='';
function openwin1(nm,width,height) {
   var name=nm;
   if (pop && !pop.closed) {
      pop.close();
   }
   pop=eval("window.open('"+name+"','NewWIN2','chrome[4],toolbar=no,left=5,top=5,width="+width+",height="+height+",directories=no,menubar=no,SCROLLBARS=yes,left=2,right=2')");
   if (!pop.opener) popUpWin.opener = self;
}
function openwin2(nm,width,height) {
   var name=nm;
   if (pop && !pop.closed) {
      pop.close();
   }
   pop=eval("window.open('"+name+"','NewWIN2','chrome[4],toolbar=no,left=5,top=5,width="+width+",height="+height+",directories=no,menubar=yes,SCROLLBARS=yes,left=2,right=2')");
   if (!pop.opener) popUpWin.opener = self;
}

function checkAll(val) {
    dml=document.form1;
    len=dml.elements.length;
    var i=0;
    for (i=0; i<len; i++) {
        if (document.form1.elements[i].type == "checkbox") {
            if (val == 1) {
                dml.elements[i].checked=true;
            }
            else {
                dml.elements[i].checked=false;
            }
        }
    }
}

function chk4() {
     chk2=document.form1;
     len=chk2.elements.length;
     var i=0;
     var pp=1;
     for (i=0; i<len; i++) {
        if ((chk2.elements[i].type == "checkbox") && (chk2.elements[i].checked==true)) {
           pp=2;
        }
     }
     if (pp==1) {
        return ("1");
     }
}

function checkSDForm(chk) {
    if (chk.yourName.value == 0) {
        alert("Name can't be left blank");
        chk.yourName.focus();
        return false;
    }
    if (chk.address.value == 0) {
        alert("Street Address can't be left blank");
        chk.address.focus();
        return false;
    }
    if (chk.city.value == 0) {
        alert("City can't be left blank");
        chk.city.focus();
        return false;
    }
    if (chk.state.value == 0) {
        alert("State can't be left blank");
        chk.state.focus();
        return false;
    }
    if (chk.country.options[chk.country.selectedIndex].value=="x") {
        alert("Select Country");
        chk.country.focus();
        return false;
    }
    if (chk.zipCode.value == 0) {
        alert("Zip/Postal Code  can't be left blank");
        chk.zipCode.focus();
        return false;
    }
}


function userValid(chk, loginVar, billingVar, shippingVar) {
    if (loginVar=="Y") {
        if (chk.email.value.length == 0) {
            alert("E-mail address can't be left blank");
            chk.email.focus();
            return false;
        }
        if (chk.email.value.indexOf('@') == -1) {
            alert("Error in e-mail address");
            chk.email.focus();
            return false;
        }
        if (chk.email.value.indexOf('.') == -1) {
            alert("Error in e-mail address");
            chk.email.focus();
            return false;
        }
        if (chk.email.value.indexOf('@') != chk.email.value.lastIndexOf('@')) {
            alert("Please Specify One E-mail address only");
            chk.email.focus();
            return false;
        }
        if (chk.pass.value == 0) {
            alert("Unable to submit !! Do not leave the Password field blank");
            chk.pass.focus();
            return false;
        }
    }
    if (billingVar=="Y") {
        if (chk.yourName.value == 0) {
            alert("Name can't be left blank");
            chk.yourName.focus();
            return false;
        }
        if (chk.address.value == 0) {
            alert("Street Address can't be left blank");
            chk.address.focus();
            return false;
        }
        if (chk.city.value == 0) {
            alert("City can't be left blank");
            chk.city.focus();
            return false;
        }
        if (chk.state.value == 0) {
            alert("State can't be left blank");
            chk.state.focus();
            return false;
        }
        if (chk.country.options[chk.country.selectedIndex].value=="x") {
            alert("Select Country");
            chk.country.focus();
            return false;
        }
        if (chk.zipCode.value == 0) {
            alert("Zip/Post Code  can't be left blank");
            chk.zipCode.focus();
            return false;
        }
        if (chk.phone.value == 0) {
            alert("Phone can't be left blank");
            chk.phone.focus();
            return false;
        }
    }
    if (shippingVar=="Y") {
        if (chk.sName.value == 0) {
            alert("Shipping Name can't be left blank");
            chk.sName.focus();
            return false;
        }
        if (chk.sAddress.value == 0) {
            alert("shipping Address can't be left blank");
            chk.sAddress.focus();
            return false;
        }
        if (chk.sCity.value == 0) {
            alert("City can't be left blank");
            chk.sCity.focus();
            return false;
        }
        if (chk.sState.value == 0) {
            alert("State can't be left blank");
            chk.sState.focus();
            return false;
        }
        if (chk.sZipCode.value == 0) {
            alert("Zip/Post Code  can't be left blank");
            chk.sZip.focus();
            return false;
        }
        if (chk.sPhone.value == 0) {
            alert("Phone can't be left blank");
            chk.phone2.focus();
            return false;
        }
    }
}



function chk1(var1, var2) {
    var p1 = chk4();
    if (p1 == "1") {
        alert("You have not selected any Order No.\n\nPlease select the Invoice check box to proceed.");
        return false;
    }
    if (var1=="Y") {
        if (chktrim(document.form1.yourSubject.value).length==0) {
            alert("Enter Your Mail Subject ");
            document.form1.yourSubject.focus();
            return false;
        }
        if (chktrim(document.form1.yourComment.value).length==0) {
            alert("Enter Your Mail Message");
            document.form1.yourComment.focus();
            return false;
        }
    }
    if (var2=="Y") {
        var3 = confirm('Are you sure you want to change Status');
        if (!var3) {
            return false;
        }
    }
}

function remindPassChk() {
    if (!document.remind.email.value.length) {
        alert("Please enter your E-Mail");
        document.remind.email.focus();
        return false;
    }
    if (document.remind.email.value.indexOf('@') == -1) {
        alert("Error in E-Mail address");
        document.remind.email.focus();
        return false;
    }
    if (document.remind.email.value.indexOf('.') == -1) {
        alert("Error in E-Mail address");
        document.remind.email.focus();
        return false;
    }
}

function chkDDSD(chk, arrlen) {
    if (chk.distID.options[chk.distID.selectedIndex].value=="") {
        alert("Select  Sub Dealear Name");
        chk.distID.focus();
        return false;
    }
    var pp=1;
    for (i=0; i<arrlen; i++) {
        box1 = eval('document.form3.chk' + i + '_0');
        box2 = eval('document.form3.chk' + i + '_1');
        box3 = eval('document.form3.chk' + i + '_2');
        if (box1.value>0) {
            pp=0;
        }
        if (Math.floor(box1.value)>Math.floor(box2.value) ) {
            alert("Quanity of " +box3.value + " is greater than max quantity");
            box1.focus();
            return false;
        }
    }
    if (pp=="1") {
        alert("Enter any of Item Quanity");
        return false;
    }
}


function chkAD(chk, arrlen) {
    var pp=1;
    for (i=0; i<arrlen; i++) {
        box1 = eval('document.form3.godown' + i + '_0');
        box2 = eval('document.form3.godown' + i + '_1');
        box3 = eval('document.form3.godown' + i + '_2');
        box4 = eval('document.form3.godown' + i + '_3');

        if (box1.value>0) {
            pp=0;
        }
        if (Math.floor(box1.value)+Math.floor(box2.value)!=Math.floor(box3.value) ) {
            alert("Quanity of " +box4.value + " should be equal to  max quantity");
            box1.focus();
            return false;
        }
    }
    if (pp=="1") {
        alert("Enter any of Item Quanity");
        return false;
    }

}

function validPassSection(chk, userTy, user, pass) {
    if (userTy=="Y") {
        if (chk.userTy.options[chk.userTy.selectedIndex].value=="") {
            alert ("select a User Type");
            chk.userTy.focus();
            return false;
        }
    }
}

function chk_login(chk1) {
    if (chk1.email.value.length == 0) {
        alert("E-mail address can't be left blank");
        chk1.email.focus();
        return false;
    }
    if (chk1.email.value.indexOf('@') == -1) {
        alert("Error in Email ID");
        chk1.email.focus();
        return false;
    }
    if (chk1.email.value.indexOf('.') == -1) {
        alert("Error in Email ID");
        chk1.email.focus();
        return false;
    }
    if (chk1.email.value.indexOf('@') != chk1.email.value.lastIndexOf('@')) {
        alert("Please Specify One Email ID only");
        chk1.email.focus();
        return false;
    }
    if (chk1.pass.value.length==0) {
        alert("Enter Your Password ");
        chk1.pass.focus();
        return false;
    }
}


function itemCal(pqty, pAmt) {
    figAmt = Math.round(pqty*pAmt);
    return(figAmt);
}
function calLST(pqty,pAmt,dtype,dAmt) {
    figAmt = Math.round(pqty*pAmt);
    if (dtype=="1") {
       figAmt = Math.floor((figAmt*dAmt)/100);
    }
    return(figAmt);
}
function invoiceCal() {
   	var aa1 = document.form1;
   	var totalAmt1=0;
    var billTotal=0;
    for (i=0; i<15; i++) {
        var i1 =i+1;
        box1 = eval('document.form1.prodID' + i +'');
        box2 = eval('document.form1.qty' + i + '');
        box3 = eval('document.form1.price' + i + '');
        box4 = eval('document.form1.totAmt' + i + '');
        box5 = eval('document.form1.totalAmt' + i1 + '');
        if (box1.value!=="") {
            i2=i+1;
            if (box2.value<=0) {
                alert("Enter No. of Quantity in Sl. No. "+i2+"");
                box2.focus();
                return false;
            }
            if (box3.value<=0) {
                alert("Enter Price in Sl. No.  "+i2+"");
                box2.focus();
                return false;
            }
            box4.value = itemCal (box2.value, box3.value);
            totalAmt1 =  itemCal (box2.value, box3.value);
            billTotal = billTotal + totalAmt1;
        }
    }
    aa1.totalAmt.value = billTotal;

    lstAmount = (billTotal+parseFloat(aa1.shipAmt.value)) * aa1.taxPer.value/100;
    aa1.lstAmount .value = lstAmount.toFixed(2);
    
    billTotal = billTotal+ lstAmount + parseFloat(aa1.shipAmt.value);
    aa1.billTotal.value = billTotal.toFixed(2);
    aa1.invCal.value='Y';
}

function validInvoice(id4) {
    if (chktrim(id4.memberID.value).length==0) {
        alert("Click here to Add party Name");
        id4.compName.focus();
        return false;
    }
    if (chktrim(id4.prodID0.value).length==0) {
        alert("Enter Product Name");
        id4.itemName0.focus();
        return false;
    }
    if (id4.invCal.value!="Y") {
        alert("Before Save Invoice, please Calculate Invoice Total");
        id4.inv5.focus();
        return false;
    }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function setDateBox()  {
    if(document.form3.dateType.selectedIndex ==0) {
            document.form3.dateTo.disabled=true;
    }
    else {
            document.form3.dateTo.disabled=false;
        }
}

MM_preloadImages('images/link-back-hover.gif');
