
//*--------------------------------------------------------------------------------------------------
//* 2007-10-23 - Change subscribe email from groupmail@ec-edi.biz to groupmail@ec-edi-mail.com
//* 2008-06-08 - Add rtns need for banner.js.  Cookies, Date format.
//* 2008-10-21 - Add TradingPartners to doClearSearch 
//* 2009-04-25 - Update viewlist() with calltype parm for tpid (ref.asp)
//* 2009-10-21 - Edition Search
//* 2010-07-11 - Milonic ChangeItmeProperty function - Used in ref.asp website button
//* 2010-08-15 - Fix alphaSearch() to pass b o or h to dir-search-adv.asp
//*--------------------------------------------------------------------------------------------------

function mm_changeItemProperty(menuName, itemName, codeRef, newValue, updateDisplay)
{
  menuName = menuName.toLowerCase();
  for (i=0; i<_mi.length; i++)
    if (_mi[i][1].replace(/\ \;/ig,' ') == itemName && _m[_mi[i][0]][1] == menuName) break;
  if (i == _mi.length) return;
  _mi[i][codeRef] = newValue;
  if (updateDisplay) BDMenu(_mi[i][0]);
}

function EditionSearch (form, letter ) {		
//******************************************************************************* 
//  dir-search.asp?list=a?sect=" & qsSectionPref  NOT USED
//*******************************************************************************  
	if (document.form0.SectionPref[0].checked) sSectPref = "B2B"
 	if (document.form0.SectionPref[1].checked) sSectPref = "Healthcare"   
			
    theCall = "dir-search.asp?list=" + letter + "&sect=" + sSectPref
 
//  alert(theCall)

	document.form0.action = theCall;  
	document.form0.method = "POST";
	document.form0.submit()
	return(0); 	 
}

function alphaSearchTESTING (form, letter ) {		
//******************************************************************************* 
//   dir-search-adv.asp?ed=b&list=d
//   dir-search-adv.asp?ed=EDITION&list=LETTER     EDITION b=B2B  h=Healthcare
//*******************************************************************************  
//	if (document.form0.SectionPref[0].checked) sSectPref = "B2B"
// 	if (document.form0.SectionPref[1].checked) sSectPref = "Healthcare"   
//alert(sSectPref)
	sSectPref = "h";  //B2B	
     theCall = "dir-search-adv.asp?ed=" + sEdition + "&list=" + letter
//    theCall = "dir-search-adv.asp?ed=" + sEdition + "&list=" + letter + "&sect=" + sSectPref
//    alert(theCall)
	document.form0.action = theCall;  
	document.form0.method = "POST";
	document.form0.submit()
	return(0); 	 
}


function alphaSearch (form, letter ) {		
//******************************************************************************* 
//   dir-search-adv.asp?ed=b&list=d
//   dir-search-adv.asp?ed=EDITION&list=LETTER     EDITION b=B2B  h=Healthcare
//*******************************************************************************  
//  var dir = location.href.substring(0,location.href.lastIndexOf('/')+1);
//  var thefile = location.href.substring(dir.length,location.href.length+1);
//* The file is defined in men-Data-ecedi_side1.js
//* eg dir-search-adv.asp?ed=b&list=c

// alert (thefile);
 
	var sEdition = "b";  //B2B	DEFAULT
	
	var posb = thefile.indexOf("ed=b");
	var posh = thefile.indexOf("ed=h");
 
	if (posb >= 0) {
		sEdition = "b";  //B2B	
	} 
	if (posh >= 0) {
		sEdition = "h";  //Healthcare	
	} 
 
    theCall = "dir-search-adv.asp?ed=" + sEdition + "&list=" + letter
	document.form0.action = theCall;  
	document.form0.method = "POST";
	document.form0.submit()
	return(0); 	 
}

//*** HARDCODED B2B, don't know why this is.
function alphaSearch_ORIG (form, letter ) {		
//******************************************************************************* 
//   dir-search-adv.asp?ed=b&list=d
//   dir-search-adv.asp?ed=EDITION&list=LETTER     EDITION b=B2B  h=Healthcare
//*******************************************************************************  
	sEdition = "b";  //B2B	
    theCall = "dir-search-adv.asp?ed=" + sEdition + "&list=" + letter
	document.form0.action = theCall;  
	document.form0.method = "POST";
	document.form0.submit()
	return(0); 	 
}

function alphaSearchOLD (form, letter ) {		
//******************************************************************************* 
//  dir-search.asp?list=a?sect=" & qsSectionPref
//*******************************************************************************  
	if (document.form0.SectionPref[0].checked) sSectPref = "B2B"
 	if (document.form0.SectionPref[1].checked) sSectPref = "Healthcare"   
			
    theCall = "dir-search.asp?list=" + letter + "&sect=" + sSectPref
 
//  alert(theCall)

	document.form0.action = theCall;  
	document.form0.method = "POST";
	document.form0.submit()
	return(0); 	 
}

function viewpdf  (pdfname, vendorid, section, typex ) {		
//******************************************************************************* 
//    Quick Product Selector
//******************************************************************************* 

//* 2006-03-09 Call veiwList which displays the lising from the database instead of the PDF
	if (typex == "list") {
		viewList (vendorid, section, "qps");
		return; 
	}
	
	if (typex == "ad") {
//		alert("typex=" + typex)
		viewAd (vendorid,pdfname, section, "qps");
		return; 
	}	

	var pdfdir = "../download/";
 	var thePDF; 	
//	if (pdfname == "") return;  // handles Select instruction.
	thePDF = pdfdir + pdfname + ".pdf"
//	alert("thePDF=" + thePDF)
 
 theCall = "viewpdf.asp?pdf=" + pdfname + "&vid=" + vendorid + "&section=" + section + "&type=" + typex
 window.open(theCall, "newwin", "width=800,height=600,menubar=yes;toolbar=yes;scrollbars=yes,status=yes,resizable=yes");
     
	return; 
}

function viewList  (vendorid, section,  calltype) {		
//******************************************************************************* 
//    View Vendor Listing -  dir-search.asp.  
//    viewlist.asp will log the click and display the dynamically generated HTML page.
//*******************************************************************************  
 var theCall = "dir-viewlist.asp?vid=" + vendorid
 
// var theCall = "dir-viewlist.asp?vid=" + vendorid + "&section=" + section;
 
// alert(theCall)

//* If listing button pressed in qps side bar 
 if (calltype == "qps" || calltype == "tpid" ) {
 	theCall = "dir-viewlist.asp?vid=" + vendorid + "&section=" + section +  "&calltype=qps";
 }	
 if (calltype == "tpid" ) {
 	theCall = "dir-viewlist.asp?vid=" + vendorid + "&section=" + section +  "&calltype=tpid";
 }	
 
  window.open(theCall,"newwin","width=950,height=700,menubar=yes,location=yes,toolbar=yes,scrollbars=yes,status=yes,resizable=yes");
 
	return; 
}

function viewWeb  (vendorid, website ) {		
//******************************************************************************* 
//    View web site -  dir-search.asp.  viewweb.asp will log the click and display the site
//*******************************************************************************  
 theCall = "dir-viewweb.asp?vid=" + vendorid + "&web=" + website
//  alert(theCall)
  window.open(theCall,"newwin","width=950,height=700,menubar=yes,location=yes,toolbar=yes,scrollbars=yes,status=yes,resizable=yes");
 
	return; 
}

function viewAd (vendorid, adfile, section,  calltype) {		
//******************************************************************************* 
//    View AD -  dir-search.asp.  viewad.asp will log the click and display the PDF
//*******************************************************************************  
 theCall = "dir-viewad.asp?vid=" + vendorid + "&ad=" + adfile;
 
//* If listing button pressed in qps side bar 
 if (calltype == "qps") {
 	theCall = "dir-viewad.asp?vid=" + vendorid + "&ad=" + adfile + "&section=" + section +  "&calltype=qps";
 }	 
 
//  alert(theCall)
   window.open(theCall,"newwin","width=800,height=700,menubar=yes,location=yes,toolbar=yes,scrollbars=yes,status=yes,resizable=yes"); 
 
	return; 
} 

function doComplist (form ) {	
//******************************************************************************* 
//    Place selected item in Compliance text field.  dir-search.asp
//******************************************************************************* 
	var item;
	var itemval;
	item  = document.form0.Complist.selectedIndex;
	itemval = document.form0.Complist.options[item].value;
 	document.form0.Compliance.value = itemval; 	
 	document.form0.Complist.selectedIndex = 0;
	return; 
}

function viewAd_OLD (fname ) {	
//******************************************************************************* 
//    Quick Product Selector  OLD
//******************************************************************************* 
	var pdfdir = "../download/";
 	var thePDF; 	
	if (fname == "") return;  // handles Select instruction.
	thePDF = pdfdir + fname + ".pdf"
//	alert("thePDF=" + thePDF)
    window.open(thePDF, "newwin", "width=800,height=600,menubar=yes;toolbar=yes;scrollbars=yes,status=yes,resizable=yes");
	return; 
}

function doSubNews ( form ) {	
//******************************************************************************* 
//  Subscribe to news   
//******************************************************************************* 
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage="";
	var errorcode=0; 
	var len;
    if (document.form1.Email.value.length ==0 || document.form1.Email.value.indexOf('@', 0) == -1 || document.form1.Email.value.indexOf('.', 0) == -1) 
 	{errormessage=errormessage+"Email address\n"} 
 	
// 	errormessage ="";  // Uncomment to deactivate validation for Testing
   
	if (errormessage !="") { alert (firstmessage + errormessage) ; return false; }
	else { 	
		document.form1.sendemailto.value = "groupmail@ec-edi-mail.com";
//		document.form1.sendemailto.value = "groupmail@ec-edi.biz";		//* OLD
// 		document.form1.sendemailto.value = "pc@twistedpixel.com"; 	 //* TEST
// 		document.form1.sendemailbcc.value = "pc@twistedpixel.com"; 	 //* TEST
  		document.form1.sendemailfrom.value  = document.form1.Email.value
  		document.form1.sendemailsubject.value = "EC-EDI: News Subscribe";
    	document.form1.redirect.value = "http://www.ec-edi.biz/" + testdir + "content/en/confirm.asp?fid=subscribe";
  		document.form1.action = "http://www.ec-edi.biz/" + testdir + "mailer/formsend.asp";  
  		document.form1.method = "POST";
  		document.form1.submit()
		return(0); 	
   }  
}

 function spaceTrim(InString) {
//*******************************************************************************
// Trim leading and trailing spaces of form input fields
//*******************************************************************************
	var LoopCtrl=true;
	while (LoopCtrl) {
		if (InString.indexOf("  ") != -1) {
			Temp = InString.substring(0, InString.indexOf("  "))
			InString = Temp + InString.substring(InString.indexOf("  ")+1, 
				InString.length)
		} else
			LoopCtrl = false;
	}
	if (InString.substring(0, 1) == " ")
		InString = InString.substring(1, InString.length)
	if (InString.substring (InString.length-1) == " ")
		InString = InString.substring(0, InString.length-1)
	return (InString)
}
function isNumberString (InString)  {
//*******************************************************************************
// Check if string is a number
//*******************************************************************************
	if(InString.length==0) 
		return (false);
	RefString="1234567890";
	for (Count=0; Count < InString.length; Count++)  {
		TempChar= InString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1)  
			return (false);
	}
	return (true);
}

function isDollarString (InString)  {
//*******************************************************************************
// Check if string contains dollar amount chars
//*******************************************************************************
	if(InString.length==0) 
		return (false);
	RefString="1234567890.";
	for (Count=0; Count < InString.length; Count++)  {
		TempChar= InString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1)  
			return (false);
	}
	return (true);
}

function doClear ( form ) {	
//*******************************************************************************
// Clear Form  -  
//*******************************************************************************	
//alert(pagelang);
    var msg_e = "Are you sure that you want to clear all the data you have entered on this form?";
    var msg_f = "Voulez-vous vraiment effacer toutes les données?";
    var clearmsg = msg_e;
 // if (pagelang == "f") clearmsg = msg_f;
    
	var confirmOK = confirm(clearmsg);
  	if (confirmOK) document.form0.reset();    
}

function doClearSearch ( form ) {	
//*******************************************************************************
// Clear Search Form  
//*******************************************************************************	
//alert(pagelang);
    var msg_e = "Are you sure that you want to clear all the data you have entered on this form?";
    var msg_f = "Voulez-vous vraiment effacer toutes les données?";
    var clearmsg = msg_e;
 // if (pagelang == "f") clearmsg = msg_f;
    
	var confirmOK = confirm(clearmsg);
  	if (confirmOK) {
  	
 	 	//document.form0.reset();    
  		document.form0.Category.selectedIndex = 0;
  		document.form0.Industry.selectedIndex = 0;
  		document.form0.StateProv.selectedIndex = 0;
  		document.form0.Complist.selectedIndex = 0;
  		document.form0.Complist.selectedIndex = 0;
  		document.form0.Compliance.value = "";
  		document.form0.TradingPartners.value = "";
  		document.form0.Keywords.value = "";
	}
}

function formatDollar (Val, DollarSign)  {
//*******************************************************************************
//	format Dollar
//*******************************************************************************	
	Val=""+Val;
	if (Val.indexOf (".", 0)!=-1) {
		Dollars = Val.substring(0, Val.indexOf (".", 0));
		Cents = Val.substring(Val.indexOf (".", 0)+1, Val.indexOf (".", 0)+9);
		if (Cents.length==0) Cents="00";
		if (Cents.length==1) Cents=Cents+"0";
		if (Cents.length > 2 ) return (false);   // bad if 12.123
	} else {
		Dollars = Val;
		Cents = "00";
	}

		return (Dollars + "." + Cents);
}
function isInteger(s)
//*******************************************************************************
//	is it an integer?
//*******************************************************************************	
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

 function doSelect(fld) {
//*******************************************************************************
// If selection value is blank, set to first item
//*******************************************************************************
 //	alert("fld =" + fld )
	var item =  eval('document.form0.' + fld + '.selectedIndex'); 
 //	alert("item =" + item )
	var selval = eval('document.form0.' + fld + '.options[item].value');
//	alert("selval =" + selval )
	if (selval == "") {  
 		eval('document.form0.' + fld + '.selectedIndex = 0');
	} 
}

function clearText(thefield){
//******************************************************************************* 
//  Clear text from input filed on focus  <input type="text" value="Search this site" onFocus="clearText(this)">
//******************************************************************************* 	
if (thefield.defaultValue==thefield.value)
thefield.value = ""
} 

function setCookie(c_name,value,expiredays)
//*******************************************************************************
//	SET COOKIE  from http://www.w3schools.com/js/js_cookies.asp
//*******************************************************************************
{
	var exdate=new Date()
	exdate.setDate(exdate.getDate()+expiredays)
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return ""
} 

/*
	Date Format 1.1
	(c) 2007 Steven Levithan <stevenlevithan.com>
	MIT license
	With code by Scott Trenda (Z and o flags, and enhanced brevity)
	http://blog.stevenlevithan.com/archives/date-time-format
*/

/*** dateFormat
	Accepts a date, a mask, or a date and a mask.
	Returns a formatted version of the given date.
	The date defaults to the current date/time.
	The mask defaults ``"ddd mmm d yyyy HH:MM:ss"``.
*/
var dateFormat = function () {
	var	token        = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloZ]|"[^"]*"|'[^']*'/g,
		timezone     = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
		timezoneClip = /[^-+\dA-Z]/g,
		pad = function (value, length) {
			value = String(value);
			length = parseInt(length) || 2;
			while (value.length < length)
				value = "0" + value;
			return value;
		};

	// Regexes and supporting functions are cached through closure
	return function (date, mask) {
		// Treat the first argument as a mask if it doesn't contain any numbers
		if (
			arguments.length == 1 &&
			(typeof date == "string" || date instanceof String) &&
			!/\d/.test(date)
		) {
			mask = date;
			date = undefined;
		}

		date = date ? new Date(date) : new Date();
		if (isNaN(date))
			throw "invalid date";

		var dF = dateFormat;
		mask   = String(dF.masks[mask] || mask || dF.masks["default"]);

		var	d = date.getDate(),
			D = date.getDay(),
			m = date.getMonth(),
			y = date.getFullYear(),
			H = date.getHours(),
			M = date.getMinutes(),
			s = date.getSeconds(),
			L = date.getMilliseconds(),
			o = date.getTimezoneOffset(),
			flags = {
				d:    d,
				dd:   pad(d),
				ddd:  dF.i18n.dayNames[D],
				dddd: dF.i18n.dayNames[D + 7],
				m:    m + 1,
				mm:   pad(m + 1),
				mmm:  dF.i18n.monthNames[m],
				mmmm: dF.i18n.monthNames[m + 12],
				yy:   String(y).slice(2),
				yyyy: y,
				h:    H % 12 || 12,
				hh:   pad(H % 12 || 12),
				H:    H,
				HH:   pad(H),
				M:    M,
				MM:   pad(M),
				s:    s,
				ss:   pad(s),
				l:    pad(L, 3),
				L:    pad(L > 99 ? Math.round(L / 10) : L),
				t:    H < 12 ? "a"  : "p",
				tt:   H < 12 ? "am" : "pm",
				T:    H < 12 ? "A"  : "P",
				TT:   H < 12 ? "AM" : "PM",
				Z:    (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
				o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4)
			};

		return mask.replace(token, function ($0) {
			return ($0 in flags) ? flags[$0] : $0.slice(1, $0.length - 1);
		});
	};
}();

// Some common format strings
dateFormat.masks = {
	"default":       "ddd mmm d yyyy HH:MM:ss",
	shortDate:       "m/d/yy",
	mediumDate:      "mmm d, yyyy",
	longDate:        "mmmm d, yyyy",
	fullDate:        "dddd, mmmm d, yyyy",
	shortTime:       "h:MM TT",
	mediumTime:      "h:MM:ss TT",
	longTime:        "h:MM:ss TT Z",
	isoDate:         "yyyy-mm-dd",
	isoTime:         "HH:MM:ss",
	isoDateTime:     "yyyy-mm-dd'T'HH:MM:ss",
	isoFullDateTime: "yyyy-mm-dd'T'HH:MM:ss.lo"
};

// Internationalization strings
dateFormat.i18n = {
	dayNames: [
		"Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat",
		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
	],
	monthNames: [
		"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
		"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
	]
};

// For convenience...
Date.prototype.format = function (mask) {
	return dateFormat(this, mask);
}
function delcookie() {
//* Delete specific cookie. 	
   delete_cookie ( "banner" );
   showcookie();
   }    
 
function showcookie() {
//* Show specific cookie. 	
   var Cvote=getCookie('banner');
   alert('The cookie= ' + Cvote);
   }
   
function get_random(pcount) {
    var ranNum= Math.round(Math.random()* pcount);
    return ranNum;
}