﻿/* This will include all the comming javascript functions that are used by the website. */
//function toggle(obj) {
//    var el = document.getElementById(obj);
//    el.style.display = (el.style.display != 'none' ? 'none' : 'block');
//}

function toggle(obj, action) {
    var el = document.getElementById(obj);
    var el_parent = document.getElementById(obj + '_parent')
    if (action == 'open') {
        el.style.display = 'block';
        el_parent.className = 'current';
    }
    else {
        el.style.display = 'none';
        el_parent.className = '';
    }
}

function get_nextsibling(n){
	/* check if the next sibling node is an element node */
	var x = n.nextSibling;
	while (x != null){
		if (x.nodeType == 1){
			break;
		}
		x = x.nextSibling;
	}
	return x;
}

function hide_display(obj){
	var node = get_nextsibling(obj);
	while (node != null){
		node.style.display = 'none';
		node = get_nextsibling(node);
	}
}

function toggle_display(obj){
	/* use this function to hide the details of the different forms. then unhide the selected value. */
	hide_display(obj);
	var x=1;
	if (Number(obj.value) != 0){
		/* loop through the siblings to activate the correct selection */
		node = get_nextsibling(obj);
		while (x != Number(obj.value)){
			node = get_nextsibling(node);
			x++;
		}
		node.style.display = '';
	}
}


function CheckPrescription( myform){
// will check for required fields.

var message = 'Required Field(s) missing:\n\n';
var isgood = true;

message = message + myform.pname.value + '\n';

if(myform.scriptdetail.value == 0){
  message = message + '  Script Detail Required. \n';
  isgood = false;
}
else{
  if(myform.scriptdetail.value == 'script on file'){
  
    if( myform.HSpatientname.value == '' ){ 
      message = message + '  Patient Name Required.\n';
      isgood = false;
    }
    
  }
  else{
    if(myform.scriptdetail.value == 'mailing script'){
    
      if( myform.Mpatientname.value == '' ){ 
        message = message + '  Patient Name Required.\n';
        isgood = false;
      }
      
    }
    
  }
  
}

if( isgood )
  { return true; }
else{
  alert( message );
  return false;
}

}

function CheckPrescriptionM( myform ){
// WILL CHECK FOR REQUIRED FEILDS.

var message = 'Required Feild(s) missing:\n\n';
var isgood = true;
var i;

for( i=0; i < myform.pname.length; i++ ){
  message = message + myform.pname[i].value + '\n';
      
  if(myform.scriptdetail[i].value == 0){
    message = message + '  Script Detail Required.\n';
    isgood = false;
  }
  else{
    if(myform.scriptdetail[i].value == 'script on file'){
      if( myform.HSpatientname[i].value == '' ){ 
        message = message + '  Patient Name Required.\n';
        isgood = false;
      }
    }
    else{
      if(myform.scriptdetail[i].value == 'mailing script'){
        if( myform.Mpatientname[i].value == '' ){ 
          message = message + '  Patient Name Required.\n';
          isgood = false;
        }
      }  
    }
  }
      
  message = message + '\n'
}

if( isgood )
  { return true; }
else{
  alert( message );
  return false;
}

}

/******************
Product Search save position
******************/
function getSearchSelection(myList) {
    // load the selection for the search.
    var Selection = Cookies.getCookie('search'); // get the search cookie.
    if (typeof (Selection) == 'undefined')
    { return; }
    try
        { myList.selectedIndex = Selection; }
    catch (ex)
        { myList.selectedIndex = 0; }
}

function setSearchSelection(myList) {
    // save the selection for the search.
    Cookies.setCookie('search', myList.selectedIndex);
}

/*****************
Catalogue page flipper new window open
*****************/
// get space available in browser
var winW = 0, winH = 0;

if (typeof (window.innerWidth) == 'number') {
    //Non-IE
    winW = window.innerWidth;
    winH = window.innerHeight;

} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
    //IE 6+ in 'standards compliant mode'
    winW = document.documentElement.clientWidth;
    winH = document.documentElement.clientHeight;

} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
    //IE 4 compatible
    winW = document.body.clientWidth;
    winH = document.body.clientHeight;
}

//open window based on browser space
function openCatWindowA(url) {
    window.open(url, "catviewer", "width=" + winW + ",height=" + winH + ",scrollbars=yes,resizable=yes,top=10,left=0");
}
