//Scripts for the complete site.

// Functions for trailing spaces.
function trim(strText) { 
		// this will get rid of leading spaces
		while (strText.substring(0,1) == ' ')
			strText = strText.substring(1, strText.length);

		// this will get rid of trailing spaces
		while (strText.substring(strText.length-1,strText.length) == ' ')
			strText = strText.substring(0, strText.length-1);
		var pos=0
		var tevePos=0
		while(strText.indexOf("\n",pos)>-1)
		{
			tevePos=strText.indexOf("\n",pos)
			pos=tevePos+1
		}
		
	   return strText;
}

// Functions for combo selected.
function selectcombo(strFormName,strCboName,strval)
{
		for (var i=0; i<eval("document."+strFormName+"."+strCboName+".options.length"); i++)
		{
			if (eval("document."+strFormName+"."+strCboName+".options[i].value")==strval)
			{
				var objFrm = eval("document."+strFormName);
				objFrm[strCboName].options[i].selected=true;
				break;
			}
		}
}

//Function for select multiple combo
function selectcombomultiple(strFormName,strCboName,strval)
	{
			var mystring = new String(strval);
			var arr = mystring.split(',');			
			for (var i=0; i<eval("document.getElementById('"+strCboName+"').options.length"); i++)
			{
				for (var j=0; j<arr.length; j++)
				{
					//alert(arr[j]);
					if(eval("document.getElementById('"+strCboName+"').options[i].value")==trim(arr[j]))
					{
						var objFrm = eval("document."+strFormName);
						objFrm[strCboName].options[i].selected=true;
						//break;
					}
				}

		    }
	}

// Functions for radio selected.
function selectradio(strFormName,strradName,strval)
{
		var objFrm = eval("document."+strFormName);
		for (var i=0; i <objFrm.elements.length; i++)
		   {
				if(objFrm.elements[i].type=="radio")
				{
					if(objFrm.elements[i].name == strradName)
					{
						if(objFrm.elements[i].value == strval)
						{
							objFrm.elements[i].checked=true;
						}
					}
				}
		   }
}

// Functions for checkbox selected.
function selectcheck(strFormName,strchkName,strval)
{
		var objFrm = eval("document."+strFormName);
		for (var i=0; i <objFrm.elements.length; i++)
		   {
				if(objFrm.elements[i].type=="checkbox")
				{
					if(objFrm.elements[i].name==strchkName)
					{
						if(strval!="")
						{
							objFrm.elements[i].checked=true;
						}
					}
				}
		   }

}

//Function for select multiple checkbox
function selchkmultiple(strFormName,strchkName,strval)
	{
			var mystring = new String(strval);
			var arr = mystring.split(',');
			//var arr = strval;
			var objFrm = eval("document."+strFormName);
			for (var i=0; i <objFrm.elements.length; i++)
		    {
				if(objFrm.elements[i].type=="checkbox")
				{
					if(objFrm.elements[i].name==strchkName)
					{
						for (var j=0; j<arr.length; j++)
						{
							//alert(arr[j]);
							if(objFrm.elements[i].value==trim(arr[j]))
							{
								objFrm.elements[i].checked=true;
							}
						}
						
					}
				}
		    }
	}

//Function for check select checkbox
function clickchkbox(strFormName,strchkName,strval)
	{
			flagchk=false;
			var chkids = "";
			var objFrm = eval("document."+strFormName);
			for(var i=0;i<objFrm.elements.length;i++)
		   {
				 if(objFrm.elements[i].type=="checkbox")
				{
					 if(objFrm.elements[i].name==strchkName)
					{
						if(objFrm.elements[i].checked==true)
						 {
							chkids = chkids + objFrm.elements[i].value + ",";
							flagchk=true;
						 }
					}
				}
		   } 
			if(flagchk==false)
			{
				alert("Please Select "+strval+" Box.");
				return false;
			}
			else
			{
				return chkids;
			}
	}

	// Functions for radio selected.
	function checkedselectradio(strFormName,strradName,strval)
	{
		flagchk=false;
			var objFrm = eval("document."+strFormName);
			for (var i=0; i <objFrm.elements.length; i++)
			   {
					if(objFrm.elements[i].type=="radio")
					{
						if(objFrm.elements[i].name == strradName)
						{
							if(objFrm.elements[i].checked == true)
							{								
								flagchk=true;
								break;
							}
						}
					}
			   }
			   if(flagchk==false)
				{
					alert("Please Select "+strval+" Radio.");
					return false;
				}
				else
				{
					return true;
				}
	}


//Function for alpha-numeric|numeric check
function keyRestrict(e, validchars) {
	 var key='', keychar='';
	 key = getKeyCode(e);
	 if (key == null) return true;
	 keychar = String.fromCharCode(key);
	 keychar = keychar.toLowerCase();
	 validchars = validchars.toLowerCase();
	 if (validchars.indexOf(keychar) != -1)
	  return true;
	 if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
	  return true;
	 return false;
}
function getKeyCode(e) {
	 if (window.event)
		return window.event.keyCode;
	 else if (e)
		return e.which;
	 else
		return null;
}

//Function for image type check
function chkimage(image)
{
	var val = trim(image);
	strlen = val.length;
	strcnt = val.lastIndexOf("\\");
	newstr = val.substr(strcnt+1,strlen);
	tempval = val.toUpperCase();
	val = tempval.substr(val.lastIndexOf("."),val.length);
	if((val.length==4 && val!='.JPG' && val!='.GIF' && val!='.PNG') || (val.length==5 && val!='.JPEG')) 
	{
		return false;
	}
	else
	{
		return true;
	}
}

//Function for voice type check
function chkvoice(voice)
{
	var val = trim(voice);
	strlen = val.length;
	strcnt = val.lastIndexOf("\\");
	newstr = val.substr(strcnt+1,strlen);
	tempval = val.toUpperCase();
	val = tempval.substr(val.lastIndexOf("."),val.length);

	if(val!='.MP3')
	{
		return false;
	}
	else
	{
		return true;
	}
}

function textCounter(field,cntfield,maxlimit) 
{
	if (field.value.length > maxlimit) // if too long...trim it!
	{
		field.value = field.value.substring(0, maxlimit);
	}	
	else // otherwise, update 'characters left' counter
	{
		cntfield.value = maxlimit - field.value.length;
	}
}
function emailCheck(emailStr) 
{
			var emailPat=/^(.+)@(.+)$/
			/* The following string represents the pattern for matching all special
			   characters.  We don't want to allow special characters in the address.
			   These characters include ( ) < > @ , ; : \ " . [ ]    */
			var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
			/* The following string represents the range of characters allowed in a
			   username or domainname.  It really states which chars aren't allowed. */
			var validChars="\[^\\s" + specialChars + "\]"
			/* The following pattern applies if the "user" is a quoted string (in
			   which case, there are no rules about which characters are allowed
			   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
			   is a legal e-mail address. */
			var quotedUser="(\"[^\"]*\")"
			/* The following pattern applies for domains that are IP addresses,
			   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
			   e-mail address. NOTE: The square brackets are required. */
			var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
			/* The following string represents an atom (basically a series of
			   non-special characters.) */
			var atom=validChars + '+'
			/* The following string represents one word in the typical username.
			   For example, in john.doe@somewhere.com, john and doe are words.
			   Basically, a word is either an atom or quoted string. */
			var word="(" + atom + "|" + quotedUser + ")"
			// The following pattern describes the structure of the user
			var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
			/* The following pattern describes the structure of a normal symbolic
			   domain, as opposed to ipDomainPat, shown above. */
			var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
			/* Finally, let's start trying to figure out if the supplied address is
			   valid. */
			/* Begin with the coarse pattern to simply break up user@domain into
			   different pieces that are easy to analyze. */
			var matchArray=emailStr.value.match(emailPat)
				if (matchArray==null) {
				  /* Too many/few @'s or something; basically, this address doesn't
				     even fit the general mould of a valid e-mail address. */
					alert("Email address seems incorrect (check @ and .'s)")
					emailStr.focus()
					return false
				}

			var user=matchArray[1]
			var domain=matchArray[2]

			// See if "user" is valid
			if (user.match(userPat)==null) {
			    // user is not valid
			    alert("The username doesn't seem to be valid.")
			    emailStr.focus()
			    return false
			}

			/* if the e-mail address is at an IP address (as opposed to a symbolic
			   host name) make sure the IP address is valid. */
			var IPArray=domain.match(ipDomainPat)
			if (IPArray!=null) {
			    // this is an IP address
				  for (var i=1;i<=4;i++) {
				    if (IPArray[i]>255) {
				        alert("Destination IP address is invalid!")
				        emailStr.focus()
					return false
				    }
			    }
			    return true
			}


			// Domain is symbolic name
			var domainArray=domain.match(domainPat)
			if (domainArray==null) {
				alert("The domain name doesn't seem to be valid.")
				emailStr.focus()
			    return false
			}

			/* domain name seems valid, but now make sure that it ends in a
			   three-letter word (like com, edu, gov) or a two-letter word,
			   representing country (uk, nl), and that there's a hostname preceding
			   the domain or country. */

			/* Now we need to break up the domain to get a count of how many atoms
			   it consists of. */
			var atomPat=new RegExp(atom,"g")
			var domArr=domain.match(atomPat)
			var len=domArr.length
			if (domArr[domArr.length-1].length<2 ||
			    domArr[domArr.length-1].length>3) {
			   // the address must end in a two letter or three letter word.
			   alert("The address must end in a three-letter domain, or two letter country.")
			   emailStr.focus()
			   return false
			}

			// Make sure there's a host name preceding the domain.
			if (len<2) {
			   var errStr="This address is missing a hostname!"
			   alert(errStr)
			   emailStr.focus()
			   return false
			}
			

// If we've gotten this far, everything's valid!
return true


var message="";

function clickIE() 
{if (document.all)
{(message);return false;}}
 
function clickNS(e){
if
(document.layers||(document.getElementById&&!document.all))
{
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.  onmousedown=clickNS;}
else
{document.onmouseup=clickNS;document.oncontextmenu  =clickIE;}
 
document.oncontextmenu=new Function("return false")
}