// JavaScript Document
//	Copyright 2005 Zia Moda LLC.	June 22, 2005 v006c: updated email to a friend PHP solution:
//	fix email to friend code to maintain "discount codes" or other parameters on an extended URL (like Google click through codes)


//	returns the position on the screen of the center of the current browser window, CURRENTLY ONLY WORKS FOR IE
function WindowCenter(center) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
  center[0] = Math.round(myWidth/2);
  center[1] = Math.round(myHeight/2);
  //window.alert( 'center x = ' + center[0] );
  //window.alert( 'center y = ' + center[1] );

}

//	function called by "email to a friend" link on a product details page
function emailToFriend (itemID, itemNumber, itemName) {
	//	encode itemName to be appended in a URL, remove illegal characters
	var urlLegalName = escape(itemName);	
	//	append parameters to end of URL
	var pageNparams = new String('/mailer/email_a_friend.htm');	//	ensure the correct path for this file--in this case it is in the same directory as the calling page
	pageNparams += '?';
	pageNparams += itemID;
	pageNparams += '&';
	pageNparams += itemNumber;
	pageNparams += '&';
	pageNparams += urlLegalName;

	//	set popup window parameters
	var popupParams = new String('width=485,height=458,status=0,toolbar=0,menubar=0,scrollbars=0,titlebar=0, location=0');

	//	If browser is Microsoft Internet Explorer, set popup window position (I'll come back and figure out how to do it for other browsers)
	if (navigator.appName == "Microsoft Internet Explorer") {
		var centerPoint = new Array(2);	// array to hold X and Y values
		WindowCenter(centerPoint);
		var popupLeft =  window.screenLeft + centerPoint[0] - 98;	// 98 is xoffset desired based on dialog width and page contents width
		var popupTop = window.screenTop + 53;

		popupParams = popupParams + ',left=' + popupLeft;
		popupParams = popupParams + ',top=' + popupTop;
	}
	else {
		//	alert('other browsers');
		//	for now, using default position given by browser
	}

	emailToFriendPopup = window.open(pageNparams, 'popupWin', popupParams);
	emailToFriendPopup.focus();	//	make sure popup window is on top
}

function big_name(imageName) {
	var splitString = imageName.split('.');
	var newString = new String();
	newString = splitString[0] + '_big.' + splitString[1];
	return newString;
}