			// TOUCH-EVENTS SINGLE-FINGER SWIPE-SENSING JAVASCRIPT
			// Courtesy of PADILICIOUS.COM and MACOSXAUTOMATION.COM
			
			// this script can be used with one or more page elements to perform actions based on them being swiped with a single finger
		
			var triggerElementID = null; // this variable is used to identity the triggering element
			var fingerCount = 0;
			var startX = 0;
			var startY = 0;
			var curX = 0;
			var curY = 0;
			var deltaX = 0;
			var deltaY = 0;
			var horzDiff = 0;
			var vertDiff = 0;
			var minLength = 10; // the shortest distance the user may swipe
			var swipeLength = 0;
			var swipeAngle = null;
			var swipeDirection = null;
			var PageArray = new Array("Issuepage1.php","Issuepage2.php","Issuepage3.php","Issuepage4.php","Issuepage5.php");
			
			// The 4 Touch Event Handlers
			
			// NOTE: the touchStart handler should also receive the ID of the triggering element
			// make sure its ID is passed in the event call placed in the element declaration, like:
			// <div id="picture-frame" ontouchstart="touchStart(event,'picture-frame');"  ontouchend="touchEnd(event);" ontouchmove="touchMove(event);" ontouchcancel="touchCancel(event);">
		
			function touchStart(event,passedName) {
				// disable the standard ability to select the touched object
				event.preventDefault();
				// get the total number of fingers touching the screen
				fingerCount = event.touches.length;
				// since we're looking for a swipe (single finger) and not a gesture (multiple fingers),
				// check that only one finger was used
				if ( fingerCount == 1 ) {
					// get the coordinates of the touch
					startX = event.touches[0].pageX;
					startY = event.touches[0].pageY;
					// store the triggering element ID
					triggerElementID = passedName;
				} else {
					// more than one finger touched so cancel
					touchCancel(event);
				}
			}
		
			function touchMove(event) {
				event.preventDefault();
				if ( event.touches.length == 1 ) {
					curX = event.touches[0].pageX;
					curY = event.touches[0].pageY;
				} else {
					touchCancel(event);
				}
			}
			
			function touchEnd(event) {
				event.preventDefault();
				// check to see if more than one finger was used and that there is an ending coordinate
				if ( fingerCount == 1 && curX != 0 ) {
					// use the Distance Formula to determine the length of the swipe
					swipeLength = Math.round(Math.sqrt(Math.pow(curX - startX,2) + Math.pow(curY - startY,2)));
					// if the user swiped more than the minimum length, perform the appropriate action
					if ( swipeLength >= minLength ) {
						caluculateAngle();
						determineSwipeDirection();
						processingRoutine();
						touchCancel(event); // reset the variables
					} else {
						touchCancel(event);
					}	
				} else {
					touchCancel(event);
				}
			}
		
			function touchCancel(event) {
				// reset the variables back to default values
				fingerCount = 0;
				startX = 0;
				startY = 0;
				curX = 0;
				curY = 0;
				deltaX = 0;
				deltaY = 0;
				horzDiff = 0;
				vertDiff = 0;
				swipeLength = 0;
				swipeAngle = null;
				swipeDirection = null;
				triggerElementID = null;
			}
			
			function caluculateAngle() {
				var X = startX-curX;
				var Y = curY-startY;
				var Z = Math.round(Math.sqrt(Math.pow(X,2)+Math.pow(Y,2))); //the distance - rounded - in pixels
				var r = Math.atan2(Y,X); //angle in radians (Cartesian system)
				swipeAngle = Math.round(r*180/Math.PI); //angle in degrees
				if ( swipeAngle < 0 ) { swipeAngle =  360 - Math.abs(swipeAngle); }
			}
			
			function determineSwipeDirection() {
				if ( (swipeAngle <= 45) && (swipeAngle >= 0) ) {
					swipeDirection = 'left';
				} else if ( (swipeAngle <= 360) && (swipeAngle >= 315) ) {
					swipeDirection = 'left';
				} else if ( (swipeAngle >= 135) && (swipeAngle <= 225) ) {
					swipeDirection = 'right';
				} else if ( (swipeAngle > 45) && (swipeAngle < 135) ) {
					swipeDirection = 'down';
				} else {
					swipeDirection = 'up';
				}
			}
			
			function processingRoutine() {
				var swipedElement = document.getElementById(triggerElementID);
				if ( swipeDirection == 'left' ) {
					// REPLACE WITH YOUR ROUTINES
					//swipedElement.style.backgroundColor = 'orange';
					NavigateToNextPageFromChild();
					//alert(1);
				} else if ( swipeDirection == 'right' ) {
					// REPLACE WITH YOUR ROUTINES
					//swipedElement.style.backgroundColor = 'green';
					NavigateToPreviousPageFromChild();
					//alert(2);
				} else if ( swipeDirection == 'up' ) {
					// REPLACE WITH YOUR ROUTINES
					//swipedElement.style.backgroundColor = 'maroon';
					//alert(3);
				} else if ( swipeDirection == 'down' ) {
					// REPLACE WITH YOUR ROUTINES
					//swipedElement.style.backgroundColor = 'purple';
					//alert(4);
				}
			}
			
			
			function SetCookie ( name, value)
			{
				//alert("test from setcookie");
				var cookie_string = name + "=" + escape ( value );
				document.cookie = cookie_string;
			}

			function GetCookie (name)
			{
				//alert("test from GetCookie");
				var nameEQ = name + "=";
				
				var ca = document.cookie.split(';');
				
				for(var i=0;i < ca.length;i++) 
				{
					var c = ca[i];
					while (c.charAt(0)==' ') c = c.substring(1,c.length);
					if (c.indexOf(nameEQ) == 0) 
					{
					   return c.substring(nameEQ.length,c.length);
					}
					  
				}
				
				return null;
			}

			function DeleteCookie ( cookie_name )
			{
				var cookie_date = new Date ( );  // current date & time
				cookie_date.setTime ( cookie_date.getTime() - 1 );
				document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
			}
			
			function GoToCatalogPage()
			{
				var PageIndex =GetCookie("CurrentPageIndex");
				//alert("from GoToCatalogPage of js");
				//window.parent.window.document.all.chcirc.src = PageArray[PageIndex];
				
				//window.location.replace("Issuepage5.php");
				//alert(PageArray[PageIndex]);
				backPageUrl = PageArray[PageIndex];
				backPageUrl += ( backPageUrl.indexOf('?') == -1 ? '?goback=1' : '&goback=1' );
				//alert(backPageUrl);
				window.location.replace(backPageUrl);
				
			}
			
			function GoToCouponSelect()
			{

				window.location.replace("CouponSelect.php");
				
			}
			
			function NavigateToHomePage()
			{
				var ParentPage = window.parent.location.href;
				var CurrentPage = window.location.href;
				
				if( ParentPage == CurrentPage)
				{
					window.location.href = 'IssueHome.php';
					window.history.forward(1);
				}
				
				//alert('parent page -----'+ParentPage);
				//alert('current page -----'+ParentPage);
			}
			
			function HandleAncillaryPageUnload()
			{
				try{
				//alert("hi");
				//alert(window.parent.window.document.all.divNexPageNav.style.visibility);
				//window.parent.window.document.all.divNexPageNav.style.visibility = "visible";
				//window.parent.window.document.all.divPrevPageNav.style.visibility = "visible";
				parent.document.getElementById('divNexPageNav').style.visibility = "visible";
				parent.document.getElementById('divPrevPageNav').style.visibility = "visible";
				//alert(window.parent.window.document.all.divNexPageNav.style.visibility);
				}catch(e){}
			}
			function NavigateToNextPageFromChild()
			{
				//alert("test from NavigateToNextPageFromChild");			
				var PageIndex =GetCookie("CurrentPageIndex");
				
				try{parent.move2focus();}catch(e){}
				if (PageIndex == null) 
				{
					SetCookie("CurrentPageIndex",0);
					PageIndex = 0;
				}
				else
				{
					PageIndex = parseInt(PageIndex) +1;
					SetCookie("CurrentPageIndex",PageIndex);
				}
				
				if(PageIndex == (PageArray.length))
				{
					//alert("You reached last page, now you will go to first page");
					SetCookie("CurrentPageIndex",0);
					PageIndex = 0;
				}
				//alert(PageIndex);
				//alert(PageArray[PageIndex]);
				//document.all.chcirc.src = PageArray[PageIndex];
				
				//alert(window.parent.window.document.all.chcirc.src);
				//window.parent.window.document.all.chcirc.src = PageArray[PageIndex];
				parent.document.getElementById('chcirc').src = PageArray[PageIndex];
				//alert(window.parent.window.document.all.chcirc.src);
			}
			
			function NavigateToPreviousPageFromChild()
			{
			
				if(document.getElementById('mnPageMenu').style.visibility != "visible")
				{
					try{parent.move2focus();}catch(e){}
					document.getElementById('mnPageMenu').style.visibility = "hidden";
					
					//alert("test from NavigateToPreviousPageFromChild");
					var PageIndex =GetCookie("CurrentPageIndex");
					
					if(PageIndex == 0)
					{
						PageIndex = null;
					}
					
					if (PageIndex == null) 
					{
						PageIndex = PageArray.length;
						PageIndex = PageIndex - 1;
						SetCookie("CurrentPageIndex",PageIndex);
					}
					else
					{
						PageIndex = parseInt(PageIndex) - 1;
						SetCookie("CurrentPageIndex",PageIndex);
					}
					//alert(PageIndex);
					//alert(PageArray[PageIndex]);
					//document.all.chcirc.src = PageArray[PageIndex];
					//alert(window.parent.window.document.all.chcirc.src);
					//window.parent.window.document.all.chcirc.src = PageArray[PageIndex];
					parent.document.getElementById('chcirc').src = PageArray[PageIndex];
					//alert(window.parent.window.document.all.chcirc.src);
					}
				
				
			}
			
			function GetQueryStringParameter(argParam)
            {
					alert(argParam);
                    var qsParm = new Array();
                    var strQueryString = window.parent.location.href;
					alert(strQueryString);
                    var URLWithParams = strQueryString.split('?');
					
					if(URLWithParams[1] != null)
					{
						var parms = URLWithParams[1].split('&');
						var i = 0;
					
						for (i=0; i<parms.length; i++) 
						{
						  
							var pos = parms[i].indexOf('=');
							
							if (pos > 0) 
							{
								var key = parms[i].substring(0,pos);
								var val = parms[i].substring(pos+1);
								if(key==argParam)
								{
									return val;
								}
							}
						}
					}
                    
                    return null;
            }
			
			function AddHotspotViewAndHotspotURLViewDetail(pHotspotID)
			{
						var xmlhttp = null;
						
						try 
						{
						   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");    // Trying Internet Explorer 
						}
						catch(e)    // Failed 
						{
						  xmlhttp = new XMLHttpRequest();    // Other browsers.
						}

						var CurrentURL = "AddHotspotViewAndHotspotURLViewDetail.php?hid="+pHotspotID;
						
						//alert(CurrentURL);
										
						xmlhttp.onreadystatechange=function()
						{
							if (xmlhttp.readyState==4 && xmlhttp.status==200)
							{
								var Content = xmlhttp.responseText;
								
								//alert(Content);
							}
						}
						
						
						xmlhttp.open("GET",CurrentURL,true);
						xmlhttp.send(null);
			}
			
			
			function IsEmailValid(EmailAddress)
			{
				//This  function returns a boolean value indicating whether or not the EmailAddress is structurally valid.
				
				var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/ ;
				
				return reg.test(EmailAddress);		// This line returns a true or a false.
			
			}
