// JavaScript Document

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function onlyNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = trim(textBox.value);
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}


function ErrorHighlight(obj)
	{		if(obj.type=="text" || obj.type=="password" || obj.type=="file")
			{	
				obj.className="barodaHighlight";
				
			}
			if(obj.type=="textarea")
			{
				obj.className="barodaHighlightTextarea";
				
			}
			if(obj.type=="checkbox")
			{
				obj.style.backgroundColor="#FFE4E1";
				
			}
	}
	function ErrorNormal(obj)
	{		if(obj.type=="text" || obj.type=="password" || obj.type=="file")
			{	//document.regform.elements(i).style.backgroundColor="#ffffff";
				obj.className="barodaNormal";
			}
			if(obj.type=="textarea")
			{	
				obj.className="barodaNormalTextarea";
			}
			if(obj.type=="checkbox")
			{
				obj.style.backgroundColor="#F7f7f7";
			}
	}
	
	function ClearError(objform)
	{
		for(i=0;i<objform.elements.length;i++)
		{	obj=objform.elements[i];
			if(obj.type=="password"||obj.type=="file" || obj.type=="text"||obj.type=="textarea"||obj.type=="checkbox")
			{	//alert(document.regform.elements(i).name+"  "+document.regform.elements(i).type);
				//document.regform.elements(i).style.backgroundColor="#ffffff";
				ErrorNormal(obj);
			}
			
		}
	}
	
	function checkEmail(obj)
	{	msg="";
		//RgExp= new 	RegExp("^[\\w\\W]+[\\w\.]*@[\\w\\W]+[\.][\\w\\W]+[\\w\\W\.]*[\\w\\W]+$");
		//"^\\w+[\\w\.-]*@\\w+\.\\w+[\\w\.]*\\w+$"
		RgExp= new RegExp("^\\w+[\\w\.-]*@[\\w-]+[\.]{1}[\\w]+([\.]{0,1}[\\w]+)*$");
		if (!RgExp.test(obj.value))
		{
			msg="- Enter valid Email.\n";
		}
		return msg;
	}
	
	function checkDate(d,m,y)
	{	msg="";
		if (m.value!=2 && m.value!=1 && m.value!=3 && m.value!=5 && m.value!=7 && m.value!=8 && m.value!=10 && m.value!=12 )
		{
			if(d.value>30)
			{	msg="- Select Vaild Date.\n";
			}
		}
		else if (m.value==2)
		{	
			if((y.value%4)==0)
			{	if(d.value>29)
				{
					msg="- Select Vaild Date.\n";
				}
			}
			else 
			{	if(d.value>28)
				{
					msg="- Select Vaild Date.\n";
				}
			}
		}
		return msg;
	}
	function checkNum(obj,desc)
	{	msg="";
		RgExp= new RegExp("^\\d+$");
		if(!RgExp.test(obj.value))
		{
			msg="- Enter Numeric "+desc+"\n";
			//ErrorHighlight(obj);
			ErrorHighlight(obj);
		}
		
		return msg;
	}
	
	function checkNumMin(obj,val,desc)
	{	msg="";
		RgExp= new RegExp("^\\d+$");
		if(!RgExp.test(obj.value))
		{
			msg="- Enter Numeric "+desc+"\n";
			//ErrorHighlight(obj);
			ErrorHighlight(obj);
		}
		else if(parseInt(obj.value)<= parseInt(val) )
		{	
			msg="- Enter "+desc+" more than "+val+"\n";
			
			ErrorHighlight(obj);
			
		}
		
		return msg;
	}
	
	function checkPhone(obj,desc)
	{	msg="";
		RgExp= new RegExp("^\\d+([-\\s]*\\d+\\s*)*$");
		if(!RgExp.test(obj.value))
		{
			msg="- Enter proper "+desc+"\n";
			ErrorHighlight(obj);
		}
		
		return msg;
	}
	function checkURL(obj,desc)
	{	msg="";
		RgExp= new RegExp("^[\\w\\W]+[\.]+");
		if(!RgExp.test(obj.value))
		{
			msg="- Enter proper "+desc+".\n";
		}
		return msg;
	}
	function checkBlank(obj,desc)
	{	msg="";
		//RgExp= new RegExp("^[\\w\\W\\D]+[\\w\\W\\D ]*$");
		//RgExp= new RegExp("^[^\\s]+[\\w\\W\\D ]*$");
		RgExp= new RegExp("[^\\s]+");
		if(!RgExp.test(obj.value))
		{
			msg="- Enter "+desc+"\n";
			//ErrorHighlight(obj);
			ErrorHighlight(obj);
		}
		
		return msg;
	}
	function checkAlpha(obj,desc)
	{	msg="";
		//RgExp= new RegExp("^[a-zA-Z]+[ a-zA-Z]*$");
		RgExp= new RegExp("[a-zA-Z]+");
		
		if(!RgExp.test(obj.value))
		{
			msg="- Enter Alphabatical "+desc+"\n";
			//ErrorHighlight(obj);
			ErrorHighlight(obj);
		}
		
		return msg;
	}
	
	function checkMatch(obj1,obj2)
	{	msg="";
		if(obj1.value!=obj2.value)
		{
			msg="- the passwords entered do not match.\n";
			ErrorHighlight(obj1);
			ErrorHighlight(obj2);
		}
		
		return msg;
	}
	
	function checkAlphaNumLen(obj,len,desc)
	{	//specific Length and ALPHA NUMERIC value
		msg="";
		//RgExp= new RegExp("^[a-zA-Z]{1}[\\w ]{"+(len-1)+",}$");
		//RgExp= new RegExp("^[a-zA-Z]{1}[\\w]{"+(len-1)+",}$");
		RgExp= new RegExp("^[^\\s]{"+(len)+",}");
		if(!RgExp.test(obj.value))
		{
			msg="- "+desc+" must be atleast "+ len + " characters, without space.\n";
			ErrorHighlight(obj);
		}
		
		return msg;
	}
	
	function checkLen(obj,len,desc)
	{	//specific Length and ALPHA NUMERIC value
		msg="";
		//RgExp= new RegExp("^[\\w]{"+len+",}$");
		RgExp= new RegExp("^[^\\s]{"+(len)+",}");
		if(!RgExp.test(obj.value))
		{
			msg="- "+desc+" must be atleast "+ len + " characters.without space\n";
			ErrorHighlight(obj);
		}
		
		return msg;
	}
	
	function AltcheckAlphaNumLen(obj,len,desc)
	{	//specific Length and ALPHA NUMERIC value
		ErrorNormal(obj);
		//RgExp= new RegExp("^[a-zA-Z]{1}[\\w ]{"+(len-1)+",}$");
		RgExp= new RegExp("^[a-zA-Z]{1}[\\w]{"+(len-1)+",}$");
		if(!RgExp.test(obj.value))
		{
			msg="- "+desc+" must be more than "+ len + " characters.\n";
			ErrorHighlight(obj);
			alert(msg);
			obj.focus();
			return false;
		}
		
		return true;
	}
	
	function AltcheckBlank(obj,desc)
	{	//RgExp= new RegExp("^[\\w\\W\\D]+[\\w\\W\\D ]*$");
		RgExp= new RegExp("[^\\s]+");
		ErrorNormal(obj);
		if(!RgExp.test(obj.value))
		{
			alert("- Enter "+desc);
			ErrorHighlight(obj);
			obj.focus();
			return false;
		}
		else
		{
			return true;
		}
		
	}

	function setUsername()
	{
		window.opener.document.regform.username.value=document.set.selusername.value;
		window.close();
	}
	
	function checkChecked(obj1,obj2,desc)
	{	msg="";
		if(obj1.checked==false && obj2.checked==false)
		{
			msg="- Select "+desc+"\n";
			//obj1.style.backgroundColor=ErrColor;
			//obj2.style.backgroundColor=ErrColor;
			ErrorHighlight(obj1);
			ErrorHighlight(obj2);
		}
		return msg;
	}
	function checkCVFile()
	{ 	msg="";
		
		if ((document.regform.file1.value).length>0)
		{	//ext=document.regform.file1.value.substr(document.regform.file1.value.length-3,3);
			RgExp= new RegExp("(\.doc)|(\.rtf)|(\.pdf)|(\.txt)$");
			if (!RgExp.test(document.regform.file1.value))// (ext.toLowerCase() != "doc" && ext.toLowerCase() != "rtf" ){
			{
				msg="- only the following file types are accepted: .doc, .rtf, .pdf or .txt\n"
				ErrorHighlight(document.regform.file1);
			}
			
		}
		/*else if ((document.regform.cv.value).length<=0)
			{
				msg="- Fill the Paste Your CV column or Submit your Resume File.\n";
				ErrorHighlight(document.regform.cv);
			}*/
		return msg;
	}
	
	function checkFile(obj)
	{	msg="";
		RgExp= new RegExp("(\.jpg)|(\.gif)|(\.jpe)|(\.jpeg)|(\.bmp)|(\.png)$");
		if (!RgExp.test(obj.value))
		{
			msg="- Choose .jpg, .gif, .png or .bmp format of Logo file.";
			ErrorHighlight(obj);
			
		}
		return msg;
	}
	function preview()
	{	//chkfl=checkFile(document.regform.file1);
		chkfl="";
		if(chkfl=="")
		{	window.open(document.regform.file1.value,null,"status=no,toolbar=no,menubar=no,location=no");
		}
		else
		{	alert(chkfl);
			document.regform.file1.focus();
		}
		
	}
	
	function AltcheckEmail(obj)
	{	
		//RgExp= new 	RegExp("^[\\w\\W]+[\\w\\W\.]*@[\\w\\W]+[\.][\\w\\W]+[\\w\\W\.]*[\\w\\W]+$");
		RgExp= new RegExp("^\\w+[\\w\.-]*@[\\w-]+[\.]{1}[\\w]+([\.]{0,1}[\\w]+)*$");
		if (!RgExp.test(obj.value))
		{
			alert("- Enter valid Email.");
			return false;
		}
		return true;
	}
	
	function AltcheckDate(d,m,y)
	{	
		if (m.value!=2 && m.value!=1 && m.value!=3 && m.value!=5 && m.value!=7 && m.value!=8 && m.value!=10 && m.value!=12 )
		{
			if(d.value>30)
			{	alert("Select Vaild Date.");
				return false;
			}
			else
					return true;
		}
		else if (m.value==2)
		{	
			if((y.value%4)==0)
			{	if(d.value>29)
				{	alert("Select Vaild Date.");
					return false;
				}
				else
					return true;
			}
			else 
			{	if(d.value>28)
				{
					alert("Select Vaild Date.");
					return false;
				}
				else
					return true;
			}
		}
		else
			return true;
		
	}
	
function correctPNG()
   {
   for(i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = (img.style.cssText) ? img.style.cssText + ";" : ""
		 var floatOrBlock = "display:inline-block;"
		 var oAttribs = img.attributes;
		 for (var j=0; j<oAttribs.length; j++)
			{
			var oAttrib = oAttribs[j];
			if (oAttrib.nodeName == "align")
			   {
			   switch(oAttrib.nodeValue)
				  {
				  case "left"  : floatOrBlock = "float:left;"  ; break;
				  case "right" : floatOrBlock = "float:right;" ; break;
				  }
			    break;
			   }
            }
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 strNewHTML += " style=\"" + floatOrBlock + imgStyle 
		 strNewHTML += " width:" + img.width + "px; height:" + img.height + "px; "
	     strNewHTML += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'" + img.src + "\');\">"
		 strNewHTML += "</span>"; 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
   }

