// THIS IS A STANDARD JAVASCRIPT FILE USED FOR CDMS INTERNATIONAL
// THIS DECLARES ALL THE REGULAR EXPRESSIONS THAT WE WILL BE USING
// FOR VALIDATION FUNCTIONS.

    var msgWindow;


startList = function() {
if (document.all&&document.getElementById) {
cssdropdownRoot = document.getElementById("cssdropdown");
for (x=0; x<cssdropdownRoot.childNodes.length; x++) {
node = cssdropdownRoot.childNodes[x];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
}
node.onmouseout=function() {
this.className=this.className.replace(" over", "");
}
}
}
}
}

if (window.attachEvent)
window.attachEvent("onload", startList)
else
window.onload=startList;


var regWhitespace                = /^\s+$/;

// =========================== 
// FUNCTIONS
// ===========================

function isEmpty(s)       { return ((s == null) || (s.length == 0)) }
function isWhitespace (s) { return (isEmpty(s)  || regWhitespace.test(s)); }
// =========================== 
//
// ===========================

function 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 newGalleryCategory( that ) {

   that.cn.value='0'; 
   that.required_title.value=''; 

}

function newGalleryImage( that ) {

   that.cn.value='0'; 
   that.required_title.value=''; 
   that.required_msg.value='';

}

function newSnippet( that ) {

   that.cn.value='0'; 
   that.required_title.value=''; 
   that.required_msg.value='';

}

function newMedia( that ) {

   that.cn.value='0'; 
   that.required_title.value=''; 
   that.required_filename.value='';

}

function addtoList( oList1, oList2, cHidden ) {
var i;
var isNew = true;
var cTemp = '';

   if (oList2.length != 0) {
      for (i = 0; i < oList2.length; i++) {
         thisitem = oList2.options[i].text;
         if (thisitem == oList1.options[oList1.selectedIndex].text ) {
            isNew = false;
            break;
         }
      }
   } 
 
   if (isNew) {
      newoption = new Option( oList1.options[oList1.selectedIndex].text , oList1.options[oList1.selectedIndex].value, false, false);
      oList2.options[oList2.length] = newoption;
   }
   
  for (i = 0; i < oList2.length; i++) {
     cTemp += ','+oList2.options[i].value;
  }
  cHidden.value = cTemp;
  oList1.selectedIndex=-1;
}

function closeDep() {

if (msgWindow && msgWindow.open && !msgWindow.closed) msgWindow.close();

}


// =========================== 
//
// ===========================
function removeFromList( oList, cHidden ) {
  var boxLength = oList.length;  
   arrSelected = new Array();
   var count = 0;
   for (i = 0; i < boxLength; i++) {
      if ( oList.options[i].selected) {
         arrSelected[count] = oList.options[i].value; 
      }
      count++;
   }
   var x;
   for (i = 0; i < boxLength; i++) {
      for (x = 0; x < arrSelected.length; x++) {
         if ( oList.options[i].value == arrSelected[x]) {
            oList.options[i] = null;
         }
      }
      boxLength = oList.length;
   }
   
  for (i = 0; i < oList.length; i++) {
    oList.options[i].selected = true;
  }
}
// =========================== 
//
// ===========================

function toggle(img, node) {

    var target = document.getElementById(node);
    if (target.style.display == "none") {
       target.style.display = "block";
    } else {
      // target.style.display = "none"; - disabled it
    }
}


function file_name_only(str) {
   var slash = '/';
   if (str.match(/\\/)) {
      slash = '\\';
   }
   sURL = str.substring(str.lastIndexOf(slash) + 1);
   return sURL;
}

function SimpleDate(date){
	if (date == null){
		this.dateValue = new Date();
	}else if (date instanceof Date){
		this.dateValue = date;
	}else{
		var longValue = parseInt(date, 10);
	 	this.dateValue = new Date(longValue);
	}
}

// =========================== 
//
// ===========================

function toggle_folder(img, node) {
    
    var cookie = readCookie( node );
    
    if ( cookie == '1' ) {
       createCookie(node , 0, 1);
    } else {
       createCookie(node , 1, 1);
    }
    
    var target = document.getElementById(node);
    if (target.style.display == "none") {
    target.style.display = "block";
    img.src = "images/openfolder.gif";
    } else {
     target.style.display = "none";
     img.src = "images/closedfolder.gif";
    }
}

function scaleImg(what,nWidth){
   var saveWidth = 0;

   what = document.getElementById(what);
   if (navigator.appName=="Netscape")
   winW = window.innerWidth;
   if (navigator.appName.indexOf("Microsoft")!=-1) 
   winW = document.body.offsetWidth;
   if (what.width>(nWidth) || saveWidth>(nWidth)) {
   if (what.width==(nWidth)) 
   what.width=saveWidth;

   else
   {
   saveWidth = what.width;
   what.style.cursor = "pointer";
   what.width=(nWidth);
   }

   }
}

function flip(name,src) {
    if (document.images)
        document.images[name].src = src;
}

// =========================== 
//
// ===========================

function warnEmpty (theField, s) { 
	theField.focus();
	cName = convert_name(s);
	alert('EMPTY:\n'+cName);
}

// =========================== 
//
// ===========================
function intgerOnly(i) {
	if(i.value.length>0) {
       i.value = i.value.replace(/[^\d|\.|\,]+/g, ''); 
	}
}
// =========================== 
//
// ===========================

function convert_name (s) {
	var v;
	if (s == 'NAME')      { v = 'Name'; }
	if (s == 'TITLE')     { v = 'Title'; }
	if (s == 'FNAME')     { v = 'First Name'; }
	if (s == 'LNAME')     { v = 'Last Name'; }
	if (s == 'HANDLE')    { v = 'User ID'; }
	if (s == 'EMAIL')     { v = 'Email Address'; }
	if (s == 'LINE1')     { v = 'Address Line 1'; }
	if (s == 'LINE2')     { v = 'Address Line 2'; }
	if (s == 'CITY')      { v = 'City'; }
	if (s == 'ZIPCODE')   { v = 'Postal Code'; }
	if (s == 'AMOUNT')    { v = 'Amount'; }
	if (s == 'LOT')    { v = 'Lot'; }
	if (s == 'PASSWD')    { v = 'Password'; }
	if (s == 'PHONE')     { v = 'Phone Number'; }
	if (s == 'MESSAGE')   { v = 'Message or Note Field'; }
	if (s == 'MSG')       { v = 'Message or Description'; }
    if (s == 'PART')      { v = 'Part Inventory Number'; }
	if (s == 'ACCOUNT')   { v = 'Account/Company Name'; }
	if (s == 'COMPANY')   { v = 'Account/Company Name'; }
	if (s == 'SUBJECT')   { v = 'Subject'; }
 	if (s == 'SEARCH')    { v = 'Search Parameter'; }
 	if (s == 'REASON')    { v = 'Reason Code'; }
 	if (s == 'DATE')      { v = 'Date'; }
    if (s == 'SKU')       { v = 'SKU'; }
    if (s == 'TRACKING')  { v = 'Tracking Number'; }
    if (s == 'BIN')       { v = 'Bin Location'; }
    if (s == 'USERID')    { v = 'User'; }

	return v;
}
// =========================== 
//
// ===========================

function validate(form) {
 var valid = true;

 for (i=0;i<form.length;i++) {
 		var tempobj=form.elements[i]; 		
		if (tempobj.name.substring(0,9)== "required_") {
			shortFieldName=tempobj.name.substring(9,30).toUpperCase();
			//alert(shortFieldName);
			// THIS IS TO CHECK TEXT BOXES AND TEXTAREA
			if (tempobj.type == 'text' || tempobj.type == 'textarea' || tempobj.type == 'hidden' || tempobj.type == 'password') {
  	            if (isWhitespace(tempobj.value)) { 
				   if (tempobj.type == 'hidden') { alert('Hidden');valid = false; break; }
  				   warnEmpty(tempobj,shortFieldName); valid = false; break; 
				
				}
			}
			//  THIS IS TO CHECK SELECT BOXES THAT ARE NOT SET TO THE FIRST OPTION
			if (tempobj.type.toString().charAt(0)=="s"&& tempobj.selectedIndex==0) { 
		     warnEmpty(tempobj,shortFieldName); valid = false; break; 
         }
		}
		
		
		if ( tempobj.name == "pict" || tempobj.name == "required_pict" ) {
		   if (!(isWhitespace(tempobj.value))) { 
            newWindow('/sms/modules/standard/screens/small-progress.php','progressbar','350','100');		
		   }
		}
  }

    if (!valid) { return false; } else { return true; }

} // CLOSING THE VALIDATE FUNCTION


// =========================== 
//
// ===========================

function createCookie(name, value, days)
{
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
    }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}
// =========================== 
//
// ===========================

function readCookie(name)
{
  var ca = document.cookie.split(';');
  var nameEQ = name + "=";
  for(var i=0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
  return null;
}
// =========================== 
//
// ===========================

function eraseCookie(name)
{
  createCookie(name, "", -1);
}




// =========================== 
//
// ===========================
function newWindow(file,window,wid,hei) {
	var wtop  = (screen.height - hei) / 2;
    var wleft = (screen.width - wid) / 2;
    msgWindow=open(file,window,"toolbar=no,resizable=yes,scrollbars=yes,width=" + wid + ",height=" + hei + ",top=" + wtop + ",left=" + wleft + ",screenX=" + wleft + ",screenY=" + wtop);
	msgWindow.focus();
    if (msgWindow.opener == null) msgWindow.opener = self;
}

// =========================== 
//
// ===========================

// function that displays status bar message

function dm(msgStr) {
  document.returnValue = false;
  if (document.images) { 
     window.status = msgStr;
     document.returnValue = true;
  }
}
// functions that swap images

function di(id,name){
  if (document.images) document.images[id].src=eval(name+".src");
}


if (document.images) {
 
   

}
// =========================== 
//
// ===========================
function comboItemSelected(oList1,oList2,cType) {
	if (oList2!=null){
 	    alert('oList2 Not Null and need to clear it out');
		clearComboOrList(oList2);
       if (oList1.selectedIndex==-1){
         oList2.options[oList2.options.length] = new Option('SELECT','');
       } else {
	  // fillCombobox(oList2,cType + '=' + oList1.options[oList1.selectedIndex].value);
	   fillCombobox(oList2,cType + oList1.options[oList1.selectedIndex].value);
	   }
	}
}

function clearComboOrList(oList) {
   for (var i = oList.options.length-1; i>=0 ; i--) {
	   oList.options[i]=null;
   }
   oList.selectedIndex = -1;
   if (oList.onchange) oList.onchange();
}

function fillCombobox(oList,vValue){
   if (vValue!=''){
	   if (assocArray[vValue]){
		   oList.options[0] = new Option('SELECT','');
		   var arrX = assocArray[vValue];
           for ( var i = 0; i<arrX.length ; i = i+2 ){
			   if (arrX[i]!='EOF') oList.options[oList.options.length] = new Option(arrX[i+1],arrX[i]);
           }
           if (oList.options.length == 1){
			   oList.selectedIndex=0;
			   if (oList.onchange) oList.onchange();
           }
       } else {
		 oList.options[0] = new Option('None Selected','');  
	   }
   }
}

function listboxItemSelected(oList1,oList2,cType) {
   if (oList2!=null) {
	   clearComboOrList(oList2);
      if (oList1.selectedIndex==-1) {
         oList2.options[oList2.options.length] = new Option('SELECT','');
      } else {
		 fillListbox(oList2,cType + oList1.options[oList1.selectedIndex].value)
		 // fillListbox(oList2,oList1.name + '=' + oList1.options[oList1.selectedIndex].value)
	  }
   }
   else {

   }
}


function fillListbox(oList,vValue){
   if (vValue!=''){
	   if (assocArray[vValue]){
		   var arrX = assocArray[vValue];
		   for ( var i = 0; i<arrX.length ; i = i+2 ){
			   
			   if (arrX[i]!='EOF') oList.options[oList.options.length] = new Option(arrX[i+1],arrX[i]);

           }
           if (oList.options.length == 1){
			   oList.selectedIndex=0;
			   if (oList.onchange) oList.onchange();
 
           }
       } else {
		 oList.options[0] = new Option('None Selected','');  
	   }

   }
   else {
     	
   }
 
}

//Pop-it menu- By Dynamic Drive

//
// ************************
// layer utility routines *
// ************************

function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
} // changeObjectVisibility

function moveObject(objectId, newXCoordinate, newYCoordinate) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.left = newXCoordinate;
	styleObject.top = newYCoordinate;
	return true;
    } else {
	// we couldn't find the object, so we can't very well move it
	return false;
    }
} // moveObject

// ********************************
// application-specific functions *
// ********************************

// store variables to control where the popup will appear relative to the cursor position
// positive numbers are below and to the right of the cursor, negative numbers are above and to the left
var xOffset = -75;
var yOffset = 5;

function showPopup (targetObjectId, eventObj) {
    if(eventObj) {
	// hide any currently-visible popups
	hideCurrentPopup();
	// stop event from bubbling up any farther
	eventObj.cancelBubble = true;
	// move popup div to current cursor position 
	// (add scrollTop to account for scrolling for IE)
	var newXCoordinate = (eventObj.pageX)?eventObj.pageX + xOffset:eventObj.x + xOffset + ((document.body.scrollLeft)?document.body.scrollLeft:0);
	var newYCoordinate = (eventObj.pageY)?eventObj.pageY + yOffset:eventObj.y + yOffset + ((document.body.scrollTop)?document.body.scrollTop:0);
	moveObject(targetObjectId, newXCoordinate, newYCoordinate);
	// and make it visible
	if( changeObjectVisibility(targetObjectId, 'visible') ) {
	    // if we successfully showed the popup
	    // store its Id on a globally-accessible object
	    window.currentlyVisiblePopup = targetObjectId;
	    return true;
	} else {
	    // we couldn't show the popup, boo hoo!
	    return false;
	}
    } else {
	// there was no event object, so we won't be able to position anything, so give up
	return false;
    }
} // showPopup

function hideCurrentPopup() {
    // note: we've stored the currently-visible popup on the global object window.currentlyVisiblePopup
    if(window.currentlyVisiblePopup) {
	changeObjectVisibility(window.currentlyVisiblePopup, 'hidden');
	window.currentlyVisiblePopup = false;
    }
} // hideCurrentPopup



// ***********************
// hacks and workarounds *
// ***********************

function explorerMacResizeFix () {
    location.reload(false);
}

// initialize hacks whenever the page loads
window.onload = initializeHacks;

// setup an event handler to hide popups for generic clicks on the document
document.onclick = hideCurrentPopup;

function initializeHacks() {
    // this ugly little hack resizes a blank div to make sure you can click
    // anywhere in the window for Mac MSIE 5
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
	&& (navigator.platform.indexOf('Mac') != -1)
	&& getStyleObject('blankDiv')) {
	window.onresize = explorerMacResizeFix;
    }
    resizeBlankDiv();
    // this next function creates a placeholder object for older browsers
    createFakeEventObj();
}

function createFakeEventObj() {
    // create a fake event object for older browsers to avoid errors in function call
    // when we need to pass the event object to functions
    if (!window.event) {
	window.event = false;
    }
} // createFakeEventObj

function resizeBlankDiv() {
    // resize blank placeholder div so IE 5 on mac will get all clicks in window
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
	&& (navigator.platform.indexOf('Mac') != -1)
	&& getStyleObject('blankDiv')) {
	getStyleObject('blankDiv').width = document.body.clientWidth - 20;
	getStyleObject('blankDiv').height = document.body.clientHeight - 20;
    }
}

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}

if (window.attachEvent)
{
   window.attachEvent("onload", correctPNG);
}


// 11/11/2002 - THE FOLLOWING FUNCTION HAS BEEN ADDED
// THIS ALLOWS FOR MOUSEOVER ALT TAGS AND EXPANDABLE 
// SECTIONS.




