﻿
/*
Open a new window with no tools and give it focus.
*/
function S52_openPreviewWindow(theURL, windowname, width, height) {
  var features = "location=no, scrollbars=no"
  features += ", width=" + width
  features += ", height=" + height
  var newwin = window.open(theURL,windowname,features)
  newwin.focus()
}

/*
IsNumeric(string)
Does the string passed in contain only numeric digits.
Note that this does not include the decimal point.
*/
function IsNumeric(sText){

   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++){ 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}
 

/*
Incrment the Integer value in the field with id fielddid
*/
function Increment(fieldid) {
    if (document.getElementById(fieldid).value == "") {
        q = 1;
    } else {
        if (IsNumeric(document.getElementById(fieldid).value)) {
            q = parseInt(document.getElementById(fieldid).value);
            q += 1;
        } else {
            q = 1;
        }
    }
    document.getElementById(fieldid).value = q;
}


/*
Decrment the Integer value in the field with id fielddid
*/
function Decrement(fieldid){
    if (document.getElementById(fieldid).value == "") {
        q = 1;
    } else {
        if (IsNumeric(document.getElementById(fieldid).value)) {
            q = parseInt(document.getElementById(fieldid).value);
            if (q > 1) {
                q -= 1;
            }
        } else {
            q = 1;
        }
    }
    document.getElementById(fieldid).value = q;
}


function IncrementSubmit(fieldid, hiddenactionfieldname, action, formname) {
    if (document.getElementById(fieldid).value == "") {
        q = 1;
    } else {
        if (IsNumeric(document.getElementById(fieldid).value)) {
            q = parseInt(document.getElementById(fieldid).value);
            q += 1;
        } else {
            q = 1;
        }
    }
    document.getElementById(fieldid).value = q;



    var txtHidden = document.getElementById(hiddenactionfieldname);
    if (txtHidden != null) {
        txtHidden.value = action;
        
        var theForm = document.getElementById(formname);
        if (theForm != null) {
            theForm.submit();
        }

    }
    
}


/*
Decrment the Integer value in the field with id fielddid
*/
function DecrementSubmit(fieldid, hiddenactionfieldname,action,formname) {
    if (document.getElementById(fieldid).value == "") {
        q = 1;
    } else {
        if (IsNumeric(document.getElementById(fieldid).value)) {
            q = parseInt(document.getElementById(fieldid).value);
            if (q > 1) {
                q -= 1;
            }
        } else {
            q = 1;
        }
    }
    document.getElementById(fieldid).value = q;


    var txtHidden = document.getElementById(hiddenactionfieldname);
    if (txtHidden != null) {
        txtHidden.value = action;  
        
        var theForm = document.getElementById(formname);
        if (theForm != null) {
            theForm.submit();
        }

    }
      
}


function OnBlurSubmit(fieldid, prevvalue, hiddenactionfieldname, action, formname) {

    var txtQuantity = document.getElementById(fieldid);
    
    if (txtQuantity != null) {
        if (txtQuantity.value != prevvalue) {
            var txtHidden = document.getElementById(hiddenactionfieldname);
            if (txtHidden != null) {
                txtHidden.value = action;

                var theForm = document.getElementById(formname);
                if (theForm != null) {
                    theForm.submit();
                }

            }
        }
    }
    

}



/*
 ***********************************************************
 * open a frameless window to the width and height given   *
 * with the name and url supplied                          *
 ***********************************************************
*/
function S52_openFramelessWindow(theURL, windowname, width, height) {
  var features = "location=no, scrollbars=yes"
  features += ", width=" + width
  features += ", height=" + height
  var newwin = window.open(theURL,windowname,features)
  newwin.focus()
}

function S52_openNonScrollingWindow(theURL, windowname, width, height) {
  var features = "location=no, scrollbars=no"
  features += ", width=" + width
  features += ", height=" + height
  var newwin = window.open(theURL,windowname,features)
  newwin.focus()
}

function S52_parentWindowUrlReload(theURL) {
  window.opener.location = theURL;
    self.focus();
}

function S52_WindowUrlReload(theURL) {
    window.location = theURL;
    self.focus();
}

function S52_closeWindow() {
  window.close();
}

function w52_jumpSite(selectid){
  	//var jumpform = document.getElementById(fieldid)
    var selectedvalue = document.getElementById(selectid).value;
    var targetURL = "";
    var isExternal = true;
    if(selectedvalue != ""){
    	 if(selectedvalue.indexOf("####INTERNAL") > -1){
       		isExternal = false;
       }
       
      targetURL = selectedvalue.substring(0, selectedvalue.indexOf("####"));
      
      if(isExternal){
      	// popup
        window.open(targetURL, '', '');
      } else {
      	// reload
        document.location.href = targetURL
      }
    }
}


function S52_FormPostOnload(formname) {
    var theForm = document.getElementById(formname);
    if (theForm != null) {
        theForm.submit();
    }
}


function S52_ParentLocationOnload(controlname) {
    var txtURL = document.getElementById(controlname);
    if (txtURL != null) {
        alert(txtURL.value);
        parent.location.href = txtURL.value;
    }
}


function SubmitRowEntry(formname, hiddenfieldname, hiddenfieldvalue) {
    var theForm = document.getElementById(formname);
    var txtHidden = document.getElementById(hiddenfieldname);
    if (txtHidden != null) {
        txtHidden.value = hiddenfieldvalue;
        if (theForm != null) {
            theForm.action = "";
            theForm.submit();
        }
    }

}
