var windowReference; 

window.onerror=function(){return true;	}

function openWin(sWin,s1,properties) {
  windowReference =window.open(sWin,s1,properties) 
  if (!windowReference.opener) windowReference.opener = self;
  windowReference.focus();
}

function openCollectionImages(sId,sTitle){
 w=600;
 h=530;
 MOOdalBox.open('viewtoyimages.php?collectionid='+sId,sTitle,w+" "+h);
}

function openBooksImages(sId,sTitle){
 w=600;
 h=530;
 MOOdalBox.open('viewbookimages.php?bookid='+sId,sTitle,w+" "+h);
}

function openCollectibleImages(sId,sTitle){
 w=600;
 h=530;
 MOOdalBox.open('viewcollectibleimages.php?id='+sId,sTitle,w+" "+h);
}
function zoomToy(sImagePath,iWidth,iHeight){
  iTop=(screen.height/2)-(iHeight/2)-70;
  iLeft=(screen.width/2)-(iWidth/2);

	openWin(sImagePath,'zoom','width='+iWidth+',height='+iHeight+',top='+iTop+',left='+iLeft+',scrollbars=yes,resizable=yes');
}

function trimString(sValue) {
         var temp = sValue;var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
         if (obj.test(temp)) { temp = temp.replace(obj, '$2');}
         var obj = / +/g;temp = temp.replace(obj, " ");
         //Remove line feed
         var obj = /\n+/g;temp = temp.replace(obj, " ");
         
         if (temp == " ") { temp = ""; }
         return temp;
};

function emailCheck(string1){
	var filter  = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(string1)) 
	      return true;
	else 
	     return false;
	     
};

var stripHTML = function(str){
  var matchTag = /<(?:.|\s)*?>/g;
  return str.replace(matchTag, "").replace(/^[\s(&nbsp;)]+/g,'').replace(/[\s(&nbsp;)]+$/g,'');
}
function postMyMessage(objForm){
	if(trimString($('txtFirstname').value)==''){
		alert("First name is required. Please enter a value in this field.");
		$('txtFirstname').select();
		return;
	}
	if(trimString($('txtLastname').value)==''){
		alert("Last name is required. Please enter a value in this field.");
		$('txtLastname').select();
		return;
	}
	
	if(trimString($('txtEmail').value)==''){
		alert("Email is required. Please enter a value in this field.");
		$('txtEmail').select();
		return;
	}
	
	if(!emailCheck(trimString($('txtEmail').value))){
		alert("Email format is invalid. Please enter a valid value in this field.");
		$('txtEmail').select();
		return;
	}
	
	if(trimString($('txtLocation').value)==''){
		alert("Location is required. Please enter a value in this field.");
		$('txtLocation').select();
		return;
	}
	
	if(trimString(stripHTML(document.getElementById('wysiwyg' + 'txtMessage').contentWindow.document.body.innerHTML))==''){
	  	alert("Message is required Please enter a value in this field.");	
	  	return false;
	}
	$('cmdSubmit').disabled=true;
	objAjax=new Ajax("postmymessage.php", {
			method: 'post',
			postBody:$(objForm).toQueryString()+"&message="+document.getElementById('wysiwyg' + 'txtMessage').contentWindow.document.body.innerHTML,
			onComplete: function(sResponse) {
				getMessages(0);
				alert("Your message has been posted.");
				MOOdalBox.close();
			},
			evalScripts: true
			}).request();
}

function getMessages(iPage){
	log=$('scrollingpanel').empty().addClass("ajax-loading");
	objAjax=new Ajax("getmessages.php", {
			method: 'post',
			postBody:"offset="+iPage,
			onComplete: function(sResponse) {
				 log.removeClass("ajax-loading");
				 log.setHTML(sResponse);
			},
			evalScripts: true
			}).request();
}
function getPhotoGallery(iPage){
    log=$('scrollingpanel').empty().addClass("ajax-loading");
	objAjax=new Ajax("getphotogallery.php", {
			method: 'post',
			postBody:"offset="+iPage,
			onComplete: function(sResponse) {
				 log.removeClass("ajax-loading");
				 log.setHTML(sResponse);
				
			},
			evalScripts: true
			}).request();
}
function openLeaveMessage(){
 w=600;
 h=500;
 MOOdalBox.open('leavemessage.php',"Leave Message",w+" "+h);
}