function strReplaceAll(string,match)
	{
		indexOfMatch = string.indexOf(match);
		
		while(indexOfMatch != -1 )
			{
//				alert(string + " " + match);
			
				string = string.replace(match,'_');
				
				indexOfMatch = string.indexOf(match);	
			}	
		return string;
	}

function acceptTextJs(text,textPattern)
	{	
//		var textPath = 'abcdefghijklmnoprstqwxyz1234567890';
		var Pattern = 'abcdefghijklmnoprstuvqwxyz';
		var textToFind = Pattern + textPattern; 
		textToFind = textToFind.toUpperCase() + textToFind.toLowerCase();
		var error = 0;
		for (var count = 0; count < text.length; count++)
			{	
				if ( textToFind.indexOf(text.substr(count,1)) < 0 )
					{
						error = 1;
						break;
					}
			}
		if ( error == 0 )
			{
				return true;	
			}
			else
				{
					return false;	
				}
	}
function checkEmail(email)
	{
//		alert(email);
		var error = 0;
		
		if ( email.indexOf('@') <= 0 )	
			{
				error = 1;	
			}
		if ( email.lastIndexOf('.') <=0 )
			{
				error = 1;
			}
		var around = 0;
		var Pattern = '@';
		for ( count = 0; count < email.length; count++ )
			{
				if ( Pattern.indexOf(email.substr(count,1)) >= 0 )
					{
						around++;	
					}
			}
		if ( around > 1)
			{
				error = 1;	
			}
		if ( email.indexOf('@') == email.lastIndexOf('.')-1 )
			{
				error = 1;	
			}
		if ( email.lastIndexOf('.') == email.length - 1 )
			{
				error = 1;	
			}
		if ( email.lastIndexOf('.') < email.lastIndexOf('@') )
			{
				error = 1;	
			}
		if ( email.length == 0 )
			{
				error = 1;	
			}
		if ( error == 0)
			{
				return	true;
			}
			else
				{
					return false;	
				}
	}



function bookMark()
	{
		
		var ua=navigator.userAgent.toLowerCase();
		var isKonq=(ua.indexOf('konqueror')!=-1);
		var isSafari=(ua.indexOf('webkit')!=-1);
  	var isMac=(ua.indexOf('mac')!=-1);
		title = document.title; 
		url = location.href;

		if (window.sidebar) 
			{ // Mozilla Firefox Bookmark
				window.sidebar.addPanel(title, url,title);
			}
			else if( window.external )
				{ // IE Favorite
					window.external.AddFavorite( url, title); 
				}
			else if(window.opera && window.print) 
				{ // Opera Hotlist
					alert("Opera");	
	        var elem = document.createElement('a');
          elem.setAttribute('href',url);
          elem.setAttribute('title',title);
          elem.setAttribute('rel','sidebar');
          elem.click();
				}
				else if ( window.home || isSafari)
					{
						alert("Safari");	
					}
					else if (window.print || isMac )
						{
							alert("Mac");
						} 
	}
	
function newsletter()
	{
		if ( $('newsError') )
			{
				$('newsError').style.display = 'none';	
			}
		var name = $('myName').value

//		alert(name + $('myEmail').value);

		var error = 0;
		var errorMsg = '';
		if ( $('myEmail').value.length == 0 )
			{
				error = 1;
				errorMsg +='E-mail must not be empty' + '<br>';	
			}
			else
				{
					if ( !checkEmail($('myEmail').value) )	
						{
							error = 1;
							errorMsg +='E-mail format is not valid' + '<br>';
						}
				}
		if (name.length == 0 )
			{
				error = 1;
				errorMSg +='Name must not be empty <br>';	
			}
			else
				{	
					if ( !acceptTextJs(name,' ') )
						{
							error = 1;	
							errorMsg +='Name is not accepted as format<br>';
						}
				}
//			alert($('myEmail').value.length);
		if ( error == 1)
			{
				$('newsError').innerHTML = errorMsg;
				Effect.Appear('newsError');	
			}
			else
				{
					new Ajax.Request
						(
							'insertEmail.php',
								{
									method : 'post',
									parameters : {email : $('myEmail').value,name: name},
									onSuccess : function (transport)
										{
												var response = transport.responseText;
												$('newsError').innerHTML = response;
												Effect.BlindDown('newsError');
										},
									onFailure : function () {$('newsError').innerHTML = 'Error retreving file'; Effect.BlindDown('newsError');	}
								}
						);
				}
		
	}
	
	
	
	
	
	
//Rotate BaNNER


var linkArray = new Array ();
var linkLinkArray = new Array();


function bannerArray()
{	
	new Ajax.Request
		(
			'getBannerLinks.php',
				{
					method : 'post',
					onSuccess : function (transport)
						{
							var response = transport.responseText;	
							var responseSplit = response.split('$');
							linkArray = responseSplit[0].split('#');
							linkLinkArray = responseSplit[1].split('#');
//							alert(linkArray + linkLinkArray);
							rotateBanner('');		
						},
					onFailure : function () {alert('Error retreving file')}
				}
		);
}

var curentAdd = 0;
/*
function addLinks()
	{
		linkArray[0] = 'images/banner1.jpg';
		linkArray[1] = 'images/banner2.jpg';
		linkArray[2] = 'images/banner3.jpg';				
	}
*/
function rotateBanner(value)
	{
		if ( value == 'start')
			{
				bannerArray();	
			}	
			else
				{
					if ( curentAdd == linkArray.length-1 )
						{
							curentAdd = 0 ;
						}
						else
							{	
								curentAdd++;
							}
					$('bannerFile').src = linkArray[curentAdd].substr(3);
					$('hrefFile').href = linkLinkArray[curentAdd];
					setTimeout("rotateBanner('')",15000);

				}
	}

	
//END ROTATE BANNER
	
function doGetArticle(id,linkText,number)
	{	
		linkText = linkText.replace(/ /gi,'_');
		
		linkText = strReplaceAll(linkText,'\'');
		linkText = strReplaceAll(linkText,':');		
		linkText = strReplaceAll(linkText,'"');		
		linkText = strReplaceAll(linkText,'?');		
		linkText = strReplaceAll(linkText,'\\');		
		linkText = strReplaceAll(linkText,'/');		
		linkText = strReplaceAll(linkText,'\'');
		linkText = strReplaceAll(linkText,';');				
		
//		alert(window.location.href);
		window.location.href = linkText + '-' + id;
//		$('articleTitle').innerHTML = linkText;
//		alert(window.location.href);
	}

/*

function doGetArticle(id,linkText,number)
	{	
//		alert(id);
		if ( number == 0 )
			{
				rotateBanner('start');	
			}
		document.title = linkText;
//		alert(window.location.href);
	//	window.location.href += linkText + ',' + id;
//		$('articleTitle').innerHTML = linkText;
//		alert(window.location.href);
		$('siteFooterTitle').innerHTML = linkText;
		
		if ( $('article') )	
			{
				$('article').style.display = 'none';	
			}
		if ( $('showArticle') )	
			{
				$('showArticle').style.display = 'none';	
			}

		new Ajax.Request
			(
				'getArticle.php',
					{
						method : 'post',
						parameters : {id : id},
						onSuccess : function (transport)
							{
								var response = transport.responseText;
								$('article').innerHTML = response;
//								$('article').update(response);
								Effect.BlindDown('article');
								Effect.Appear('showArticle');								
	//						eval(response);
							},
						onFailure : function () { $('showArticle').innerHTML = ' Error retreving file'; Effect.BlindDown('article');Effect.Appear('showArticle');			}
					}
			);
	}
*/
	
function siteMap()
	{
		if ( $('article') )
			{
				$('article').style.display = 'none';	
			}
		if ( $('showArticle') )	
			{
				$('showArticle').style.display = 'none';	
			}
			
		new Ajax.Request
			(
				'getSiteMap.php',
					{
						method : 'get',
						onSuccess : function (transport)
							{
								var response = transport.responseText;
								$('article').update(response);	
								Effect.BlindDown('showArticle');
								Effect.Appear('article');								
							},
						onFailure : function () { $('article').innerHTML = 'Error retreving file'; Effect.BlindDown('showArticle');Effect.Appear('article');}
					}
			);
	}
	
	
	