// JavaScript Document

//Filter for typing characters in Input box
function Filter4Characters(evt) 
{
	if(navigator.appName.indexOf('Microsoft')!=-1) 
	{
		if(event.keyCode < 46 || event.keyCode > 57) 
		{
			event.returnValue = false;
		}
	}
	else 
	{
		if(evt.charCode && (evt.charCode < 46 || evt.charCode > 57)) 
		{
			if(evt.preventDefault)
			{
				evt.preventDefault();
			}
		}
	}
}

//Function to prevent typing characters in input box
function preventOpp(objID)
{
	if(navigator.appName.indexOf('Microsoft')!=-1) 
	{
		
		document.getElementById(objID).onkeypress = Filter4Characters;
		
	} 
	else 
	{
		//alert(objID);
		document.getElementById(objID).addEventListener("keypress",Filter4Characters, true);
		
	}
}

//function to clear the Login form fields on Focus
function clearFields(_field, _default, _current) 
{  
  if (_default == _current) 
  {
	_field.value='';
  }
}
//Validating the tags
function tagvalidate(objname)
{		
	return(objname.value.match(/([\<])([^\>]{1,})*([\>])/i));
}


function OpenWindow(URL,txtTitle)
{
	var win = new Window({
					 url:URL,
					 className: "bluelighting", 
					 width:450, 
					 height:500, 
					 zIndex: 100, 
					 resizable: true, 
					 title: txtTitle, 
					 showEffect:Effect.Appear, 
					 hideEffect: Effect.Fade, 
					 draggable:true, 
					 wiredDrag: true
					 })
	win.showCenter();
}

function OpenLoader(value)
{
	var Img = "<span style='padding:0px;color:#4C636E'><img src='images/icons/loading_small.gif' width='16' height='16' border='0'  align='absmiddle'>Loading Please Wait....</span>";
	if(value)
	{
		Dialog.info(Img,{className: "bluelighting",width:200, height:50, showProgress: false});
	}else{
		Dialog.closeInfo();
	}
}

//Function Automatically Load Banners on Left Panel
function AutoLoadBannerMiddle(LoaderID)
{
	//alert("middle");
	var ResponseURL = "ajaxserver/MiddleBanner.php";
	new Ajax.PeriodicalUpdater(LoaderID, ResponseURL, 
							   {
									method : 'post',
									frequency : 30,
									decay : 1
					 			});
}

function AutoLoadBannerLeft(LoaderID)
{
	//alert(LoaderID);
	var ResponseURL = "ajaxserver/LeftBanner.php";
	new Ajax.PeriodicalUpdater(LoaderID, ResponseURL, 
							   {
									method : 'post',
									frequency : 10,
									decay : 1
					 			});
}
function AutoLoadBannerLeft2(LoaderID)
{
	//alert(LoaderID);
	var ResponseURL = "ajaxserver/LeftBanner2.php";
	new Ajax.PeriodicalUpdater(LoaderID, ResponseURL, 
							   {
									method : 'post',
									frequency : 10,
									decay : 1
					 			});
}

function AutoLoadBannerRight(LoaderID)
{
	//alert("middle");
	var ResponseURL = "ajaxserver/RightBanner.php";
	new Ajax.PeriodicalUpdater(LoaderID, ResponseURL, 
							   {
									method : 'post',
									frequency : 10,
									decay : 1
					 			});
}
function AutoLoadBannerTop(LoaderID,LoadTime)
{
	//alert(LoadTime);
	var ResponseURL = "ajaxserver/TopBanner.php";
	new Ajax.PeriodicalUpdater(LoaderID, ResponseURL, 
							   {
									method : 'post',
									frequency : LoadTime,
									decay : 1
					 			});
}

function LoadBannerTop(LoaderID,LoadTime)
{
	//alert("top");
	//alert(LoadTime);
	var ResponseURL = "ajaxserver/TopBanner.php";
	new Ajax.Updater(LoaderID, ResponseURL, 
							   {
									method : 'post',
									frequency : LoadTime,
									decay : 1
					 			});
}

function clickCount(BannerID,LoadTime)
{
		//alert("BannerID");
		BannerClickInsert(BannerID,LoadTime,'bannerPannel', 'bannerPannel','0');///REQUEST TO JAVASCRIPT WITH PARAMS ( advID,CatID,$('AjaxMessage'+advID), $('AjaxShowOutPut'+advID) ) TO REQUEST TO EMBEDED PHP PAGE
		
}


function BannerClickInsert(bannerId,LoadTime,loadingObj,outputClt,doIt)
{
	//alert(bannerId);
	//$('bannerPannel').innerHTML = 
	OpenLoader(true);
	new Ajax.Request('ajaxserver/BannerClickCount.php',
	{
		method:'post',
		parameters: 
		{
			task:'insert',
			bannerId:bannerId,
			doIt:doIt		
		},
		onSuccess: function(transport)
		{
			OpenLoader(false);
			LoadBannerTop('bannerPannel',LoadTime);
		},
		
		onFailure: function(transport)
		{ 
			 if (404 == transport.status)
			 {
				loadingObj.innerHTML="Sorry, Resource Is Unavailable";
			 }
			  else if (500 == transport.status)
			 {
				loadingObj.innerHTML="Sorry, Internal Error. Please Contact Administrator.";
				
			 }
			 else
			 {
			   loadingObj.innerHTML="Sorry, Unexpected Response Status: " +transport.status ; 
			 }
		}
  }); 

}


/*function getDiscount(mcount)
{
	//alert(mcount);
	var URL = "ajaxserver/ResponseDiscountValue.php";
	//alert(URL);
	new Ajax.Request
	(URL,
		{
			method:'post',
			parameters: 
			{
				mcount : mcount 
			},
			onSuccess : function(transport)
			{ 
				var response = transport.responseText;
				alert(response);
				$('hidDiscountValue').value = response;
				alert(document.getElementById('hidDiscountValue').value);
			}
		}
	  ); 
}*/

