var remoteWin=null;

var AudioPlayer = new Object();
AudioPlayer.play = function AudioPlayer_play(src) 
{
	if (!src) return false;
	this.stop();
	var elm;
	if (typeof document.all != "undefined") 
	{
		elm = document.createElement("bgSound");
		elm.src = src;
	}
	else 
	{
		elm = document.createElement("object");
		elm.setAttribute("data",src);
		elm.setAttribute("type","audio/x-wav");
		elm.setAttribute("controller","true");
	}
	document.body.appendChild(elm);
	this.elm = elm;
	return true;
};

AudioPlayer.stop = function AudioPlayer_stop() 
{
	if (this.elm) 
	{
		this.elm.parentNode.removeChild(this.elm);
		this.elm = null;
	}
};


function startPopupWindow(urlname, width, height, resizable, scrollbars)  // resizeable = yes or no   scrollable = 0 or 1(yes)
{
	//Modified as a fix for 184289 (Ruby-J) -- Shashank -- Modified for the fix for defect 188040
	var prop = "\"" + "toolbar=yes, resizable=" + resizable + ", scrollbars=" + scrollbars + ",width=" + width + ", height=" + height + "\"";
	//remoteWin = window.open(urlname,"PopupWindow",'toolbar=yes,resizable=' + resizable +',scrollbars=' + scrollbars + ',width=' + width + ',height=' + height);
	remoteWin = window.open(urlname,"PopupWindow",prop);
}
				
function openFeedback ()
{
		startPopupWindow('http://www.hp.com/go/ize/feedback1?sourceid=6', 570, 630, 'yes', '1');
}

function openTermsOfUse (tosURL)
{
	startPopupWindow(tosURL, 570, 630, 'yes', '1');
}

function OpenLargeView( url )
{
	url = url + '&index=' + globalIndex;	
	window.open( url,'', 'status=no, menuvar=no, scrollbars=yes,resizable=yes' );
}

function openLowBarPrintWindow(paramList)
{		
		window.open('/PrintEngineWebTier/PEWebInterface.aspx?'+paramList,
		"PrintWindow",
		'menubar=yes,' +
		'toolbar=no,' + 
		'resizable=yes,' + 
		'scrollbars=yes,' +
		'width=570,' + 
		'height=630');
}

function isSP2 ()
{
	return (window.navigator.userAgent.indexOf("SV1")!= -1)
}

/*****************************************
 *    ACTIVE-X DETECTION FUNCTIONS       *
 *****************************************/

var PRINT_PROGID = "LaunchPrintActiveX.LaunchPrint.1"; 
var PRINT_VERSION = 0.12; 
var SAVE_PROGID = "HighBarSaveActiveX.SaveImageFiles.1"; 
var SAVE_VERSION = 0.12; 
var retry = 0;

function isPrintActiveXInstalled()
{
	// VBScript detection of ActiveX
	try
	{
		if (isActiveXInstalledAndCurrent(PRINT_PROGID, PRINT_VERSION))
			return true;
	}
	catch (e)
	{}

	// Javascript detection ActiveX.
	try
	{
		if (checkActiveXVersion(PRINT_PROGID, PRINT_VERSION))
			return true;
	}
	catch(e)
	{}
	/*
	// Last ditch effort
	try
	{
		var version = PTLauncher.GetVersion();
		return compareVersion(version, PRINT_AT_HOME_VERSION);
	}
	catch(e){}
	*/
	return false;
}

function isSaveActiveXInstalled()
{
	// VBScript detection of ActiveX
	try
	{
		if (isActiveXInstalledAndCurrent(SAVE_PROGID, SAVE_VERSION))
			return true;
	}
	catch (e)
	{}

	// Javascript detection ActiveX.
	try
	{
		if (checkActiveXVersion(SAVE_PROGID, SAVE_VERSION))
			return true;
	}
	catch(e)
	{}
	/*
	// Last ditch effort
	try
	{
		var version = SaveLauncher.GetVersion();
		return compareVersion(version, PRINT_AT_HOME_VERSION);
	}
	catch(e){}
	*/
	return false;
}


function checkActiveXVersion(progId, progVersion)
{
	try
  {
		var obj = new ActiveXObject(progId);
		if (( obj ) 
			  && ( typeof obj.GetVersion() != "undefined" )
			  )
		{
			var vOld  = obj.GetVersion();
		  return ( vOld == progVersion );
		}
	}
	catch(e) {}
	return false;
}

function compareVersion( vOld, vNew )
{
	if ( vOld == vNew )
        return true;
	var y;
	var m;
	var d;
	var v;
	var ny;
	var nm;
	var nd;
	var nv;
	var vwork = vOld.split (",");
	if ( vwork.length == 4 )
	{
		y = vwork[0];
		m = vwork[1];
		d = vwork[2];
		v = vwork[3];
	}
	var vtemp = vNew;
    vwork = vtemp.split (",");
	if ( vwork.length == 4 )
	{
		ny = vwork[0];
		nm = vwork[1];
		nd = vwork[2];
		nv = vwork[3];
	}

	if (d.length == 1)
		d = "0" + d;

	if (m.length == 1)
		m = "0" + m;

	if (( y < ny ) ||
	   (( y == ny ) &&
		( m < nm )) ||
	   (( y == ny ) &&
		( m == nm ) &&
		( d < nd )) ||
	   (( y == ny ) &&
		( m == nm ) &&
		( d == nd ) &&
		( v < nv )))
		return false;
	 return true;
}

// This fn is used localize a formatted string
function FormatLocalizedString(localizedString, valuesArray)
{
	//localizedString=new String("One={0}, Two={1}, Three={2}, Four={3}");
	for(i=0;i<valuesArray.length;i++)
	{
		localizedString=localizedString.replace('{'+i+'}',valuesArray[i]);
	}
	return localizedString;
}

// This fn is used to update the Photo counter in Filmstrip view page
function UpdateImageIndexMessage(strMessage, imgIndex, totalImages)
{
	var message=new String(strMessage);
	message=message.replace(/\{0\}/gi,imgIndex+1);
	message=message.replace(/\{1\}/gi,totalImages);
	document.getElementById("toolbarImgCounter").innerHTML=message;
	RetrieveRotationFromCookies();
}
// Cookies management functions

<!--

/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}


/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}


/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}




// Image rotation calls to be used on FilmStrip and FullScreen pages

var rotationFactor=0;
function RotateInit()
{
	
	if(rotationFactor!=0)
	{
		rotationFactor=0;
		oDiv.style.filter='progid:DXImageTransform.Microsoft.BasicImage(rotation='+rotationFactor+')';
	}
}
function StoreRotationInCookies()
{
	var hashCodeEndIndex=aryThumbImages[globalIndex].indexOf("/thumbnail");
	var hashCodeBeginIndex=hashCodeEndIndex-36;
	var hashCode=aryThumbImages[globalIndex].substring(hashCodeBeginIndex,hashCodeEndIndex);
	var currentTime=new Date();
	var expireDate=new Date((currentTime.getFullYear()+1),currentTime.getMonth(),currentTime.getDate());
	setCookie(hashCode,rotationFactor,expireDate);
}

function RetrieveRotationFromCookies()
{
	var hashCodeEndIndex=aryThumbImages[globalIndex].indexOf("/thumbnail");
	var hashCodeBeginIndex=hashCodeEndIndex-36;
	var hashCode=aryThumbImages[globalIndex].substring(hashCodeBeginIndex,hashCodeEndIndex);
	var prevRotation=getCookie(hashCode);
	if(prevRotation!=null)
	{
		rotationFactor=prevRotation;
		oDiv.style.filter='progid:DXImageTransform.Microsoft.BasicImage(rotation='+rotationFactor+')';
	}
	else
	if(rotationFactor!=0)
	{
		rotationFactor=0;
		oDiv.style.filter='progid:DXImageTransform.Microsoft.BasicImage(rotation='+rotationFactor+')';
	}	
}

function RotatePhotoSlideShow() 
{
	StoreRotationInCookies();
	oDiv.style.filter='progid:DXImageTransform.Microsoft.BasicImage(rotation='+rotationFactor+')';
}

function RotateLeftSlideShow()
{
	rotationFactor--;
	if(rotationFactor<0)
		rotationFactor=3;
	RotatePhotoSlideShow();
}

function RotateRightSlideShow()
{
	rotationFactor++;
	if(rotationFactor>3)
		rotationFactor=0;
	RotatePhotoSlideShow();
}



function RotatePhoto()
{
	StoreRotationInCookies();
	oDiv.style.filter='progid:DXImageTransform.Microsoft.BasicImage(rotation='+rotationFactor+')';
	var thumbDiv=document.getElementById("oDivThumbNail"+globalIndex);
	thumbDiv.style.filter='progid:DXImageTransform.Microsoft.BasicImage(rotation='+rotationFactor+')';
}

function RotateLeft()
{
	rotationFactor--;
	if(rotationFactor<0)
		rotationFactor=3;
	RotatePhoto();
}

function RotateRight()
{
	rotationFactor++;
	if(rotationFactor>3)
		rotationFactor=0;
	RotatePhoto();
}

function RotateInitThumbnail()
{
	// Update all the thumbnailes and the first photo
	for(i=0;i<aryThumbImages.length;i++)
	{
		var hashCodeEndIndex=aryThumbImages[i].indexOf("/thumbnail");
		var hashCodeBeginIndex=hashCodeEndIndex-36;
		var hashCode=aryThumbImages[i].substring(hashCodeBeginIndex,hashCodeEndIndex);
		var prevRotation=getCookie(hashCode);
		if(prevRotation!=null)
		{
			// Update main photo
			//if(globalIndex==i)
			//{
			//	rotationFactor=prevRotation;
			//	oDiv.style.filter='progid:DXImageTransform.Microsoft.BasicImage(rotation='+prevRotation+')';
			//}
			// Update the thumbnail
			var thumbDiv=document.getElementById("oDivThumbNail"+i);
			
			thumbDiv.style.filter='progid:DXImageTransform.Microsoft.BasicImage(rotation='+prevRotation+')';
			
		}
		
	}
}

function RotateReset()
{
	// Update all the thumbnailes and the first photo
	for(i=0;i<aryThumbImages.length;i++)
	{
		var hashCodeEndIndex=aryThumbImages[i].indexOf("/thumbnail");
		var hashCodeBeginIndex=hashCodeEndIndex-36;
		var hashCode=aryThumbImages[i].substring(hashCodeBeginIndex,hashCodeEndIndex);
		var prevRotation=getCookie(hashCode);
		if(prevRotation!=null)
		{
			// Update main photo
			if(globalIndex==i)
			{
				rotationFactor=prevRotation;
				oDiv.style.filter='progid:DXImageTransform.Microsoft.BasicImage(rotation='+prevRotation+')';
			}
			// Update the thumbnail
			var thumbDiv=document.getElementById("oDivThumbNail"+i);
			thumbDiv.style.filter='progid:DXImageTransform.Microsoft.BasicImage(rotation='+prevRotation+')';
			
		}
		
	}
}

function UpdateSelectedPhotoCountMessage(strMessage, selPhotos)
{
	var message=new String(strMessage);
	message=message.replace(/\{0\}/gi,selPhotos);
	document.getElementById("toolbarImgCounter").innerHTML=message;
	if(document.getElementById("hdnPreviewflag"))
	{	
		RefreshPrintHTML();
	}

}
