//###########################################
//# Title: 		custom.js          			#
//#-----------------------------------------#
//# Editors:	Mark Overy        	      	#
//# 			James Worsdall				#
//#-----------------------------------------#
//# Created:	01-06-2010					#
//# Modified:	18-01-2011					#
//#-----------------------------------------#
//# Version:	1.0							#
//###########################################

function aboutLoad(){
	tinyMCE.init
	({
		mode : "exact",
		skin : "o2k7",
		elements : "aboutEdit",
		theme : "advanced",
		theme_advanced_buttons1 : "cut,copy,paste,|,bold,italic,underline,|,fontsizeselect,|,bullist,numlist,|,forecolor,backcolor,|,undo,redo,",
		theme_advanced_buttons2 : ""
	});
}

function aboutShow(){
	if (document.getElementById('aboutDisplayBlock').offsetHeight > 199){
		document.getElementById('aboutShowMore').style.display = 'block';
	};
}

function aboutEdit(){
	changePanel('aboutSaveLink','aboutEditLink'); 
	changePanel('aboutEditBlock','aboutDisplayBlock'); 
	document.getElementById('aboutShowMore').style.display = 'none';
	document.getElementById('aboutShowLess').style.display = 'none';
	document.getElementById('aboutDisplayBlock').style.maxHeight = '99999px';	
}

function aboutSave(){
	ajaxFunctions('/scripts/asp/ajaxFunctions.asp?page=1','ajc=auu&auc=' + escape(tinyMCE.get('aboutEdit').getContent()));
	changePanel('aboutDisplayBlock','aboutEditBlock');
	changePanel('aboutEditLink','aboutSaveLink'); 
	document.getElementById('aboutDisplayBlock').innerHTML=tinyMCE.get('aboutEdit').getContent();
	document.getElementById('aboutShowMore').style.display = 'none';
	document.getElementById('aboutShowLess').style.display = 'none';

	if (document.getElementById('aboutDisplayBlock').offsetHeight > 200){
		document.getElementById('aboutShowLess').style.display = 'block';
		document.getElementById('aboutShowLess').style.visibility = 'visible';
	};
}

function aboutCancel(){
	changePanel('aboutDisplayBlock','aboutEditBlock'); 
	changePanel('aboutEditLink','aboutSaveLink');
	document.getElementById('aboutShowMore').style.display = 'none';
	document.getElementById('aboutShowLess').style.display = 'none';
	
	if (document.getElementById('aboutDisplayBlock').offsetHeight > 200){
		document.getElementById('aboutShowLess').style.display = 'block';
		document.getElementById('aboutShowLess').style.visibility = 'visible';
	};
}

function cellMouseOver(cell){

var textid = document.getElementById(cell + "T");
textid.style.color = "#D4DDD5";

var cellid = document.getElementById(cell);
cellid.bgColor = "#6A9A37";
cellid.style.cursor = "pointer";
cellid.style.cursor = "hand";

}

function checkAlbumInput(ob) {
  if(/[`¬!"£$%^&*()=+\[\]{};:'@#~,<.>?\/\\|]/gi.test(ob.value)) {
        alert("Invalid character in album name");
            ob.value = ob.value.substring(0,ob.value.length-1);
    }
}

function cellMouseOut(cell){

var textid = document.getElementById(cell + "T");
textid.style.color = "#6A9A37";

var cellid = document.getElementById(cell);
cellid.bgColor = "#D4DDD5";

}

function changeImg(imgElement,stopSrc){
	document[imgElement].src = stopSrc;
}

function swapImg(imgElement,startSrc,stopSrc){
var imgElementStr = document[imgElement].src;

if (imgElementStr.match(startSrc))
	{
		document[imgElement].src = stopSrc;
	}else{
		document[imgElement].src = startSrc;
	}
}

function commentValidation(form,destination,video){
	document.getElementById(destination + 'CommentsError').innerHTML=''
	document.getElementById(destination + 'CommentsError').style.display='none'
	if (form.addComment.value == form.addComment.defaultValue){
		document.getElementById(destination + 'CommentsError').innerHTML='you must enter a comment'
		document.getElementById(destination + 'CommentsError').style.display='block'
		return false;
	}else{
		if (video == 'video'){
			var str, videoSource, idFound
			idFound = 0;
			str=document.getElementById(destination + 'AddVideo').value
			// check video specified is on youtube
			if (/youtube/gi.test(str)){
				so = str.split("?");
				// retrieve video ID if its a normal youtube video
				if (so.length > 1){
					st = so[1].split("&");
					for (i=0;i<st.length;i++) {
						ft = st[i].split("=");
						if (ft[0] == "v") {
							videoSource = ft[1];
							idFound = 1;
						}
					}
					//retrieve video ID if its a weird channel video
					if (idFound==0) {
						st = so[1].split("/");
						videoSource = st[3];
					}
				}else{
				// retrieve video ID if its a user channel video
					st = so[0].split("/");
					for (i=0;i<st.length;i++){
						if (st[i] == "user"){
							videoSource = st[i+4]
						}
					}
				}
				ajaxFunctions('/scripts/asp/dataPutCommentNew.asp?page=1','commRecipOwnerID=' + form.commRecipOwnerID.value + 
																		'&commRecipID=' + form.commRecipID.value +
																		'&commRecipType=' + form.commRecipType.value +
																		'&commAuthorOwnerID=' + form.commAuthorOwnerID.value +
																		'&commAuthorID=' + form.commAuthorID.value +
																		'&commAuthorType=' + form.commAuthorType.value +
																		'&addComment=' + escape(form.addComment.value) +
																		'&videoSource=' + videoSource);
			}else{
				document.getElementById(destination + 'CommentsError').innerHTML='it must be a video hosted by youtube'
				document.getElementById(destination + 'CommentsError').style.display='block'
				return false;
			}
		}else{
			ajaxFunctions('/scripts/asp/dataPutCommentNew.asp?page=1','commRecipOwnerID=' + form.commRecipOwnerID.value + 
																	'&commRecipID=' + form.commRecipID.value +
																	'&commRecipType=' + form.commRecipType.value +
																	'&commAuthorOwnerID=' + form.commAuthorOwnerID.value +
																	'&commAuthorID=' + form.commAuthorID.value +
																	'&commAuthorType=' + form.commAuthorType.value +
																	'&addComment=' + escape(form.addComment.value) +
																	'&videoSource=none');
		}
	} 
	switch(destination)
	{
		case 'commentTab':
			ajaxLoad('/scripts/asp/ajaxComments.asp?page=1&comm=C','tPanelContent');
			break;
		case 'homeTab':
			ajaxLoad('/scripts/asp/ajaxCommentsHome.asp?page=1&comm=M','CommentsHomeContent');
			break;
	}
} 

function replyValidation(form,destination,threadID){ 
	if (form.comment.value == form.comment.defaultValue){
		return false;
	}else{
		ajaxFunctions('/scripts/asp/dataPutCommentReply.asp?page=1','replyCommentID=' + form.replyCommentID.value + 
																'&replyRecipOwnerID=' + form.replyRecipOwnerID.value +
																'&replyRecipID=' + form.replyRecipID.value +
																'&replyRecipType=' + form.replyRecipType.value +
																'&replyAuthorOwnerID=' + form.replyAuthorOwnerID.value +
																'&replyAuthorID=' + form.replyAuthorID.value +
																'&replyAuthorType=' + form.replyAuthorType.value +
																'&comment=' + escape(form.comment.value));
	} 
	switch(destination)
	{
		case 'homeTab':
			ajaxLoad('/scripts/asp/ajaxCommentsHomeThread.asp?page=1&tid=' + threadID,'thread' + threadID);
			break;
		case 'commentTab':
			ajaxLoad('/scripts/asp/ajaxCommentsTabThread.asp?page=1&tid=' + threadID,'tabThread' + threadID);
			break;
		case 'galleryPage':
			ajaxLoad('/scripts/asp/ajaxCommentsGalleryThread.asp?page=1&tid=' + threadID,'commentThreadGallery');
			break;
	}
} 

//prevent menus being clicked on transition
var menuMoving;
menuMoving = false;

// toggle reply display
function messageReplyToggle(messNum){
if (menuMoving == false){
menuMoving = true;
var ElementId = document.getElementById('messageReply' + messNum);
if (ElementId.style.display!='none')
	{
		Effect.SlideUp('messageReply' + messNum); 
		Effect.SlideDown('messageBar' + messNum);
		setTimeout('replyBox' + messNum + '.value = replyBox' + messNum + '.defaultValue; menuMoving = false; resizeArea(replyBox' + messNum + ');',1000);
	}else{
		Effect.SlideUp('messageBar'+ messNum);
		Effect.SlideDown('messageReply'+ messNum);
		setTimeout('menuMoving = false;', 1000);
	}
}
}

// toggle message display
// if reply div is visible delay retraction slide of main message div
function messageMainToggle(messNum){
if (menuMoving == false){

var ElementId = document.getElementById('messageReply' + messNum);
if (ElementId.style.display!='none')
	{	
		messageReplyToggle(messNum)
		setTimeout("Effect.toggle('messageBody" + messNum + "', 'slide');", 1000);
	}else{
		Effect.toggle('messageBody' + messNum, 'slide');
		menuMoving = false;
	}
	
swapTitle('messageTitle' + messNum,'click to open message','click to close message'); 
changeImg('mailIco' + messNum,'images/interface/mailreadicon.png'); 
//swapImgOnDiv('messageBody' + messNum,'expandIco' + messNum,'images/interface/expand2Icon.png','images/interface/retractIcon.png');
}
}

// if div is not visible startSrc else display stopSrc
function swapImgOnDiv(divElement,imgElement,startSrc,stopSrc){

var divElementId = document.getElementById(divElement);
if (divElementId.style.display=="none")
	{
		document[imgElement].src = stopSrc;
	}else{
		document[imgElement].src = startSrc;
	}
}


function swapTitle(element,titleOne,titleTwo){
var elementId = document.getElementById(element);
	if (elementId.title == titleOne)
	{
		elementId.title = titleTwo;
	}else{
		elementId.title = titleOne;
	}
}

function busMouseOver(cell){

var cellid = document.getElementById(cell);
cellid.style.background = "#FFFFFF";
cellid.style.height = "88px";
cellid.style.backgroundImage = "url(images/interface/nonBack.png)";


var cellid2 = document.getElementById("d" + cell);
cellid2.style.display = "block";

}

function busMouseOut(cell){

var cellid = document.getElementById(cell);
cellid.style.background = "none";
cellid.style.height = "37px";

var cellid2 = document.getElementById("d" + cell);
cellid2.style.display = "none";

}

function panelMouseOver(cell){

var cellid = document.getElementById(cell);
cellid.style.cursor = "pointer";
cellid.style.cursor = "hand";

}

function stabClick(tab,tab2){

var tabid = document.getElementById(tab);
tabid.className='stabOn';

var tabidb = document.getElementById(tab + 'b');
tabidb.style.display = "block";

var tabid2 = document.getElementById(tab2);
tabid2.className='stabOff';

var tabidb2 = document.getElementById(tab2 + 'b');
tabidb2.style.display = "none";
}


function manageSlides(slideElement1,slideElement2,slideElement3,slideElement4){

var slideElementId = document.getElementById(slideElement2);
if (slideElementId.style.display!="none"){Effect.SlideUp(slideElement2);}
var slideElementId = document.getElementById(slideElement3);
if (slideElementId.style.display!="none"){Effect.SlideUp(slideElement3);}
var slideElementId = document.getElementById(slideElement4);
if (slideElementId.style.display!="none"){Effect.SlideUp(slideElement4);}	
var slideElementId = document.getElementById(slideElement1);
if (slideElementId.style.display=="none"){Effect.SlideDown(slideElement1);}	
	
}

function changePanel(Element1,Element2){


var Element1Id = document.getElementById(Element1);
var Element2Id = document.getElementById(Element2);

if (Element1Id.style.display=="none"){
	Element2Id.style.display = "none";
	Element2Id.style.visibility = "hidden";
	Element1Id.style.display = "block";
	Element1Id.style.visibility = "visible";
	}
}

function submitCSearch(){
	if (document.getElementById('searchPanel').style.display == 'none'){
		ajaxPost('/scripts/asp/ajaxControls.asp?page=1','searchPanel','ajc=sc&ct=' + escape(returnCheckedOption('reportType',4)) + '&st=' + escape(document.getElementById('messageSearch').value)); 
		showPanel('searchPanel');
	};
}


function hideshowPanel(Element1){

var Element1Id = document.getElementById(Element1);

if (Element1Id.style.display=="none"){
	Element1Id.style.display = "block";
	Element1Id.style.visibility = "visible";
	}else{
	Element1Id.style.display = "none";
	Element1Id.style.visibility = "hidden";
	}
}

function hidePanel(Element1){

var Element1Id = document.getElementById(Element1);

	Element1Id.style.display = "none";
	Element1Id.style.visibility = "hidden";

}


function showPanel(Element1){

var Element1Id = document.getElementById(Element1);

	Element1Id.style.display = "block";
	Element1Id.style.visibility = "visible";
	
}


var menuOn = 0;
function hideMenu(){

	menuOn = 0;
	setTimeout("removeMenu('dropDownPanel');",300);
}

function removeMenu(Element1){

if (menuOn == 0){
	var Element1Id = document.getElementById(Element1);
	Element1Id.style.display = "none";
	Element1Id.style.visibility = "hidden";}
}

function showMenu(Element1){

var Element1Id = document.getElementById(Element1);
	menuOn = 1;
	Element1Id.style.display = "block";
	Element1Id.style.visibility = "visible";

}


function expandAboutPanel(){


var Element1Id = document.getElementById('aboutContentM');
var Element2Id = document.getElementById('aboutContentL');

if (Element1Id.style.display=="none"){
	Element2Id.style.display = "none";
	Element2Id.style.visibility = "hidden";
	Element1Id.style.display = "block";
	Element1Id.style.visibility = "visible";
	}else{
	Element1Id.style.display = "none";
	Element1Id.style.visibility = "hidden";
	Element2Id.style.display = "block";
	Element2Id.style.visibility = "visible";
}
}


function swapLittlePanel(panHeight){
	if (document.getElementById('ilPanel').style.height != "43px"){
		document.getElementById('ilPanel').style.height = "43px";
		document.getElementById('cbaPanel').className = 'lpElement';
	}else{
		document.getElementById('ilPanel').style.height = panHeight + "px";
		document.getElementById('cbaPanel').className = 'lpSElement';
	}
	//var ElementId = document.getElementById('ilPanel');
	//alert(numpets + " pets " + ElementId.style.height);
}

function moreCommentReplies(startLimit,divID,comID,threadLength,bpRpc){
	ajaxRequest('/scripts/asp/ajaxCommentsMore.asp?replies=' + startLimit + '&comID=' + comID + '&threadLength=' + threadLength + '&bpRpc=' + bpRpc,divID);
}

function checkComment(replyForm){
var element = document.getElementById(replyForm);
	element.replyBody.value= (encodeURIComponent(element.comment.value));
}

function textLineBreaks(element){
var bodyStr=document.getElementById(element).value;
bodyStr = bodyStr.replace(/\n/g, '!br!');
return bodyStr;
}

function ajaxRequest(script,destination,sync)
{
if (sync == null){sync = true;}
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp1=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp1=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp1.onreadystatechange=function()
  {
  if (xmlhttp1.readyState==4 && xmlhttp1.status==200)
    {
    document.getElementById(destination).innerHTML=xmlhttp1.responseText;
    }
  }
 if (navigator.userAgent.indexOf("Firefox")!=-1){
	xmlhttp1.open("GET",script + '&ms=' + new Date().getTime(),true);
}else{
	xmlhttp1.open("GET",script + '&ms=' + new Date().getTime(),false);
}
xmlhttp1.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
xmlhttp1.send();
}

function ajaxRequest2(script,destination,sync)
{
if (sync == null){sync = true;}
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp2=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp2.onreadystatechange=function()
  {
  if (xmlhttp2.readyState==4 && xmlhttp2.status==200)
    {
    document.getElementById(destination).innerHTML=xmlhttp2.responseText;
    }
  }
 if (navigator.userAgent.indexOf("Firefox")!=-1){
	xmlhttp2.open("GET",script + '&ms=' + new Date().getTime(),true);
}else{
	xmlhttp2.open("GET",script + '&ms=' + new Date().getTime(),false);
}
xmlhttp2.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
xmlhttp2.send();
}

function ajaxRequest3(script,destination,sync)
{
if (sync == null){sync = true;}
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp7=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp7=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp7.onreadystatechange=function()
  {
  if (xmlhttp7.readyState==4 && xmlhttp7.status==200)
    {
    document.getElementById(destination).innerHTML=xmlhttp7.responseText;
    }
  }
 if (navigator.userAgent.indexOf("Firefox")!=-1){
	xmlhttp7.open("GET",script + '&ms=' + new Date().getTime(),true);
}else{
	xmlhttp7.open("GET",script + '&ms=' + new Date().getTime(),false);
}
xmlhttp7.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
xmlhttp7.send();
}

function ajaxRequest4(script,destination,sync)
{
if (sync == null){sync = true;}
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp8=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp8=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp8.onreadystatechange=function()
  {
  if (xmlhttp8.readyState==4 && xmlhttp8.status==200)
    {
    document.getElementById(destination).innerHTML=xmlhttp8.responseText;
    }
  }
 if (navigator.userAgent.indexOf("Firefox")!=-1){
	xmlhttp8.open("GET",script + '&ms=' + new Date().getTime(),true);
}else{
	xmlhttp8.open("GET",script + '&ms=' + new Date().getTime(),false);
}
xmlhttp8.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
xmlhttp8.send();
}


function ajaxPost(script,destination,varStrs)
{

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp3=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp3=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp3.onreadystatechange=function()
  {
  if (xmlhttp3.readyState==4 && xmlhttp3.status==200)
    {
    document.getElementById(destination).innerHTML=xmlhttp3.responseText;
    }
  }
if (navigator.userAgent.indexOf("Firefox")!=-1){
	xmlhttp3.open("POST",script + '&ms=' + new Date().getTime(),true);
}else{
	xmlhttp3.open("POST",script + '&ms=' + new Date().getTime(),false);
}

xmlhttp3.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp3.send(varStrs);
}

function ajaxPost2(script,destination,varStrs)
{

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp6=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp6=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp6.onreadystatechange=function()
  {
  if (xmlhttp6.readyState==4 && xmlhttp6.status==200)
    {
    document.getElementById(destination).innerHTML=xmlhttp6.responseText;
    }
  }
if (navigator.userAgent.indexOf("Firefox")!=-1){
	xmlhttp6.open("POST",script + '&ms=' + new Date().getTime(),true);
}else{
	xmlhttp6.open("POST",script + '&ms=' + new Date().getTime(),false);
}

xmlhttp6.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp6.send(varStrs);
}


function ajaxFunctions(script,varStr)
{

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp4=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp4=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp4.onreadystatechange=function()
  {
  if (xmlhttp4.readyState==4 && xmlhttp4.status==200)
    {
    }
  }
 if (navigator.userAgent.indexOf("Firefox")!=-1){
	xmlhttp4.open("POST",script + '&ms=' + new Date().getTime(),true);
}else{
	xmlhttp4.open("POST",script + '&ms=' + new Date().getTime(),false);
}
xmlhttp4.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp4.send(varStr);
}

function ajaxFunctionsSync(script,varStr)
{

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp5=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp5=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp5.onreadystatechange=function()
  {
  if (xmlhttp5.readyState==4 && xmlhttp5.status==200)
    {
    }
  }
xmlhttp5.open("POST",script + '&ms=' + new Date().getTime(),true);
xmlhttp5.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp5.send(varStr);
}

function ajaxLoad(script,destination){
	document.getElementById(destination).innerHTML='<table height="100%" align="center"><tr><td><img src="images/interface/loading.gif" /><br /><br /></td></tr></table>';
	ajaxRequest(script,destination);
}
function ajaxLoad2(script,destination){
	document.getElementById(destination).innerHTML='<table height="100%" align="center"><tr><td><img src="images/interface/loading.gif" /><br /><br /></td></tr></table>';
	ajaxRequest2(script,destination);
}
function ajaxLoad3(script,destination){
	document.getElementById(destination).innerHTML='<table height="100%" align="center"><tr><td><img src="images/interface/loading.gif" /><br /><br /></td></tr></table>';
	ajaxRequest3(script,destination);
}


function updateBrowseEntity(strVar){
ajaxPost('/scripts/asp/ajaxLittlePanel.asp?page=1','lPanel', strVar); //sends changes
location.reload(true);
}

function updateEntityCounts(){
ajaxLoad3('/scripts/asp/ajaxMenuPanel.asp?page=1','menuPanel');
}

function updateBrowseElements(timeOut){
if (timeOut == null){timeout = 0;}
//setTimeout("ajaxLoad('/scripts/asp/ajaxProfilePanel.asp?page=1','profilePanel'); profileHash();", timeOut); //used to refesh whole profile panel
//location.reload(true); //solution to above problem
//setTimeout("ajaxPost('/scripts/asp/ajaxControls.asp?page=1','mainBlockTitle','ajc=ctt');", timeOut);
location.reload(true);
}


function updateBusinessElements(timeOut){
if (timeOut == null){timeout = 0;}
//setTimeout("ajaxLoad('/scripts/asp/conBusinessFeatures.asp?Page=1','busFeatures'); profileHash();", timeOut);
//setTimeout("ajaxPost('/scripts/asp/ajaxControls.asp?page=1','mainBlockTitle','ajc=ctt');", timeOut);
location.reload(true);
}

//update page when adding pet on big panel or home tab
function updatePetElements(){
var hashStr = window.location.hash
//alert(hashStr.length);
if (window.location.hash != ""){

	if (hashStr.substring(1,2) == "b"){
		ajaxRequest('/scripts/asp/ajaxPets.asp?page=1&pt=A','bPanelContent')
	}
}
ajaxRequest2('/scripts/asp/ajaxPetSummary.asp?page=1','petSummary')
ajaxRequest3('/scripts/asp/ajaxPetSummaryMore.asp?page=1','petSummaryMore')
ajaxRequest4('/scripts/asp/ajaxLittlePanel.asp?page=1','lPanel')

}

//register clicks on ad banners
function adClick(advert){
ajaxFunctions('/scripts/asp/ajaxFunctions.asp?page=1','ajc=ac&ad='+advert);
}

//register business search
function recordSearch(searchType){
switch(searchType)
{
	case 'p':
		ajaxFunctions('/scripts/asp/ajaxFunctions.asp?page=1','ajc=rs&ty=p&ca=' + escape(document.getElementById('category').value) 
																				+ '&di=' + escape(document.getElementById('distance').value) 
																				+ '&po=' + escape(document.getElementById('pc').value) 
																				+ '&cr=0&cy=0&to=0');
		break;
	case 'l':
		ajaxFunctions('/scripts/asp/ajaxFunctions.asp?page=1','ajc=rs&ty=l&ca=' + document.getElementById('scategory').value 
																				+ '&di=0&po=0&cr=' + escape(document.getElementById('profileCountry').value) 
																				+ '&cy=' + escape(document.getElementById('ajaxLocality').value) 
																				+ '&to=' + escape(document.getElementById('ajaxTown').value));
		break;
}
}

//form field data validation
function validateField(field,destination,text){
	
	if (document.getElementById(field).value==null||document.getElementById(field).value==""||document.getElementById(field).value=="0")
		{
			document.getElementById(destination).innerHTML='<div class="errorSubmitForm" style="margin-left: 30px; margin-right: 30px;">' + text + '</div>';document.getElementById(field + 'Err').innerHTML='*';return false;
		}
		else
		{
			document.getElementById(field + 'Err').innerHTML='';return true;
		}
	
}

//valid email address check
function validateEmail(email,destination){
var apos=document.getElementById(email).value.indexOf("@");
var dotpos=document.getElementById(email).value.lastIndexOf(".");
if (apos<1||dotpos-apos<2){
document.getElementById(destination).innerHTML='<div class="errorSubmitForm" style="margin-left: 30px; margin-right: 30px;">You must supply a valid email address</div>';
document.getElementById(email + 'Err').innerHTML='*';
return false;}
else{return true;}
}

//matching email addresses form validation
function validateEmailMatch(emaila,emailb,destination){
if (document.getElementById(emaila).value == document.getElementById(emailb).value){
document.getElementById(emaila + 'Err').innerHTML='';
document.getElementById(emailb + 'Err').innerHTML='';
return true;
}
else{
document.getElementById(destination).innerHTML='<div class="errorSubmitForm" style="margin-left: 30px; margin-right: 30px;">The email addresses supplied do not match</div>';
document.getElementById(emaila + 'Err').innerHTML='*';
document.getElementById(emailb + 'Err').innerHTML='*';
return false;
}
}

//matching password form validation
function validatePasswordMatch(passa,passb,destination){
if (document.getElementById(passa).value == document.getElementById(passb).value){
document.getElementById(passa + 'Err').innerHTML='';
document.getElementById(passb + 'Err').innerHTML='';
return true;
}else{
document.getElementById(destination).innerHTML='<div class="errorSubmitForm" style="margin-left: 30px; margin-right: 30px;">The passwords supplied do not match</div>';
document.getElementById(passa + 'Err').innerHTML='*';
document.getElementById(passb + 'Err').innerHTML='*';
return false;
}
}

//password length validation
function validatePasswordLength(pass,destination,text){
if (document.getElementById(pass).value.length < 8){
document.getElementById(destination).innerHTML='<div class="errorSubmitForm" style="margin-left: 30px; margin-right: 30px;">' + text + '</div>';
document.getElementById(pass + 'Err').innerHTML='*';
return false;
}
}

//password content check
function validatePasswordContent(pass,destination,text){
if (document.getElementById(pass).value == 'password'||document.getElementById(pass).value == 'Password'){
document.getElementById(destination).innerHTML='<div class="errorSubmitForm" style="margin-left: 30px; margin-right: 30px;">' + text + '</div>';
document.getElementById(pass + 'Err').innerHTML='*';
return false;
}
}

//update form validation
function updateValidation(valA,valB){
if (valB==false){return false;}
else{return valA;}
}

//add group form data validation
function validateAddGroupForm(){
var validateForm=true;
var val;
val=validateField('addGroupName','addGroupError','You must supply a name for your group');
validateForm=updateValidation(validateForm,val);
return validateForm;
}

//add pet form data validation
function validateAddPetForm(){
var validateForm=true;
var val;
val=validateField('addPetCategory','addPetError','You must supply a category for your pet');
validateForm=updateValidation(validateForm,val);
val=validateField('addPetGender','addPetError','You must supply a gender for your pet');
validateForm=updateValidation(validateForm,val);
val=validateField('addPetName','addPetError','You must supply a name for your pet');
validateForm=updateValidation(validateForm,val);
return validateForm;
}

//user signup form data validation
function validateUserSignupForm(){
var validateForm=true;
var val;
val=validateField('addUserTerms','signupError','You must agree to the terms of use');
validateForm=updateValidation(validateForm,val);
val=validateField('addUserTagline','signupError','Help others learn more about you by supplying a tagline');
validateForm=updateValidation(validateForm,val);
val=validateField('addUserAnswer','signupError','You must supply an answer to your security question');
validateForm=updateValidation(validateForm,val);
val=validateField('addUserQuestion','signupError','You must supply a security question');
validateForm=updateValidation(validateForm,val);
val=validatePasswordMatch('addUserPassword','addUserPassword2','signupError');
validateForm=updateValidation(validateForm,val);
val=validatePasswordContent('addUserPassword','signupError','"password" as your password? Are you kidding me?');
validateForm=updateValidation(validateForm,val);
val=validatePasswordLength('addUserPassword','signupError','Your password must be at least eight characters long');
validateForm=updateValidation(validateForm,val);
val=validateEmailMatch('addUserEmail','addUserEmail2','signupError');
validateForm=updateValidation(validateForm,val);
val=validateEmail('addUserEmail','signupError');
validateForm=updateValidation(validateForm,val);
val=validateField('addUserDOBYear','signupError','You must supply a date of birth');
validateForm=updateValidation(validateForm,val);
val=validateField('addUserDOBMonth','signupError','You must supply a date of birth');
validateForm=updateValidation(validateForm,val);
val=validateField('addUserDOBDay','signupError','You must supply a date of birth');
validateForm=updateValidation(validateForm,val);
val=validateField('addUserGender','signupError','You must supply a gender');
validateForm=updateValidation(validateForm,val);
val=validateField('addUserLastName','signupError','You must supply a last name');
validateForm=updateValidation(validateForm,val);
val=validateField('addUserFirstName','signupError','You must supply a first name');
validateForm=updateValidation(validateForm,val);
return validateForm;
}

//messagebox to show value of element
function showValue(valueElement){

var valueElementId = document.getElementById(valueElement);
alert('Value equals: ' + valueElementId.style.display);	
}

//profile tab selection
function tabClick(tab,loopNum){

var i=1;
for (i=1; i<=loopNum; i++)
	{
		var tabid = document.getElementById('tab' + i);
		tabid.className='tabOff';

		var tabidb = document.getElementById('tab' + i + 'b');
		tabidb.style.display = "none";
		tabidb.style.visibility = "hidden";
	}

var tabid = document.getElementById(tab);
tabid.className='tabOn';


var tabidb = document.getElementById(tab + 'b');
tabidb.style.display = "block";
tabidb.style.visibility = "visible";
}

//profile tab selection
function searchClick(selected){

document.getElementById('spets').className='searchElement';
document.getElementById('speople').className='searchElement';
document.getElementById('sgroups').className='searchElement';
document.getElementById('sbusinesses').className='searchElement';

var selectedId = document.getElementById('s' + selected);
selectedId.className='searchSElement';
}

function profileHash(strVar){
var hashStr = window.location.hash;

if (window.location.hash != ""){
	if (hashStr.substring(1,2) == "t"){
		profileTabClick(hashStr.substring(1,5),4);
		setupTabPanel(hashStr.substring(1),strVar);
	}
	if (hashStr.substring(1,2) == "b"){
		setupBigPanel(hashStr.substring(1));
		changePanel('bigPanel','tabPanel');
		
	}
}
}


function searchHash(strVar){
var hashStr = window.location.hash;

	if (hashStr.substring(1,2) == "b"){
		setupSearchPanel(hashStr.substring(1));
		showPanel('searchPanel');
		
	}else{
		switch(queryString('cat'))
		{
			case 'pets':
				setupSearchPanel('pets');
				showPanel('searchPanel');
			break;
			case 'people':
				setupSearchPanel('people');
				showPanel('searchPanel');
			break;
			case 'groups':
				setupSearchPanel('groups');
				showPanel('searchPanel');
			break;
			case 'businesses':
				setupSearchPanel('businesses');
				showPanel('searchPanel');
			break;
			default:
				setupSearchPanel('bp10');
				showPanel('searchPanel');
		}
	}
}

function clearPageCache(){
ajaxFunctionsSync('/scripts/asp/ajaxFunctions.asp?page=1','ajc=cpc');
}

function changeHash(hashChar){
var hashStr = window.location.hash;

window.location.hash = hashStr.substring(1,5) + hashChar;
}

//profile tab selection
function profileTabClick(tab,loopNum){
var hashStr = window.location.hash;

if (hashStr.substring(1,5) != tab){
	window.location.hash = tab;
}

//profile tab selection
function profilePreviousSetTab(tab){
var hashStr = window.location.hash;

previousTab = hashStr.substring(1,5);
}


//reset all graphics
var i=1;
for (i=1; i<=loopNum; i++)
	{
		var tabid = document.getElementById('tab' + i + 'a');
		tabid.className='tabOff';
	}
	//tab div
	if (tab == 'tab1'){
		var tab1db = document.getElementById('tab1b');
		tab1db.style.display = "block";
		tab1db.style.visibility = "visible";
		var tab2db = document.getElementById('tab2b');
		tab2db.style.display = "none";
		tab2db.style.visibility = "hidden";
	}else{
		var tab2db = document.getElementById('tab2b');
		tab2db.style.display = "block";
		tab2db.style.visibility = "visible";
		var tab1db = document.getElementById('tab1b');
		tab1db.style.display = "none";
		tab1db.style.visibility = "hidden";
	}
//tab graphic	
var tabid = document.getElementById(tab + 'a');
tabid.className='tabOn';

}

//change elements swap elements css class 
function swapCSS(con,cssName1,cssName2){

var conid = document.getElementById(con);

if (conid.className==cssName1)
	{
		conid.className=cssName2;
	}
	else
	{
		conid.className=cssName1;
	}
}

function actionCSS(con,cssName){

var conid = document.getElementById(con);

conid.className=cssName;
}


function resizeArea(t) {
a = t.value.split('\n');
b=1;
for (x=0;x < a.length; x++) { if (a[x].length >= t.cols) b+= Math.floor(a[x].length/t.cols);
}
b+= a.length;
if (b != t.rows) t.rows = b;
}


function changeText(element,txt){
document.getElementById(element).firstChild.nodeValue=txt;
}

function changeHTML(element,txt){
document.getElementById(element).innerHTML=txt;
}

function writeTitle(){
document.write(document.title);
}

function changeTitle( txt ){
document.title = txt;
}

function drawLine(){

	document.write("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");
	document.write("<tr height='6'><td></td></tr>");
	document.write("<tr height='2'><td><img height='2' width='100%' src='images/interface/lineBg.gif' /><td></tr>");
	document.write("<tr height='6'><td></td></tr>");
	document.write("</table>");
}


function drawSmlLine(){

	document.write("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");
	document.write("<tr height='1'><td></td></tr>");
	document.write("<tr height='2'><td><img height='2' width='100%' src='images/interface/lineBg.gif' /><td></tr>");
	document.write("<tr height='1'><td></td></tr>");
	document.write("</table>");
}

function y2k(number){ 
return (number < 1000) ? number + 1900 : number; 
}

function showCopyright(){
	var today = new Date();
	var year = y2k(today.getYear());
	document.write('Copyright &copy; '+ year +' petCompare&#174;. All Rights Reserved');
}

function returnCheckedOption(optionGroupName,numOptions){

	var i=1;
	for (i=1; i<=numOptions; i++)
		{
			if (document.getElementById(optionGroupName + i).checked == true){
				return document.getElementById(optionGroupName + i).value;
				break;
			}
		}
}

function returnTickedStr(optionGroupName,numOptions){
	var tempStr = "";
	var i=0;
	for (i=0; i<=numOptions; i++)
		{
			if (document.getElementById(optionGroupName + i).checked == true){
				tempStr = tempStr + "1";
			}else{
				tempStr = tempStr + "0";
			}
		}
return tempStr;
}

function returnTickedStars(optionGroupName,numOptions,destination){
	var tempNum = 0;
	var totalNum = (numOptions + 1) /2;
	var tempStr = "";
	var i=0;
	for (i=0; i<=numOptions; i++)
		{
			if (document.getElementById(optionGroupName + i).checked == true){
				tempNum = tempNum + 0.5;
			}
		}
	totalNum = totalNum - tempNum;
	tempStr = tempStr + "<table><tr>";
	while (tempNum > 0)
	{
		if (tempNum != 0.5){
			tempStr = tempStr + "<td><img src='images/interface/starSml.png' /></td>";
		}else{
			tempStr = tempStr + "<td><img src='images/interface/starSmlHalf.png' /></td>";
		}
	tempNum = tempNum - 1;
	}
	while (totalNum > 0.5)
	{
			tempStr = tempStr + "<td><img src='images/interface/starSmloff.png' /></td>";
			totalNum = totalNum - 1;
	}							
	tempStr = tempStr + "</tr></table>";
	document.getElementById(destination).innerHTML=tempStr;
}

function truncate(inputStr,trucateAt){
	var tempStr = inputStr;
	if (inputStr.length >= trucateAt){
		tempStr = trim(inputStr.substring(0,trucateAt)) + "..."
	}
	return tempStr;
}

function trim(s)
{
	var l=0; var r=s.length -1;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	while(r > l && s[r] == ' ')
	{	r-=1;	}
	return s.substring(l, r+1);
}

function navCache(uid,type,page){
ajaxFunctionsSync('/scripts/asp/ajaxEntityUpdate.asp?page=1',type + 'id=' + uid + '&cp=' + escape(page));
}

function queryString(varStr) {
hu = window.location.search.substring(1);
gy = hu.split("&");
for (i=0;i<gy.length;i++) {
ft = gy[i].split("=");
if (ft[0] == varStr) {
return ft[1];
}
}
}

function pageReload(){
location.reload(true);
}

function joinRedirect(strVar){
window.location.assign('page.asp?page=pview&uid=' + strVar);
}
