
//----------------------------------------------------------------------------------------------------
// openCalendarPopup opens the common calendar.asp page
// This page is located in /includes/calendar.asp
// All we pass are the query string parameters which can include parent form, parent field, etc
//----------------------------------------------------------------------------------------------------
function openCalendarPopup(QUERY_STRING)
{
	var url = "/includes/browsers/calendars/basic.asp?" + QUERY_STRING;
	w = 235;
	h=250;
	var newWin = "";
	newWin = window.open(url,"CALENDAR_POPUP_WINDOW",'width=' + w + ', height=' + h + ',resizable,status,menu=0,scrollbars');
	newWin.focus();
}

//----------------------------------------------------------------------------------------------------
//-- newWindowPopup opens a new popup window
//-- The URL of the window is passed as well as its width and height
//-- LEGACY FUNCTION
//----------------------------------------------------------------------------------------------------
function newWindowPopup(nom,w,h)
{
	var url = nom;
	if(w=="")
		w = 425;
	if(h=="")
		h=500;
			
	var newWin = window.open(url,"NEW_WINDOW_POPUP",'width=' + w + ', height=' + h + ',resizable,menubar=0,status,toolbar,scrollbars');	
	newWin.focus();
}


//----------------------------------------------------------------------------------------------------
//-- Generic Admin OnResize function routine
//----------------------------------------------------------------------------------------------------
function ReloadRoutine()
{
}

//----------------------------------------------------------------------------------------------------
//-- Generic Admin OnUnload function routine
//----------------------------------------------------------------------------------------------------
function UnloadRoutine()
{
}

//----------------------------------------------------------------------------------------------------
//-- This function can be passed from a return keystroke on the Shopper Update or the Shopper Login textbox
//-- windowType tells us where this popup should go
//----------------------------------------------------------------------------------------------------

function shprShortsPopup(windowType, features, ADMIN_NSS_SHOPPER_NO)
{	
	var pageToGoTo = "";
	
	// If shopper update, stay on Admin Side
	if (windowType == "UPDATE")
	{		
		pageToGoTo = "/admin/shopper/shpr_update.asp?NSS_SHOPPER_NO=" + ADMIN_NSS_SHOPPER_NO;
	}
	else if ( windowType =="LOGIN_OTHER_SHOPPER" || windowType == "LOGIN_MY_SHOPPER" )
	{		
		// Go to Shopper Login Redirect page
		pageToGoTo = "/shopper/from_admin.asp?FROM_ADMIN=TRUE&NSS_SHOPPER_NO=" + ADMIN_NSS_SHOPPER_NO;
	}
	
	var URL = pageToGoTo; 
	
	newWindowPopupWithFeatures(URL,"NSS_ADMIN", features)
}

//----------------------------------------------------------------------------------------------------
// This function looks for a return key being pressed while the focus is on either of the Shopper Shorts textboxes
// If a return key is pressed, the appropriate action is taken in "shprShortsPopup"
//----------------------------------------------------------------------------------------------------
function onReturnKey(event, windowType, inputValue)
{
	// if (moz) else ie
	if(event.which)
		mykey = event.which;
	else
		mykey = event.keyCode;
		
	if(mykey == 13)
	{
		shprShortsPopup(windowType, "width=600,height=600,resizable=1,menubar=1,toolbar=1,location=1,scrollbars=1", inputValue);
	}

}

//----------------------------------------------------------------------------------------------------
//-- Function to show and hide header div layers for "logout", "client logins" and "shopper shrots"
//----------------------------------------------------------------------------------------------------
function showHideExpandLayer( showHideLayer, imageID, baseImageID )
{
	var currentDivLayer = "";
	//var currentImgLayer = "";
	//var currentImgStyle = "";
	var currentBaseImage = "";
	
	currentDivLayer = GetObj( showHideLayer, "STYLE");
	//currentImgLayer = GetObj( imageID, "LAYER");
	//currentImgStyle = GetObj( imageID, "STYLE");
	currentBaseImage = GetObj( baseImageID, "LAYER");
	
	var tmp_admin_logout_options = GetObj("admin_logout_options", "STYLE");
	var tmp_admin_client_logins_options = GetObj("admin_client_logins_options", "STYLE");
	var tmp_admin_shpr_shorts_options = GetObj("admin_shpr_shorts_options", "STYLE");
	
	if( showHideLayer == "admin_logout_options")	
	{
		tmp_admin_client_logins_options.display = "none";
		tmp_admin_shpr_shorts_options.display = "none";	
	}
	else if( showHideLayer == "admin_client_logins_options")
	{
		tmp_admin_logout_options.display = "none";
		tmp_admin_shpr_shorts_options.display = "none";	
	}
	else if( showHideLayer == "admin_shpr_shorts_options")	
	{
		tmp_admin_logout_options.display = "none";
		tmp_admin_client_logins_options.display = "none";
	}
		
	if( currentDivLayer.display == "none" )
	{		
		currentDivLayer.top = ( findPosY(currentBaseImage) * 1 + 24 ) + 'px';
		currentDivLayer.left = findPosX(currentBaseImage) + 'px';
		currentDivLayer.display = "";
		MM_swapImage(imageID,'','/images/admin/headers/130/buttons/submenu/expand_blue_up.jpg',1)
		//currentImgLayer.src = "/images/admin/headers/130/buttons/submenu/expand_blue_up.jpg";
	}
	else
	{
		currentDivLayer.display = "none";
		MM_swapImage(imageID,'','/images/admin/headers/130/buttons/submenu/expand_blue_down.jpg',1)
		//currentImgLayer.src = "/images/admin/headers/130/buttons/submenu/expand_blue_down.jpg";
	}
	
	window.status = "";
		
}

//----------------------------------------------------------------------------------------------------
//-- Img swap on header down and up arrows
//----------------------------------------------------------------------------------------------------
function showHideExpandButton( moveToStatus, imageID, showHideLayer )
{		
	var imageToUse = "";
	var currentDivLayer = "";
	var currentImgLayer = "";
	
	currentDivLayer = GetObj(showHideLayer, "STYLE");
	currentImgLayer = GetObj(imageID, "LAYER");	
		
	if(moveToStatus == "SHOW")
	{
		if( currentDivLayer.display == "none" )
		{
			MM_swapImage(imageID,'','/images/admin/headers/130/buttons/submenu/expand_blue_down.jpg',1)
			//imageToUse = "/images/admin/headers/130/buttons/submenu/expand_blue_down.jpg";	
		}
		else
		{
			MM_swapImage(imageID,'','/images/admin/headers/130/buttons/submenu/expand_blue_up.jpg',1)
			//imageToUse = "/images/admin/headers/130/buttons/submenu/expand_blue_up.jpg";	
		}		
	}
	else
	{
		if( currentDivLayer.display == "none" )
		{
			//MM_swapImage(imageID,'','/images/admin/headers/130/buttons/submenu/expand_white_down.jpg',1)
			//imageToUse = "/images/admin/headers/130/buttons/submenu/expand_white_down.jpg";	
			MM_swapImgRestore()
		}
		else
		{
			MM_swapImage(imageID,'','/images/admin/headers/130/buttons/submenu/expand_white_up.jpg',1)
			//mageToUse = "/images/admin/headers/130/buttons/submenu/expand_white_up.jpg";	
		}		
	}
	
	//currentImgLayer.src = imageToUse;
}


// Page Global Variables
var ie_check =document.all;
var mouse_locX, mouse_locY;

//----------------------------------------------------------------------------------------------------
//-- Constantly have the mouse position being returned
//----------------------------------------------------------------------------------------------------
document.onmousemove=getCurrentMouseLocation;

//----------------------------------------------------------------------------------------------------
//-- Function adds option to select list 
//----------------------------------------------------------------------------------------------------
function addExtraSelectListOption(form_name, form_field, option_text, option_value)
{
	//***Get current number of options present***//
	numItems = document.forms[form_name].elements[form_field].options.length;
	bolOption_Exists = false;
	
	 //***Check if option is already in slect list***//
	for (j=0;j<numItems;j++)
	{
		if (document.forms[form_name].elements[form_field].options[j].value == option_text)
		{
			bolOption_Exists = true;
		}
	}
			 
	//***write option to select list***//
	if (bolOption_Exists == false)
	{
		//alert(window.opener.document.forms[form_name].elements[form_field].options[numItems-1]);
		if (ie_check) 
		{
			new_option = document.createElement("option");
			new_option.text = option_text;
			new_option.value = option_value;
			document.forms[form_name].elements[form_field].options.add(new_option);
		}
		else
		{
			document.forms[form_name].elements[form_field].options[numItems]  = new Option(option_text, option_value);
		}		
	}
}


//----------------------------------------------------------------------------------------------------
//-- Function Retrieves Mouse X/Y coordicates 
//----------------------------------------------------------------------------------------------------
function getCurrentMouseLocation(e)
{
	//mouse_locX=(e||event).clientX;
	//mouse_locY=(e||event).clientY;
	if(ie_check)
	{
		mouse_locX = event.clientX;
		mouse_locY = event.clientY;
	}
	else
	{
		mouse_locX=(e||event).pageX;
		mouse_locY=(e||event).pageY;	
	}
}


//----------------------------------------------------------------------------------------------------
//-- Function DIsplays Color Palette/Chooser
//----------------------------------------------------------------------------------------------------
function OpenColorPalette (cp_form_name, cp_form_field)
{
	//alert(mouse_locX + " - " + mouse_locY);
	var cp_locationX, cp_locationY;
	cp_locationX = mouse_locX;
	cp_locationY = mouse_locY;
	
	//***Show Div conntaining color palette***//
	if (document.layers) 
		{
			document.layers["doc"].display = "";
			
		}
	else 
		{ 
			document.getElementById("doc").style.display="";
		}
		
	//***Set Width, Height and Position of Color Palette***//
	document.color.width=260;
    document.color.height=250;
	doc.style.top = cp_locationY;
	doc.style.left = cp_locationX;
	
	//***Store form and field names in hidden variables***//
	document.color_palette_form.CP_FORM_NAME.value = cp_form_name;
	document.color_palette_form.CP_FIELD_NAME.value = cp_form_field;
	
}

//----------------------------------------------------------------------------------------------------
//-- Function Transfers color selected from Color Palette to specific field in form
//----------------------------------------------------------------------------------------------------
function TransferPaletteColor (cp_color)
{
//***Retrieve form name and field name where color must be written to***//
cp_form_name = document.color_palette_form.CP_FORM_NAME.value
cp_form_field = document.color_palette_form.CP_FIELD_NAME.value

//***Write color to field ***//
if (cp_color != null)
{
	if (cp_color.length >= 6)
		{
		document.forms[cp_form_name].elements[cp_form_field].value = cp_color;
		}
}
//***Hide Div containing color palette***//
Hide_ColorPalette('doc');
}

//----------------------------------------------------------------------------------------------------
//-- Function Hides div containing Color Palette 
//----------------------------------------------------------------------------------------------------
function Hide_ColorPalette(current_div)
{
//***Hide div containing Color Palette/chooser***//
if (document.layers) 
	{
		document.layers["doc"].display = "None";
	}
else 
	{ 
		document.getElementById("doc").style.display="None";
	}
}

//----------------------------------------------------------------------------------------------------
// submitFormToPopup submits a form to a popup window
// This function takes the form name, URL of the popup, popup window name and the features / settings of the popup window
//----------------------------------------------------------------------------------------------------
function submitFormToPopup(strFORM, strACTION_URL, strWIN_NAME, strFEATURES){
	window.open("", strWIN_NAME, strFEATURES);
    document.forms[strFORM].action = strACTION_URL;
    document.forms[strFORM].target = strWIN_NAME;
    document.forms[strFORM].submit()
}

//----------------------------------------------------------------------------------------------------
//-- Return object type reference (i.e. Div Layer, CSS layer, etc)
//----------------------------------------------------------------------------------------------------
function GetObj(name, objType)
{
	var currObj;
	
	 if (document.getElementById)
	 {
	 	if( objType == "LAYER" )
		{		
			currObj = document.getElementById(name);
		}
		else if ( objType == "STYLE" )		
		{			
			currObj = document.getElementById(name).style;
		}
	 }
	 else if (document.all)
	 {
	 	if( objType == "LAYER" )		
		   currObj = document.all[name];
		else if ( objType == "STYLE" )		
		   currObj = document.all[name].style;
	 }
	 else if (document.layers)
	 {
		   if (document.layers[name])
		   {
	   		if( objType == "LAYER" )
				currObj = document.layers[name];
			else if ( objType == "STYLE" )
				currObj = document.layers[name];
		   }
		   else
		   {
		   	if( objType == "LAYER" )
				currObj = document.layers.testP.layers[name];
			else if ( objType == "STYLE" )
				currObj = document.layers.testP.layers[name];
		   }
	 }
	 
	 return currObj;
}


//----------------------------------------------------------------------------------------------------
//-- Image Swap functions
//----------------------------------------------------------------------------------------------------
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  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&&id.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//----------------------------------------------------------------------------------------------------
//-- Returns the X coordinate of any object on a web page.  Just pass the object and return the X value
//----------------------------------------------------------------------------------------------------
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

//----------------------------------------------------------------------------------------------------
//-- Returns the Y coordinate of any object on a web page.  Just pass the object and return the Y value
//----------------------------------------------------------------------------------------------------
function findPosY(obj)
{
	var curtop = 0;
	var printstring = '';
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	window.status = printstring;
	return curtop;
}

//----------------------------------------------------------------------------------------------------
// newWindowPopupWithFeatures opens a new popup window
// The URL of the window is passed as well as its name and features
//----------------------------------------------------------------------------------------------------
function newWindowPopupWithFeatures(URL,windowName, features)
{
	var url = URL;			
	var newWin = window.open( url, windowName,features);	
	newWin.focus();
}

//-----------------------------------------------------------------------------------------------------
//-- Check / Uncheck all checkboxes function
//-----------------------------------------------------------------------------------------------------

function checkUncheckAllFields( formName, selectAllCheckbox, listCheckbox)
{
	if( eval("document." + formName + "." + listCheckbox) )
	{
		var bolAllChecked	= eval("document." + formName + "." + selectAllCheckbox + ".checked");
		var listLength			= eval("document." + formName + "." + listCheckbox + ".length");
		
		if( listLength > 1 )
		{
			for( i=0; i< listLength; i++ )
			{
				eval( "document." + formName + "." + listCheckbox + "[" + i + "].checked=" + bolAllChecked );
			}
		}
		else
		{	
			eval( "document." + formName + "." + listCheckbox + ".checked=" + bolAllChecked );
		}
	}	
	
}

//-----------------------------------------------------------------------------------------------------
//-- Take a string and return true/false based on if string is numeric
//-----------------------------------------------------------------------------------------------------
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;   
}





