/*==========================================================================*/
/*                      Copyright (c) 2003 Macromedia.                      */
/*                           All rights reserved.                           */
/*==========================================================================*/

/*==========================================================================*/
/*                         Save Time Stamp Auto Shape                       */
/*==========================================================================*/


/*==========================================================================*/
/* Localizable Strings                                                      */
/*==========================================================================*/
var kTitle;
var kFont = "Arial";
var isMacintosh = System.osName[0] == "M"; // either M or W
var tmp  = (Files.getLanguageDirectory()).split("/");
var lang = tmp[tmp.length-1];
switch (lang)
{
	// German
	case "de.lproj":
	case "German":
		kTitle = "Zeit gespeichert";		
		break;

	// French
	case "fr.lproj":
	case "fr_CA.lproj":
	case "fr_CA":
	case "French":
		kTitle = "Temps économisé";		
		break;

	// Italian
	case "it.lproj":
	case "Italian":
		kTitle = "Tempo salvato";		
		break;

	// Spanish
	case "es.lproj":
	case "es_MX.lproj":
	case "es_MX":
	case "Spanish":
		kTitle = "Hora guardada";		
		break;

	// Japanese
	case "ja.lproj":
	case "Japanese":
		kTitle = "保存した日時";		
		kFont = isMacintosh ? "Osaka" : "MS UI Gothic";
		break;

	// Chinese (Simplified)
	case "Simplified%20Chinese":
		kTitle = "时间已保存";		
		kFont = isMacintosh ? "Osaka" : "宋体";
		break;

	// Chinese (Traditional)
	case "Traditional%20Chinese":
		kTitle = "已儲存時間";		
		kFont = isMacintosh ? "Osaka" : "新細明體";
		break;

	// Korean
	case "Korean":
		kTitle = "저장된 시간";		
		kFont = isMacintosh ? "AppleMyungjo" : "굴림";
		break;

	// Brazilian Portuguese
	case "pt.lproj":
	case "Brazilian%20Portuguese":
		kTitle="jfyã_Time Saved";
		break;

	// Dutch
	case "nl.lproj":
	case "Dutch":
		kTitle="jfy€_Time Saved";
		break;

	// Swedish
	case "sv.lproj":
	case "Swedish":
		kTitle="jfyå_Time Saved";
		break;

	//Czech
	case "cs.lproj":
	case "Czech":
		kTitle="Uložená hodnota času";
		break;

	//Polish
	case "pl.lproj":
	case "Polish":
		kTitle="Zapisany czas";
		break;

	// Russian
	case "ru.lproj":
	case "Russian":
		kTitle="Сэкономленное время";
		break;

	// Turkish
	case "tr.lproj":
	case "Turkish":
		kTitle="Kaydedildiği Saat";
		break;

	// English
	case "en.lproj":
	case "English":
	default:
		kTitle = "Time Saved";		
		break;
}

/*==========================================================================*/
/* Constants                                                                */
/*==========================================================================*/
var kFontSize = 12;
var kTextWidth = 200;//doesn't really matter - we are auto-sizing
var gEventStr = "onFwDocumentSave";	//Do NOT localize

/*==========================================================================*/
/* main switch                                                              */
/*==========================================================================*/
switch(smartShape.operation) {

	case "BeginDragInsert":
	case "InsertSmartShapeAt":
		var p = smartShape.currentMousePos;
		InsertSmartShapeAt(p.x, p.y);
		smartShape.elem.RegisterForEvent(gEventStr);
		break;

	case gEventStr:
		SetTimeStamp();
		break;
}

/*==========================================================================*/
/* functions                                                                */
/*==========================================================================*/
function GetDate() {
	var time = new Date()

            switch(lang)

            {

                        // Japanese

                        case "ja.lproj":

                        case "Japanese":

                                    return((1900 + time.getYear()) + "/" + (1 + time.getMonth()) + "/" + time.getDate());

                                    break;

                        case "en.lproj":

                        case "English":

                                    return((1 + time.getMonth()) + "/" + time.getDate() + "/" + (1900 + time.getYear()));

                                    break;

                        default:

                                    return((1900 + time.getYear()) + "-" + (1 + time.getMonth()) + "-" + time.getDate());

                                    break;

            }

}

function GetTime() {
	var time = new Date()
	var hour = time.getHours()
	var minute = time.getMinutes()
	var second = time.getSeconds()
	var temp = "" + ((hour > 12) ? hour - 12 : hour)
	if (hour == 0)
		temp = "12";
	temp += ((minute < 10) ? ":0" : ":") + minute
	temp += ((second < 10) ? ":0" : ":") + second
	temp += (hour >= 12) ? " PM" : " AM"
	return temp
} 

function InsertSmartShapeAt(x, y)
{
	smartShape.elem.elements[0] = new Text;
	smartShape.elem.elements[0].textRuns = { initialAttrs:{ alignment:"center", antiAliasSharpness:192, antiAliasStrength:64, baselineShift:0, bold:false, face:kFont, fillColor:"#000000", horizontalScale:1, italic:false, leading:1, leadingMode:"percentage", overSample:8, paragraphIndent:0, paragraphSpacingAfter:0, paragraphSpacingBefore:0, rangeKerning:0, size:kFontSize+"pt", underline:false }, textRuns:[ { changedAttrs:{  }, characters:" " } ] };
	smartShape.elem.elements[0].autoExpand = true;
	smartShape.elem.elements[0].orientation = "horizontal left to right";
	smartShape.elem.elements[0].rawLeft = x - kTextWidth / 2;
	smartShape.elem.elements[0].rawWidth = kTextWidth;
	smartShape.elem.elements[0].rawTop = y - kFontSize / 2;

	smartShape.elem.elements[1] = new Text;
	smartShape.elem.elements[1].textRuns = { initialAttrs:{ alignment:"center", antiAliasSharpness:192, antiAliasStrength:64, baselineShift:0, bold:false, face:kFont, fillColor:"#000000", horizontalScale:1, italic:false, leading:1, leadingMode:"percentage", overSample:8, paragraphIndent:0, paragraphSpacingAfter:0, paragraphSpacingBefore:0, rangeKerning:0, size:kFontSize+"pt", underline:false }, textRuns:[ { changedAttrs:{  }, characters:kTitle } ] };
	smartShape.elem.elements[1].autoExpand = true;
	smartShape.elem.elements[1].orientation = "horizontal left to right";
	smartShape.elem.elements[1].rawLeft = x - kTextWidth / 2;
	smartShape.elem.elements[1].rawWidth = kTextWidth;
	smartShape.elem.elements[1].rawTop = y - kFontSize * 3 / 2;
	
	SetTimeStamp();
}

function SetTimeStamp()
{
	// Make the string
	var stampStr = GetDate() + "\r" + GetTime();
	// extract the old attributes, so if they get changed, we don't overwrite them
	var oldAttrs = smartShape.elem.elements[0].textRuns.initialAttrs;
	// set the attributes and the string
	smartShape.elem.elements[0].textRuns = { initialAttrs:oldAttrs, textRuns:[ { changedAttrs:{  }, characters:stampStr } ] };
}
