
function SwapIMG(imageName, image, imagePath)
{
	if (image.src == '')
	{
		image.src = imagePath;
	}
	document.images[imageName].src = image.src;
}

function setChoice(pServiceTypeID)
{
	document.getElementById('doctorsoption').className='doctors';
	document.getElementById('pharmaciesoption').className='pharmacies';
	document.getElementById('dentistsoption').className='dentists';
	document.getElementById('opticiansoption').className='opticians';	

	switch (pServiceTypeID)
	{
		case 1:
			document.getElementById('doctorsoption').className='doctorson';
			break;		
		case 2:
			document.getElementById('pharmaciesoption').className='pharmacieson';
			break;
		case 3:
			document.getElementById('dentistsoption').className='dentistson';
			break;
		case 4:
			document.getElementById('opticiansoption').className='opticianson';	
			break;			
	}
	
	document.getElementById('ServiceTypeID').value = pServiceTypeID;	
}

function winPop(pageToLoad, winName, width, height, center, scroll, control)
{
    xposition=0; yposition=0;
    if ((parseInt(navigator.appVersion) >= 4 ) && (center))
    {
        xposition = (screen.width - width) / 2;
        yposition = (screen.height - height) / 2;
    }
    
    args = "width=" + width + ","
    + "height=" + height + ","
    + "location=0,"
    + "menubar=1,"
    + "resizable=" + control + ","
    + "scrollbars="+scroll+", "
    + "status=1,"
    + "titlebar=1,"
    + "toolbar=1,"
    + "hotkeys=0,"
    + "screenx=" + xposition + ","  //NN Only
    + "screeny=" + yposition + ","  //NN Only
    + "left=" + xposition + ","     //IE Only
    + "top=" + yposition;           //IE Only

    window.open(pageToLoad,winName,args );
}

function winPopFull(pageToLoad, winName, width, height, center, scroll, control)
{
    xposition=0; yposition=0;
    if ((parseInt(navigator.appVersion) >= 4 ) && (center))
    {
        xposition = (screen.width - width) / 2;
        yposition = (screen.height - height) / 2;
    }
    
    args = "width=" + width + ","
    + "height=" + height + ","
    + "location=1,"
    + "menubar=1,"
    + "resizable=" + control + ","
    + "scrollbars="+scroll+", "
    + "status=1,"
    + "titlebar=1,"
    + "toolbar=1,"
    + "hotkeys=1,"
    + "screenx=" + xposition + ","  //NN Only
    + "screeny=" + yposition + ","  //NN Only
    + "left=" + xposition + ","     //IE Only
    + "top=" + yposition;           //IE Only

    window.open(pageToLoad,winName,args );
}

function validateNewsletterForm(pForm)
{
	var bValid = true;

	if ((bValid) && ((pForm.Name.value=='')||(pForm.Name.value=='Type in your name')))
	{
		bValid = false;
		alert('You must enter you Name');
	}
		
	if ((bValid) && ((pForm.Email.value=='')||(pForm.Email.value=='Type in your email')))
	{
		bValid = false;
		alert('You must enter your Email Address');
	}
	else if (bValid)
	{
		bValid = validEmail(pForm.Email.value);
	}
	
	return bValid;
}

function validateLocationIDForm(pForm)
{
	var bValid = true;
	
	if ((bValid) && (pForm.LocationID.value==''))
	{
		bValid = false;
		alert('You must select a Service to continue');
	}
	
	return bValid;
}

function validatePageIDForm(pForm)
{
	var bValid = true;
	
	if ((bValid) && (pForm.PageID.value==''))
	{
		bValid = false;
		alert('You must select a Page to continue');
	}
	
	return bValid;
}

function validateArticleIDForm(pForm)
{
	var bValid = true;
	
	if ((bValid) && (pForm.ArticleID.value==''))
	{
		bValid = false;
		alert('You must select an Article to continue');
	}
	
	return bValid;
}

function validatePageDownloadForm(pForm)
{
	var bValid = true;

	if ((bValid) && (pForm.DownloadTitle.value==''))
	{
		bValid = false;
		alert('You must enter a Title');
	}

	if ((bValid) && (pForm.Filename.value==''))
	{
		bValid = false;
		alert('You must select a file');
	}
	
	return bValid;
}

function validatePageLinkForm(pForm)
{
	var bValid = true;

	if ((bValid) && (pForm.LinkTitle.value==''))
	{
		bValid = false;
		alert('You must enter a Title');
	}

	if ((bValid) && (pForm.LinkURI.value=='')&&(pForm.InternalPageURI.value==''))
	{
		bValid = false;
		alert('You must enter a link');
	}
	
	return bValid;
}

function validatePageForm(pForm)
{
	syncTextarea();
	var bValid = true;
	
	if ((bValid) && (pForm.ParentID.value==''))
	{
		bValid = false;
		alert('You must select a navigation section');
	}

	if ((bValid) && (pForm.PageTitle.value==''))
	{
		bValid = false;
		alert('You must enter a Title');
	}

	if ((bValid) && (pForm.PageContent.value==''))
	{
		bValid = false;
		alert('You must enter the Page Content');
	}
	
	return bValid;
}

function validateArticleForm(pForm)
{
	var bValid = true;
	
	if ((bValid) && (pForm.ArticleTitle.value==''))
	{
		bValid = false;
		alert('You must enter the Article Title');
	}
	
	if ((bValid) && (pForm.ArticleDescription.value==''))
	{
		bValid = false;
		alert('You must enter the Article Title');
	}
	else
	{
		if ((bValid) && (pForm.ArticleDescription.value.length > 80))
		{
			bValid = false;
			alert('The maximum length for a Description is 80 characters.');			
		}
	}
	
	if ((bValid) && (pForm.ArticlePublishDate.value==''))
	{
		bValid = false;
		alert('You must enter the Publish Date');
	}
	
	if ((bValid) && (pForm.AuthorName.value==''))
	{
		bValid = false;
		alert('You must enter the Author Name');
	}

	if ((bValid) && (pForm.ArticleContent.value==''))
	{
		bValid = false;
		alert('You must enter the Article Content');
	}
	
	return bValid;
}

function validateHelpForm(pForm)
{
	var bValid = true;
	
	if ((bValid) && (pForm.Title.value==''))
	{
		bValid = false;
		alert('You must enter your Title');
	}
	
	if ((bValid) && (pForm.Firstname.value==''))
	{
		bValid = false;
		alert('You must enter your First Name');
	}
	
	if ((bValid) && (pForm.Surname.value==''))
	{
		bValid = false;
		alert('You must enter your Surname');
	}
		
	if ((bValid) && (pForm.Telephone.value==''))
	{
		bValid = false;
		alert('You must enter your Telephone Number');
	}
		
	if ((bValid) && (pForm.Email.value==''))
	{
		bValid = false;
		alert('You must enter your Email Address');
	}
	else if (bValid)
	{
		bValid = validEmail(pForm.Email.value);
	}
		
	if ((bValid) && (pForm.Question.value==''))
	{
		bValid = false;
		alert('You must enter your Question');
	}
	
	return bValid;
}

function validateCommentsForm(pForm)
{
	var bValid = true;
	
	if ((bValid) && (pForm.CommentContent.value==''))
	{
		bValid = false;
		alert('You must type a comment if you want to add one to the Intranet');
	}
	
	return bValid;
}

function validateSearchForm(pForm)
{
	var bValid = true;
	
	if ((bValid) && (pForm.keywords.value==''))
	{
		bValid = false;
		alert('You must enter a keyword to search the Intranet');
	}
	
	return bValid;
}

function NumberOfChar(str,char)
{
	var ii, charCount;
	charCount = 0;
	for (ii=0; ii < str.length;ii++)
	{
		var cc = str.charAt(ii);
		if (cc == char)
		{
			charCount = charCount + 1;
		}
	}
	return charCount;
}

function validEmail(str)
{
	var bool;
	bool = true;
	if (str.length < 6)
	{
		bool = false;
		alert("Email address has too few characters.");
	}
	if ((bool) && ((NumberOfChar(str,'@')==0)||(NumberOfChar(str,'@')>1)))
	{
		bool = false;
		alert("Email address contains the wrong number of @'s.");
	}
	if ((bool) && (NumberOfChar(str,'.')==0))
	{
		bool = false;
		alert("Email address must contain at least one '.'.");
	}
	if ((bool) && (NumberOfChar(str,' ')!=0))
	{
		bool = false;
		alert("Email address must not contain any spaces.");
	}
	return bool;
}

function Left(pString, pLength)
{
	if (pLength <= 0)
	{
	    return "";
	}
	else if (pLength > String(pString).length)
	{
	    return pString;
	}
	else
	{
	    return String(pString).substring(0,pLength);
	}
}

function Right(pString, pLength)
{
    if (pLength <= 0)
    {
		return "";
	}
    else if (pLength > String(pString).length)
    {
    	return pString;
    }
    else 
    {
       var iStringLength = String(pString).length;
       return String(pString).substring(iStringLength, iStringLength - pLength);
    }
}

/*************************************************/
/****************** Image Fading *****************/
/*************************************************/
var iImageIndex = 1;
var iImageCount = 0;
var oImageDiv;

function runSlideShow(pCount)
{
	iImageCount = pCount;
	setTimeout("nextImage()", 5000);	
	oImageDiv = document.getElementById('fadingimage');
}

function nextImage()
{
	iImageIndex++;
	
	if (iImageIndex > iImageCount) iImageIndex = 1;
	
	$('fadingimage').fade(); 

	setTimeout("showImage()", 1000);
}

function showImage()
{
	var sImageSrc = oImageDiv.src.substr(0,(oImageDiv.src.length - 5)) + iImageIndex.toString() + '.jpg';
	oImageDiv.src = sImageSrc;
	$('fadingimage').appear(); 	
	setTimeout("nextImage()", 5000);
}
