/*
   +----------------------------------------------------------------------+
   | misc.js                                                              |
   +----------------------------------------------------------------------+
   | Copyright (c) 2003-2005 Zander Limited (http://www.zander.net)       |
   +----------------------------------------------------------------------+
   | This source file has been licensed to:                               |
   | Tots Planet Limited (http://www.totsplanet.co.uk)                      |
   +----------------------------------------------------------------------+
   | Author: Alexander Goldstone <alex@zander.net>                        |
   +----------------------------------------------------------------------+
*/
function imagePopUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=440,left = 312,top = 164');");
}

function openContentWindow(url) {
  var width, height;
  width = 600;
  height = 500;
  if (screen.availWidth) {
    var posX, posY;
    height = screen.availHeight - 75;
    posX = Math.round((screen.availWidth - width) / 2);
    posY = Math.round((screen.availHeight - height) / 2);
    if(height > 665)
      height = 665;
    newWin = window.open(url, 'subwin','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0, copyhistory=0,width='+width+',height='+height+',left='+posX+',top='+posY+'');
  }
  else {
    newWin = window.open(url, 'subwin','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0, copyhistory=0,width='+width+',height='+height);
  }
}

function openGiftWrapWindow(url) {
	var width, height;
	width = 600;
	height = 500;
  if (screen.availWidth) {
    var posX, posY;
		height = screen.availHeight - 75;
    posX = Math.round((screen.availWidth - width) / 2);
    posY = Math.round((screen.availHeight - height) / 2);
		if(height > 665)
			height = 665;
    newWin = window.open(url, 'subwin','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0, copyhistory=0,width='+width+',height='+height+',left='+posX+',top='+posY+'');    
  }
  else {
    newWin = window.open(url, 'subwin','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0, copyhistory=0,width='+width+',height='+height);
  }
}

/* START GIFT WRAP TEXT AREA */

var _isPasted=false;
var _lastValue="";

function GetTextArea() {
	return document.forms["gift_options"].elements["gift_message"];
}

function TextareaKeyPress(event)
{
	//get pointer to text control:
	var objTextArea=GetTextArea();
	
	//get value:
	var strValue=objTextArea.value;
	
	var maxChars=200;
	
	//check if exceeded:
	if (strValue.length >= maxChars) {
		if (_isPasted) {
			//crop to maximum size:
			objTextArea.value = strValue.substr(0, maxChars);
		}
		if ((!event)||(!event.keyCode))
			return false;
		
		var arrAllowedChars=new Array(8, 9, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46);
		return InArray(arrAllowedChars, event.keyCode);
	}
	
	return true;
}

function TextareaKeyUp(event)
{

	//get pointer to text control:
	var objTextArea=GetTextArea();
	
	//get id of control:
	var strID=objTextArea.name+"_charsCount";
	
	//get pointer to text container:
	var objSpan=document.getElementById(strID);
	
	//abort if not defined:
	if (!objSpan)
		return false;

	//get value:
	var strValue=objTextArea.value;
	
	var maxChars=200;
	
	//check if exceeded:
	if (strValue.length >= maxChars) {
		if (_lastValue.length != strValue.length) {
			//crop to maximum size:
			objTextArea.value = strValue.substr(0, maxChars);
		}
		strValue=objTextArea.value;
	}
	
	//store last value:
	_lastValue = strValue;
	
	//set container text:
	objSpan.innerHTML = (maxChars-strValue.length)+" characters left";
}

function TextareaPaste(event)
{
	//initiate keypress and keyup events:
	_isPasted = true;
	var s1=setTimeout("TextareaKeyPress();", 100);
	var s2=setTimeout("TextareaKeyUp();", 500);
}

function InArray(arr, key) {
	for (var i=0; i<arr.length; i++) {
		if (arr[i] == key)
			return true;
	}
	return false;
}

/* END GIFT WRAP TEXT AREA */
