
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
checked = false;

//Onmouserover & Onmouseout --Starts here
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//Onmouserover & Onmouseout --Ends here


//Alpha Validation --Starts here
function alpha(alphane)
{
	var value = alphane;
	for(var j=0; j<value.length; j++)
	{
	 	var alphaa = value.charAt(j);
		var hh = alphaa.charCodeAt(0);
		if((hh > 64 && hh<91) || (hh > 96 && hh<123)){
		}
		else
			return false;		
	}
 	return true;
}
//Alpha Validation --Ends here

//Alpha with space Validation --Starts here
function alphawithspace(alphane)
{
	var first= '',next = '';
	var value = alphane;
	for(var j=0; j<value.length; j++)
	{
	 	var alphaa = value.charAt(j);
		var hh = alphaa.charCodeAt(0);
		if((hh > 64 && hh<91) || (hh > 96 && hh<123)|| (hh == 32))
		{
			if(hh==32)
			{	
				if(first == '')				
					first = j				
				else				
					next = j				
					
				if(next == (first+1))				
					return false;
			}
			else				
				first = '';	
		}
		else			  
			return false;		
	}
 	return true;
}
//Alpha with space Validation --Ends here



//Numeric Validation --Starts here
function numeric(alphane)
{
	var value = alphane;
	for(var j=0; j<value.length; j++)
	{
	 	var alphaa = value.charAt(j);
		var hh = alphaa.charCodeAt(0);
		if((hh > 47 && hh<59)){
		}
		else		  
			return false;		
	}
 	return true;
}
//Numeric Validation --Ends here


//Alpha Numeric Validation --Starts here
function alphanumeric(alphane)
{
	var value = alphane;
	for(var j=0; j<value.length; j++)
	{
	 	var alphaa = value.charAt(j);
		var hh = alphaa.charCodeAt(0);
		if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123)){
		}
		else		
			return false;		
	}
 	return true;
}
//Alpha Numeric Validation --Ends here



//Alpha Numeric With Space Validation --Starts here
function alphanumericwithspace(alphane)
{
	var first = '', next = '';
	var value = alphane;
	for(var j=0; j<value.length; j++)
	{
	 	var alphaa = value.charAt(j);
		var hh = alphaa.charCodeAt(0);
		if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || (hh == 32))
		{
			if(hh==32)
			{	
				if(first == '')				
					first = j				
				else				
					next = j				
					
				if(next == (first+1))				
					return false;
			}
			else				
				first = '';				
		}
		else		  		
			return false;		
	}	
 	return true;
}
//Alpha Numeric With Space Validation --Ends here


//check all checkboxes -- Starts here
function checkAll(theElement) 
{
     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++)
	 {
      	if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
	  		theForm[z].checked = theElement.checked;
	  	}
     }
}
//check all checkboxes -- Ends here

//uncheck checkall checkboxe -- Ends here
function uncheckparent(theElement)
{
	var el_collection=theElement.form;	
	var count = 6;
	if(el_collection.length > 0)
	{
		for (c = 0;c<el_collection.length;c++)
		{
			if(el_collection[c].checked == false)
				document.getElementById("checkall").checked = false;
			if(el_collection[c].checked == true)
				count++;
		}
		
		if(count == el_collection.length)
			document.getElementById("checkall").checked = true;
		else
			document.getElementById("checkall").checked = false;
	}
	else
		document.getElementById("checkall").checked = el_collection.checked;
}
//uncheck checkall checkboxe -- Ends here

//firstCaps --starts here
var name,temp1,temp2;
function firstCaps(ref)
{
	if(ref.value!='')
	{
		name=ref.value;
		temp1=name.substring(0,1);
		if(name.length>1)
		{
			temp2=name.substring(1);
			ref.value=temp1.toUpperCase()+temp2;
		}
		else{
			ref.value=temp1.toUpperCase();
		}
	}
}
//firstCaps --ends here

//isSelected --ends here 
function isSelected(value) {
	var result = true;
		
	if (value == "-1" || value == "0") {
		result = false;
	}
	else{
		result = true;    
	}
return result;
}
//isSelected --ends here

//Email Id validation -- starts here
function checkMailId(mailid)
{
	var arr = new Array('.com','.net','.org','.biz','.coop','.info','.museum','.name','.pro','.edu','.gov','.int','.mil','.ac','.ad','.ae','.af','.ag','.ai',
	'.al','.am','.an','.ao','.aq','.ar','.as','.at','.au','.aw','.az','.ba','.bb','.bd','.be','.bf','.bg','.bh','.bi','.bj','.bm','.bn','.bo','.br','.bs',
	'.bt','.bv','.bw','.by','.bz','.ca','.cc','.cd','.cf','.cg','.ch','.ci','.ck','.cl','.cm','.cn','.co','.cr','.cu','.cv','.cx','.cy','.cz','.de',
	'.dj','.dk','.dm','.do','.dz','.ec','.ee','.eg','.eh','.er','.es','.et','.fi','.fj','.fk','.fm','.fo','.fr','.ga','.gd','.ge','.gf','.gg','.gh',
	'.gi','.gl','.gm','.gn','.gp','.gq','.gr','.gs','.gt','.gu','.gv','.gy','.hk','.hm','.hn','.hr','.ht','.hu','.id','.ie','.il','.im','.in','.io',
	'.iq','.ir','.is','.it','.je','.jm','.jo','.jp','.ke','.kg','.kh','.ki','.km','.kn','.kp','.kr','.kw','.ky','.kz','.la','.lb','.lc','.li','.lk',
	'.lr','.ls','.lt','.lu','.lv','.ly','.ma','.mc','.md','.mg','.mh','.mk','.ml','.mm','.mn','.mo','.mp','.mq','.mr','.ms','.mt','.mu','.mv','.mw',
	'.mx','.my','.mz','.na','.nc','.ne','.nf','.ng','.ni','.nl','.no','.np','.nr','.nu','.nz','.om','.pa','.pe','.pf','.pg','.ph','.pk','.pl','.pm',
	'.pn','.pr','.ps','.pt','.pw','.py','.qa','.re','.ro','.rw','.ru','.sa','.sb','.sc','.sd','.se','.sg','.sh','.si','.sj','.sk','.sl','.sm','.sn',
	'.so','.sr','.st','.sv','.sy','.sz','.tc','.td','.tf','.tg','.th','.tj','.tk','.tm','.tn','.to','.tp','.tr','.tt','.tv','.tw','.tz','.ua','.ug',
	'.uk','.um','.us','.uy','.uz','.va','.vc','.ve','.vg','.vi','.vn','.vu','.ws','.wf','.ye','.yt','.yu','.za','.zm','.zw'); 

	var mai = mailid;
	var val = true;

	var dot = mai.lastIndexOf(".");
	var ext = mai.substring(dot,mai.length);
	var at = mai.indexOf("@");
	var dom = dot - at;
	var sp = mai.indexOf(" ");

	if(dom >= 4 && at >1 && sp == -1)
	{
		for(var i=0; i<arr.length; i++)
		{
			if(ext == arr[i])
			{
				val = true;
				break;
			} 
			else			
				val = false;
			
		}
		if(val == false)			
			return false;		
	}
	else		
		return false;
			
	return true;
}
//Email Id validation -- ends here


//Alpha Numeric with Space Hypen Validation --Starts here
function alphanumericwithspacehypen(alphane)
{
	var first= '',next = '';
	var value = alphane;
	for(var j=0; j<value.length; j++)
	{
	 	var alphaa = value.charAt(j);
		var hh = alphaa.charCodeAt(0);
		if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || hh == 45 || hh == 32)
		{
			if(hh==32)
			{	
				if(first == '')				
					first = j				
				else				
					next = j				
					
				if(next == (first+1))				
					return false;
			}
			else				
				first = '';	
		}
		else 
			return false;		
	}
 	return true;
}
//Alpha Numeric Space Hypen Validation --Ends here

//control refresh action--starts here
/*function checkKeyCode(evt)
{	
	var evt = (evt) ? evt : ((event) ? event : null);
	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
	if(event.keyCode==116)
	{
		evt.keyCode=0;
		return false
	}
}
document.onkeydown=checkKeyCode;
document.onmouseup=checkKeyCode;*/
//control refresh action--ends here


//For Default time format(HH:MM)--starts here
function clearField(formName,fieldName)
{
	var fieldValue = document.getElementById(fieldName).value;
	var el_collection=eval("document.forms."+formName+"."+fieldName);
	if(fieldValue != '' && fieldValue == 'HH:MM')
		el_collection.value = "";
}
//For Default time format(HH:MM)--ends here

//Image file upload--starts here
function isValidImageFormat(imageFormat){
	if (!/(\.(gif|jpg|jpeg))$/i.test(imageFormat)){		
		return false;
	}
	return true;
}
//Image file upload--ends here

//Alpha Numeric With Hypen Validation --Starts here
function alphanumericwithhypen(alphane)
{
	var value = alphane;
	for(var j=0; j<value.length; j++)
	{
	 	var alphaa = value.charAt(j);
		var hh = alphaa.charCodeAt(0);
		if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || hh == 45)
		{
		}
		else	
		{  
			 return false;
		}
	}
 	return true;
}
//Alpha Numeric With Hypen Validation --Ends here

//Numeric With Hypen Validation --Starts here
function numericwithhypen(alphane)
{
	var value = alphane;
	for(var j=0; j<value.length; j++)
	{
	 	var alphaa = value.charAt(j);
		var hh = alphaa.charCodeAt(0);
		if((hh > 47 && hh<59) || hh == 45 || hh == 43)
		{
		}
		else	
		{  
			 return false;
		}
	}
 	return true;
}
//Numeric With Hypen Validation --Ends here

function alphawithcomma(alphane)
{
	var first= '',next = '';
	var value = alphane;
	for(var j=0; j<value.length; j++)
	{
	 	var alphaa = value.charAt(j);
		var hh = alphaa.charCodeAt(0);
		if((hh > 64 && hh<91) || (hh > 96 && hh<123) || hh == 44)
		{
			if(hh==32)
			{	
				if(first == '')				
					first = j				
				else				
					next = j				
					
				if(next == (first+1))				
					return false;
			}
			else				
				first = '';	
		}
		else 
			return false;		
	}
 	return true;
}

function alphanumericwithspacedot(alphane)
{
	var first = '', next = '';
	var value = alphane;
	for(var j=0; j<value.length; j++)
	{
	 	var alphaa = value.charAt(j);
		var hh = alphaa.charCodeAt(0);
		if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || (hh == 32) || (hh == 46))
		{
			if(hh==32)
			{	
				if(first == '')				
					first = j				
				else				
					next = j				
					
				if(next == (first+1))				
					return false;
			}
			else				
				first = '';				
		}
		else		  		
			return false;		
	}	
 	return true;
}

function alphawithspacehypendot(alphane)
{
	var first= '',next = '';
	var value = alphane;
	for(var j=0; j<value.length; j++)
	{
	 	var alphaa = value.charAt(j);
		var hh = alphaa.charCodeAt(0);
		if((hh > 64 && hh<91) || (hh > 96 && hh<123) || hh == 45 || hh == 32 || hh == 46)
		{
			if(hh==32)
			{	
				if(first == '')				
					first = j				
				else				
					next = j				
					
				if(next == (first+1))				
					return false;
			}
			else				
				first = '';	
		}
		else 
			return false;		
	}
 	return true;
}

function openTerms(url)
{
	url = url + "/TermsAndConditions.jsp";	
	window.open(url,'Preview','toolbars=no,location=no,directories=no,status=no,scrollbars=1,menubar=0,resizable=0,copyhistory=no,top=10,left=10,width=420,height=500'); 
}


function disableEnterKey(e)
{
     var key;      
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox      

     return (key != 13);
}


function showImages(url, userID, photo1, photo2, fullname)
{
	url = url + "/PreviewPhoto.jsp?userID="+userID+"&photo1="+photo1+"&photo2="+photo2+"&name="+fullname+""; 
	window.open(url,'Preview','toolbars=no,location=no,directories=no,status=no,scrollbars=1,menubar=0,resizable=0,copyhistory=no,top=10,left=10,width=310,height=500'); 
}

function toggle(id) {
	var el = document.getElementById(id);
	if(el.style.display=='none' ){
		el.style.display = '';
	}else{
		el.style.display = 'none';
	}
}






