/*
To focus on the next element considering the maximum length/enter key press /tab key press event of the form element starts here
thisForm=Name of the form containing the concerned element
thisElement=this i.e. the form element using this function
thisEvent=event, here it's onkeypress event
MaxLngth=max length set for the form element
*/
function nextFocusWithMaxLength(thisForm,thisElement,thisEvent,MaxLngth)
{
var kCode = (navigator.appName == "Netscape") ? thisEvent.which : thisEvent.keyCode
txtVal=thisElement.value;
txtName=thisElement.name;
frmName=thisForm.name;
tLength=parseInt(thisElement.value.length)
frmLength=parseInt(document.forms.length);
for(p=0;p < frmLength;p++)
{
if(document.forms[p].name==frmName)
{
elemntLength=parseInt(document.forms[p].elements.length)
	for(i=0;i<elemntLength;i++)
	{
		if(document.forms[p].elements[i].name == txtName)
		{
			for(k=0;k < tLength;k++)
			{
			j=i+1;
				if( (kCode !=8) && (kCode !=46))
				{
						nxtElmnt=document.forms[p].elements[j].name;
						if( (thisElement.value.length == MaxLngth) || (kCode ==9) || (kCode ==13))
						{
							document.forms[p][nxtElmnt].focus();
							break;
						}
				}
			}
		}
	}
}
}
}
//To focus on the next element considering the maximum length/enter key press /tab key press event of the form element ends




//Function to Validate  Email starts here
function chktxtEmail(txtEmail)
{
			var vCount=0; //Global variable to check the number of @s.
			var invalid="~!#$%^&*()`<>,;:'\"/?[]{}";
			var dom=txtEmail.substring(txtEmail.indexOf("@"),txtEmail.length);
			vLen=parseInt(txtEmail.length);
			lastchar=txtEmail.substring(vLen-1,vLen)
			vLastDecPosn=txtEmail.lastIndexOf(".")
			charsAftrDec=txtEmail.substring(vLastDecPosn+1)
			charsAftrDecLen=charsAftrDec.length
			
				if (txtEmail.length<5)
					{
						return false;
					}
				else if(txtEmail.indexOf("@")==-1) 
					{
						return false;
					}
				else if(txtEmail.charAt(0)=="@")
					{
						return false;
					}
					
				if(txtEmail.indexOf(".")==-1) 
					{
						return false;
					}
				else if(txtEmail.charAt(0)==".")
					{
						return false;
					}
				else if(dom.indexOf(".")-dom.indexOf("@")<2)
					{
						return false;
					}
				else if(txtEmail.indexOf(".")==txtEmail.length)
					{
						return false;
					}
				else if( (lastchar==".")|| (lastchar=="@"))
					{
						return false;
					}
				else if(charsAftrDecLen < 2)
					{
						return false;
					}
				for(var i=0;i<txtEmail.length;i++)
					{
					firstChar=txtEmail.charAt(i)
					secChar=txtEmail.charAt(i+1)
					if(txtEmail.charAt(i) == "@") vCount++;
					if(invalid.indexOf(txtEmail.substring(i,i+1))!=-1)
						{
						return false;
						}
					else if(txtEmail.substring(i,i+1)==" ")
						{
						return false;
						}
					else if( ( (firstChar =="@") && (secChar =="@")) || ((firstChar ==".") && (secChar ==".")))
						{
						return false;
						}
					else if(vCount > 1)
						{
						return false;
						}
					}
}
//Function to Validate  Email ends here



//Function to Validate  URL starts here
function chktxtURL(txtURL)
{
			var vCount=0; //Global variable to check the number of .s.
			var invalid="~!#$%^&*()`<>,;'\"?[]{}@";
			vLen=parseInt(txtURL.length);
			lastchar=txtURL.substring(vLen-1,vLen)
			vLastDecPosn=txtURL.lastIndexOf(".")
			charsAftrDec=txtURL.substring(vLastDecPosn+1)
			charsAftrDecLen=charsAftrDec.length
			chkHTTP=txtURL.substring(0,4)
			chkHTTPlower=chkHTTP.toLowerCase();//To get http
			chkHTTPSlower=txtURL.substring(0,5).toLowerCase(txtURL.substring(0,5));//To get https
			colonCharPosition=txtURL.charAt(4);
			frstSlashCharPosition=txtURL.charAt(5);
			secondSlashCharPosition=txtURL.charAt(6);
			charAfterHTTP=txtURL.substring(4,7);
			charAfterHTTPS=txtURL.substring(5,8);
					
				
				if (txtURL.length < 5)
				{
				return false;
				}
				if( (txtURL.indexOf(":")!=-1) && ( (chkHTTPlower !='http')  ) )
				{
				return false;
				}
				/*
				if( (txtURL.indexOf("/")!=-1) && ( (chkHTTPlower !='http')  ) )
				{
				return false;
				}
				*/
				if( (chkHTTPSlower =='https') && (charAfterHTTPS !='://'))
				{
				return false;
				}
				else if( (chkHTTPSlower !='https') && (chkHTTPlower =='http') && (charAfterHTTP !='://') )
				{
				return false;
				}

				if(txtURL.indexOf(".")==-1) 
					{
						return false;
					}
				else if(txtURL.charAt(0)==".")
					{
						return false;
					}
				else if(txtURL.indexOf(".")==txtURL.length)
					{
						return false;
					}
				else if(lastchar==".")
					{
						return false;
					}
				else if(charsAftrDecLen < 2)
					{
						return false;
					}
				for(var i=0;i<parseInt(txtURL.length);i++)
					{
					firstChar=txtURL.charAt(i)
					secChar=txtURL.charAt(i+1)
						if(txtURL.charAt(i) == ".") vCount++; 
						if(invalid.indexOf(txtURL.substring(i,i+1))!=-1)
							{
							return false;
							}
						else if(txtURL.substring(i,i+1)==" ")
							{
							return false;
							}
						else if( ( (firstChar ==".") && (secChar == ".") ) )
							{
							return false;
							}
						else if( (firstChar==':') && (i > 5) )
							{
							return false;
							}
						/*
							else if( (firstChar=='/') && ( i > 7) )
							{
							return false;
							}
						*/
				}
					if(vCount < 1)
							{
							return false;
							}
}
//Function to Validate URL ends here


//Function to trim a given text starts here
function TrimText(srcString)
{
	// Code for Trimming Text.
	var source
	var startIndex
	var endIndex
	var strLength
	var i
	source = srcString;
	strLength = source.length;
	for(i=0;i<=(strLength-1);i++)
	{
		if (source.substr(i,1) != " ")
		{
			startIndex = i;
			break;
		}
	}
	for(i=(strLength-1);i>=0;i--)
	{
		if (source.substr(i,1) != " ")
		{
			endIndex = i;
			break;
		}
	}
	var result;
	result = source.substring(startIndex,endIndex+1);
	return result;
}
//Function to trim a given text ends here




//Function to Validate entry for small braces , hypen and numbers starts here
function chkHypen_Brace_Number(str)
{
//variable to check the number of (,),-
vCountStartBracket=0;
vCountEndBracket=0;
vCountHypen=0;
txtVal=str;
			var invalid="~!#$%^=.|_&*`<>;:'\"/?[]{}@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
			vLen=parseInt(txtVal.length);
			firstElement=txtVal.charAt(0);
			lastElement=txtVal.substring(vLen-1,vLen)
						
				if (vLen <7)
					{
						return false;
					}
				else if( (firstElement==")") || (firstElement=="-") || (lastElement =="(") || (lastElement =="-") )
					{
						return false;
					}
				else if( (txtVal.indexOf("(")!=-1) && ((txtVal.indexOf(")")==-1)) )
					{
						return false;
					}
				else if( (txtVal.indexOf(")")!=-1) && ((txtVal.indexOf("(")==-1)) )
					{
						return false;
					}
				for(var i=0;i<parseInt(txtVal.length);i++)
					{
					firstChar=txtVal.charAt(i)
					secChar=txtVal.charAt(i+1)
						if(txtVal.charAt(i) == "(") vCountStartBracket++; 
						else if(txtVal.charAt(i) == ")") vCountEndBracket++; 
						else if( txtVal.charAt(i) == "-") vCountHypen++; 
						if(invalid.indexOf(txtVal.substring(i,i+1))!=-1)
							{
							return false;
							}
						else if(  ((firstChar ==")")&&(secChar == ")"))    ||   ((firstChar =="(")&&(secChar == ")"))   ||   ((firstChar =="(")&&(secChar == "("))  ||   ((firstChar ==")")&&(secChar == "(")) ||  ((firstChar =="-")&&(secChar == "-"))  ||  ((firstChar =="-")&&(secChar == "-"))    ||  ((firstChar =="-")&&(secChar == ")"))                      )
							{
							return false;
							}
					}
					if( (vCountStartBracket >1) ||   (vCountEndBracket >1) || ( vCountHypen >3) )
							{
							return false;
							}
}
//Function to Validate entry for small braces , hypen and numbers ends here



//Function to find screen resolution starts
function resolutionChk()
{
    screenwidth=window.screen.width;
	screenheight=window.screen.height; 
	resolution=screenwidth+"x"+screenheight;
}
//Function to find screen resolution ends



//Allowing user input to contain only numbers, letters and underscore starts
function chkUserName(userName)
{
			var valid="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
			var firstChar=userName.charAt(0);
			if( (firstChar=="_") || (!isNaN(firstChar))  )
			{
			return false;
			}
			for(var i=0;i<userName.length;i++)
			{
				if(valid.indexOf(userName.substring(i,i+1))==-1)
				{
				return false;
				}
				else if(userName.substring(i,i+1)==" ")
				{
				return false;
				}
			}
}
//Allowing user input to contain only numbers, letters and underscore ends


//Function to hide and display toolTip layer starts here
//Global variable
var firstPosn;
function showToolTip(object,offset,linkTopPosn)
{ 
	if (document.layers && document.layers[object] != null)
	{
	firstPosn=parseInt(document.layers[object].pageX);
	document.layers[object].pageX =document.layers["linkDiv"].pageX + offset;
	document.layers[object].pageY =document.layers["linkDiv"].pageY + linkTopPosn;
	document.layers[object].bgColor='#ffffef' 
	document.layers[object].visibility = 'visible'; 
	}
}
function hide(object) 
{ 
	if (document.layers && document.layers[object] != null)
	{
	document.layers[object].visibility = 'hidden'; 
	document.layers[object].pageX=firstPosn;
	}
}
//Function to hide and display toolTip layer ends here


//Function to restrict TextArea Length starts************
//eg:onKeyDown="checkLength(this,10);" onKeyUp="checkLength(this,10);"
function checkLength(field,maxlimit,eventName) 
{
	if (field.value.length > maxlimit) // if too long...trim it!
	{
	if( (eventName=='blur')||(eventName=='focus') )
	alert("You cannot enter characters more than "+maxlimit)
	field.value = field.value.substring(0, maxlimit);
	field.focus();
	}
}
//Function to restrict TextArea Length ends************


//Function to hide and display window size starts
//Global variable
var N6 = (document.getElementById && !document.all) ? true : false; //To determine netscape 6
function show(object)
{
	if (document.layers && document.layers[object] != null)
	{
	document.layers[object].visibility = 'visible'; 
	document.layers[object].pageX =115
	document.layers[object].pageY =400
	}
	else if (document.all) 
	{
	document.all[object].style.visibility = 'visible'; 
	document.all[object].style.posLeft = 130
	document.all[object].style.posTop = 430
	}
	else if(N6)
	{
	document.getElementById(object).style.left = 115
	document.getElementById(object).style.top = 440
	document.getElementById(object).style.bgColor='#ffffef' 
	document.getElementById(object).style.visibility="visible";
	}
}

function hide(object) 
{ 
	if (document.layers && document.layers[object] != null)
	{
	document.layers[object].visibility = 'hidden'; 
	}
	else if (document.all) 
	{
	document.all[object].style.visibility = 'hidden'; 
	}
	else if(N6)
	{
	document.getElementById(object).style.visibility="hidden";
	}

}
//Function to hide and display window size ends


//function to check MSIE version starts....
function msieversion() 
{
        var ua = window.navigator.userAgent
        var msie = ua.indexOf ( "MSIE " )
        if ( msie > 0 )         // is Microsoft Internet Explorer; return version number
                return parseInt ( ua.substring ( msie+5, ua.indexOf ( ".", msie ) ) )
        else
                return 0        // is other browser
}
//function to check MSIE version ends....


//function to check the phone entry while typing starts....
function chkPhoneEntry(t,evt) 
{
	var isNav = (navigator.appName.indexOf("Netscape") != -1);
	var isIE = (navigator.appName.indexOf("Microsoft") != -1);
	var isIE4 = (msieversion() <=4);

	var agt=navigator.userAgent.toLowerCase();
	var isMac = (agt.indexOf("mac")!=-1);

	if (isMac) 
	{
	return true;
	}

	if (isIE) 
	{

        if (isIE4 == true) 
		{
        var keycode = window.event.keyCode;
        var pos     = t.value.length + 1;

        if (pos == 1) return true;
        if (pos == 2) return true;
        if (pos == 3) return true;
        if (pos == 4) return true;
        if (pos == 5) return true;
        if (pos == 6) return true;
        if (pos == 7) return true;
        if (pos == 8) return true;
        if (pos == 9) return true;
        if (pos == 10) return true;
        if (pos == 11) return true;
        if (pos == 12) return true;
        if (pos == 13) return true;
        if (pos == 14) return true;
        if (keycode == 13) return true;

        return false;

        } 
		else 
		{
        var keycode = window.event.keyCode;
        var shift   = window.event.shiftKey;
        var ctrl    = window.event.ctrlKey;
        var alt     = window.event.altKey;
        var digit   = (!shift && !ctrl && !alt && keycode >= 48 && keycode <= 57);
        var lparen  = (shift  && !ctrl && !alt && keycode == 40);
        var rparen  = (shift  && !ctrl && !alt && keycode == 41);
        var space   = (!shift && !ctrl && !alt && keycode == 32);
        var dash    = (!shift && !ctrl && !alt && keycode == 45);
        var slash   = (!shift && !ctrl && !alt && keycode == 47);

        var pos     = t.value.length + 1;

        if (keycode == 13) return true; 

        if (!lparen && !rparen && !space && !dash && !digit) return false;

        if (pos == 1  && lparen) return true;
        if (pos == 1  && digit) { t.value = '('; return true; }

        if (pos == 2  && digit) return true;
        if (pos == 3  && digit) return true;
        if (pos == 4  && digit) return true;

        if (pos == 5  && rparen) { t.value += ') '; return false; }
        if (pos == 5  && dash)   { t.value += ') '; return false; }
        if (pos == 5  && slash)  { t.value += ') '; return false; }
        if (pos == 5  && space)  { t.value += ') '; return false; }
        if (pos == 5  && digit)  { t.value += ') '; return true; }

        if (pos == 6  && space) return true;
        if (pos == 6  && digit) { t.value += ' '; return true; }

        if (pos == 7  && digit) return true;
        if (pos == 8  && digit) return true;
        if (pos == 9  && digit) return true;

        if (pos == 10 && dash) return true;
        if (pos == 10 && space) { t.value += '-'; return false; }
        if (pos == 10 && digit) { t.value += '-'; return true; }

        if (pos == 11 && digit) return true;
        if (pos == 12 && digit) return true;
        if (pos == 13 && digit) return true;
        if (pos == 14 && digit) return true;

		return false;

        }

	}
}
//function to check the phone entry while typing ends....