﻿// JScript File

//Register***************************	
		function ascii_value (c)
			{
			// restrict input to a single character
			c = c . charAt (0);

			// loop through all possible ASCII values
			var i;
			for (i = 0; i <= 256; i++)
			{
			// convert i into a 2-digit hex string
			var h = i . toString (16);
			if (h . length == 1)
			h = "0" + h;

			// insert a % character into the string
			h = "%" + h;

			// determine the character represented by the escape code
			h = unescape (h);

			// if the characters match, we've found the ASCII value
			if (h == c)
			break;
			}
			return i;
			}
			
		function val()
		{
			if(document.frmreg.txtfirstname.value=="")
			{
				alert("Please enter First name");
				document.frmreg.txtfirstname.focus();
				return false;
			}
			var result = ascii_value (document.frmreg.txtfirstname.value);

			if(result=="32")
			{
			alert("Space not allowed in First Name.");
			document.frmreg.txtfirstname.focus();
			return false;
			} 
			if(document.frmreg.txtfirstname.value!="")
			{
				var alpha=/^[a-zA-Z\ ]*$/;
				if (!alpha.test(document.frmreg.txtfirstname.value)) 
				{
					alert("Enter Only Alphabet");
					//document.frmreg.txtfirstname.value="";
					document.frmreg.txtfirstname.focus();
					return false;
				}
			}
			if(document.frmreg.txtlastname.value=="")
			{
				alert("Please enter Last name");
				document.frmreg.txtlastname.focus();
				return false;
			}
			
			var result = ascii_value (document.frmreg.txtlastname.value);

			if(result=="32")
			{
			alert("Space not allowed in Last Name.");
			document.frmreg.txtlastname.focus();
			return false;
			}
			
			if(document.frmreg.txtlastname.value!="")
			{
				var alpha=/^[a-zA-Z\ ]*$/;
				if (!alpha.test(document.frmreg.txtlastname.value)) 
				{
					alert("Please Enter Only Alphabet in Last Name");
					//document.frmreg.txtfirstname.value="";
					document.frmreg.txtlastname.focus();
					return false;
				}
			}
			if(document.frmreg.txtfirstname.value==document.frmreg.txtlastname.value)
			{
				alert("First name and Last name cannot be same");
				document.frmreg.txtlastname.focus();
				return false;
			}
			
			if(document.frmreg.txtusername.value=="")
			{
				alert("Please enter UserName");
				document.frmreg.txtusername.focus();
				return false;
			}
			var result = ascii_value (document.frmreg.txtusername.value);

			if(result=="32")
			{
			alert("Space not allowed in User Name.");
			document.frmreg.txtusername.focus();
			return false;
			}
			if(document.frmreg.txtpassword.value=="")
			{
				alert("Please enter Password");
				document.frmreg.txtpassword.focus();
				return false;
			}
			
			var result = ascii_value (document.frmreg.txtpassword.value);

			if(result=="32")
			{
			alert("Space not allowed in Password.");
			document.frmreg.txtpassword.focus();
			return false;
			}
			
			if(document.frmreg.txtpassword.value!="")
			{
				if(document.frmreg.txtpassword.value.length < 6)
				{
					alert("Password must be 6-12 alphanumeric characters");
					document.frmreg.txtpassword.focus();
					return false;
				}
				if(document.frmreg.txtpassword.value.length > 12 )
				{
					alert("Password must be 6-12 alphanumeric characters");
					document.frmreg.txtpassword.focus();
					return false;
				}
			}
			
			if(document.frmreg.txtconfirmpassword.value=="")
			{
				alert("Please enter Confirm password");
				document.frmreg.txtconfirmpassword.focus();
				return false;
			}
			
			
			if(document.frmreg.txtpassword.value!=document.frmreg.txtconfirmpassword.value)
			{
				alert("Your password does not match.Try again?");
				document.frmreg.txtconfirmpassword.value="";
				document.frmreg.txtconfirmpassword.focus();
				return false;
			}
			
			
			
			
			if(document.frmreg.txtemail.value=="")
			{
				alert("Please enter E-mail address");
				document.frmreg.txtemail.focus();
				return false;
			}
			if (document.frmreg.txtemail.value!="")
			{
				var theeidStr=document.frmreg.txtemail.value;
				var regeidexp = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
				if (!theeidStr.match(regeidexp)) 
				{
					alert("Please enter proper E-mail Id");
					document.frmreg.txtemail.value="";
					document.frmreg.txtemail.focus();
					return false;
				}
			}
			
			if(document.frmreg.ddl_month.selectedIndex=="")
			
				{
					alert("Please select Month");
					document.frmreg.ddl_month.focus();
					return false;
				}
				
			if(document.frmreg.ddl_date.selectedIndex=="")
			
				{
					alert("Please select Date");
					document.frmreg.ddl_date.focus();
					return false;
				}
				
			if(document.frmreg.ddl_year.selectedIndex=="")
			
				{
					alert("Please select Year");
					document.frmreg.ddl_year.focus();
					return false;
				}
				
				
			
	}
	
	//End Regsiter**********************	
	
	//Forum***************
	function validate()
		{		
			var _ctrlArr;
          _ctrlArr=document.frmreg.elements;
          var i=0;
          var sqlrgex1=/(\%27|\-\-|\%23|#)/i;
          var sqlrgex2=/(\%3D|=).*(\%27|\'|\-\-|\%3B|;)/i;
          var sqlrgex3=/\w*(\%27|\')(\%6F|o|\%4F)(\%72|r|\%52)/i;
          var sqlrgex4=/(\%27|\')union/i;
          var sqlrgex5=/exec(\s|\+)+(s|x)p\w+/i;
          
          var cssrgex1=/(\%3C|<)(\%2F|\/)*[a-z0-9\%]+(\%3E|>)/i;
          var cssrgex2=/(\%3C|<)(\%69|i|\%49)(\%6D|m|\%4D)(\%67|g|\%47).*(\%3E|>)/i;
          var cssrgex3=/(\%3C|<).*(\%3E|>)/i;          
			for(i=0;i<_ctrlArr.length;i++)
			{
				if(_ctrlArr[i].type == 'text' || _ctrlArr[i].type == 'textarea')
				{
					var _ctrl = _ctrlArr[i].value;
					if(_ctrl.search(sqlrgex1)!=-1 || _ctrl.search(sqlrgex2)!=-1 || _ctrl.search(sqlrgex3)!=-1 || _ctrl.search(sqlrgex4)!=-1 || _ctrl.search(sqlrgex5)!=-1)
					{
					_ctrlArr[i].focus();
					alert("One or more fields contain scripting characters. Please eliminate characters such as '<' or '>' and resubmit the page.");                
					return false;
					}
					if(_ctrl.search(cssrgex1)!=-1 || _ctrl.search(cssrgex2)!=-1 || _ctrl.search(cssrgex3)!=-1 )
					{
					_ctrlArr[i].focus();          
					alert("One or more fields contain scripting characters. Please eliminate characters such as '<' or '>' and resubmit the page.");
					return false;
					}
				}
			}
		}		
	//End Forum *************	
	
	//Challengers*************
	function MM_jumpMenu(targ,selObj,restore){ 
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
					
			function validate_search()
			 {
				if (document.getElementById("txt_search").value == "")
					{
						alert("Enter something to Search for..");
						document.getElementById("txt_search").focus();
						return false;
					}
				else if (document.getElementById("txt_search").value != "")
					{
						if (document.getElementById("ddl_Select").value == 0)
							{
								alert("Select Search Type");
								document.getElementById("ddl_Select").focus();
								return false;
							}
						else if (document.getElementById("ddl_Select").value == 1)
							{
								if (!isInteger(document.getElementById("txt_search").value))
									{
										alert("Please enter only digits [0-9] to search for Zip Code");
										document.getElementById("txt_search").value="";
										document.getElementById("txt_search").focus();					
										return false;
									}	
								else 
									{	
										var fnenter=document.getElementById("txt_search").value;
										var Alphabet=/(^\d{5}$)/;
										if (!fnenter.match(Alphabet))
											{
												alert("Please Enter Zip code in Format (xxxxx) - 5 digits");
												document.getElementById("txt_search").value="";
												document.getElementById("txt_search").focus();
												return false;
											}		
									}
							}
						else if (document.getElementById("ddl_Select").value == 2)
							{			
										/*state*/
										var fnenter=document.getElementById("txt_search").value;
										var fnform=/[A-Za-z]$/;
										if (!fnenter.match(fnform))
											{
												alert("Please Enter only characters in State");
												document.getElementById("txt_search").value="";
												document.getElementById("txt_search").focus();
												return false;
											}	
							}	
					}
			 }				
			function ascii_value (c)
				{
				// restrict input to a single character
				c = c . charAt (0);

				// loop through all possible ASCII values
				var i;
				for (i = 0; i <= 256; i++)
				{
				// convert i into a 2-digit hex string
				var h = i . toString (16);
				if (h . length == 1)
				h = "0" + h;

				// insert a % character into the string
				h = "%" + h;

				// determine the character represented by the escape code
				h = unescape (h);

				// if the characters match, we've found the ASCII value
				if (h == c)
				break;
				}
				return i;
				}
			
			function isInteger(strPh)
			{   var i;
				for (i=0; i < strPh.length; i++)
				{
					// Check that current character is number.
					var c = strPh.charAt(i);
					if (((c < "0") || (c > "9"))) return false;
				}
				// All characters are alphanumeric.
				return true;
			}
	//End Challengers*********
	
	//You Tube **************
	
	 function updateHTML(elmId, value) {
          document.getElementById(elmId).innerHTML = value;
        }

        function setytplayerState(newState) {
          updateHTML("playerstate", newState);
        }

        function onYouTubePlayerReady(playerId) {
          ytplayer = document.getElementById("myytplayer");
          setInterval(updateytplayerInfo, 250);
          updateytplayerInfo();
          ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
          ytplayer.addEventListener("onError", "onPlayerError");
        }

        function onytplayerStateChange(newState) {
          setytplayerState(newState);
        }

        function onPlayerError(errorCode) {
          alert("An error occurred: "+ errorCode);
        }

        function updateytplayerInfo() {
          updateHTML("bytesloaded", getBytesLoaded());
          updateHTML("bytestotal", getBytesTotal());
          updateHTML("videoduration", getDuration());
          updateHTML("videotime", getCurrentTime());
          updateHTML("startbytes", getStartBytes());
        }

        // functions for the api calls
        function play() {
          if (ytplayer) {
            ytplayer.playVideo();
          }
        }

        function pause() {
          if (ytplayer) {
            ytplayer.pauseVideo();
          }
        }

        function stop() {
          if (ytplayer) {
            ytplayer.stopVideo();
          }
        }

        function getPlayerState() {
          if (ytplayer) {
            return ytplayer.getPlayerState();
          }
        }

        function seekTo(seconds) {
          if (ytplayer) {
            ytplayer.seekTo(seconds, true);
          }
        }

        function getBytesLoaded() {
          if (ytplayer) {
            return ytplayer.getVideoBytesLoaded();
          }
        }

        function getBytesTotal() {
          if (ytplayer) {
            return ytplayer.getVideoBytesTotal();
          }
        }

        function getCurrentTime() {
          if (ytplayer) {
            return ytplayer.getCurrentTime();
          }
        }

        function getDuration() {
          if (ytplayer) {
            return ytplayer.getDuration();
          }
        }

        function getStartBytes() {
          if (ytplayer) {
            return ytplayer.getVideoStartBytes();
          }
        }

        function mute() {
          if (ytplayer) {
            ytplayer.mute();
          }
        }

        function unMute() {
          if (ytplayer) {
            ytplayer.unMute();
          }
        }
        
        /******Resource Upload ***********/
        	function image_extension()
				{
					var filepath = document.myaccount.file1.value;
					var file_ext = filepath.substring(filepath.lastIndexOf('.') + 1)
					if (file_ext != "jpg" && file_ext != "jpeg" && file_ext != "gif")
					{
						alert("Upload Image with 'jpeg','jpg' or 'gif' extension only");
						return false;
					}
				}
				
				function pdf_extension()
				{
				
					var filepath = document.myaccount.file1.value;
					var file_ext = filepath.substring(filepath.lastIndexOf('.') + 1)
					if (file_ext != "pdf")
					{
						alert("Upload pdf extension only");
						return false;
					}
				}
				