// JavaScript Document
function removeHelpText(textValue,secondFunction){
//alert(textValue)
	currentInputId='#'+textValue;
	helpText=$(currentInputId).attr('title')
	v=$(currentInputId).val();
	if(v==helpText){
		$(currentInputId).attr('value','');
	}
		
	

	
}
function validateField(errorMsg,spanId,secondFunction){
	//alert(errorMsg);
	//validateField('isBlank~Enter User Name#isUserName~Please Enter Alphanumeric Values In User Name','userNameTxt',' checkValidUserName() ')
	//isBlank~Enter User Name# isUserName~Please Enter Alphanumeric Values In User Name----userNameTxt
	var errorArray = errorMsg.split("#");
	len=errorArray.length;
	
	//alert(len)
	var message="";
	for(i=0;i<len;i++){
		var errorMsgArray=errorArray[i].split("~");
		//alert(errorMsgArray)
		currentId="#"+spanId;
		
		data=$(currentId).val();
		data = jQuery.trim(data);
		
		$(currentId).attr('value',data);
		//alert(jQuery.trim(errorMsgArray[0]))
		if(jQuery.trim(errorMsgArray[0])=='isBlank' || jQuery.trim(errorMsgArray[0])=='isEmpty')
			message=isBlank(spanId,errorMsgArray[1]);
		if(jQuery.trim(errorMsgArray[0])=='isUserName')
			message=isUserName(spanId,errorMsgArray[1]);
		if(jQuery.trim(errorMsgArray[0])=='isCharacter')
			message=isCharacter(spanId,errorMsgArray[1]);
		if(jQuery.trim(errorMsgArray[0])=='isSpecialCharacter')
			message=isSpecialCharacter(spanId,errorMsgArray[1]);
		if(jQuery.trim(errorMsgArray[0])=='isFirstCharBlank')
			message=isFirstCharBlank(spanId,errorMsgArray[1]);
		if(jQuery.trim(errorMsgArray[0])=='isNumeric')
			message=isNumeric(spanId,errorMsgArray[1]);
		if(jQuery.trim(errorMsgArray[0])=='isEmail')
			message=isEmailValid(spanId,errorMsgArray[1]);
		if(jQuery.trim(errorMsgArray[0])=='isDecimal')
			message=isDecimal(spanId,errorMsgArray[1]);
		if(jQuery.trim(errorMsgArray[0])=='isDate')
			message=isDate(spanId,errorMsgArray[1]);
		if(jQuery.trim(errorMsgArray[0])=='isPhonrNumber')
			message=isPhonrNumber(spanId,errorMsgArray[1]);
		if(jQuery.trim(errorMsgArray[0])=='isSpaceExist')
			message=isSpaceExist(spanId,errorMsgArray[1]);
		if(jQuery.trim(errorMsgArray[0])=='IsDecimal1')
			message=IsDecimal1(spanId,errorMsgArray[1]);
		if(jQuery.trim(errorMsgArray[0])=='isValidateMarks')
			message=isValidateMarks(spanId,errorMsgArray[1]);	
		//if(jQuery.trim(errorMsgArray[0])=='isEmail')
//			message=isEmail(spanId,errorMsgArray[1]);
//alert(message);
//alert('sssssssssssss');
		if(message!="")
		   {  
			   errorSpan="#error"+spanId;
			   formErrorInput='#formPost'+spanId
			   $(formErrorInput).attr('value','2');
			   $(errorSpan).html(errorMsgArray[1]);
			   return false;
		   }
		
	}
	if(toString(secondFunction.length>3)){
		eval(secondFunction);
	}
	return true;
	
}

function removeError(spanId){
	errorSpan="#error"+spanId;
	$('#errorTr'+spanId).hide();
	formErrorInput='#formPost'+spanId
	$(formErrorInput).attr('value','1');
	$(errorSpan).html('');		
	

	
}
function validateCustomError(spanId,msg,status){
	
	var str=status;
	str=str.toUpperCase();
	   if(str=='FAIL'){
		   errorSpan="#error"+spanId;
		   formErrorInput='#formPost'+spanId
		   $(formErrorInput).attr('value','2');
		   $(errorSpan).html(msg);
		     $('#errorTr'+spanId).show();
	   }else{
		   errorSpan="#error"+spanId;
		   formErrorInput='#formPost'+spanId
		   $(formErrorInput).attr('value','1');
		   $(errorSpan).html('');
		   $('#errorTr'+spanId).hide();
	   }
	   
	   return;
}


function checkHelpText(textValue,secondFunction){
//alert(textValue)
	currentInputId='#'+textValue;
	helpText=$(currentInputId).attr('title')
	v=$(currentInputId).val();
	
	if(v.length==0){
		$(currentInputId).attr('value',helpText)
	}
	
	if( toString(secondFunction) != 1){
		eval(secondFunction);
	}
}

function validateForm(frmName)
{
	
	var flag=1;//alert('1'); return false;
	if(frmName)
	{
		var hi= $('#'
		+frmName+' input:hidden');
	}
	else
	{
		var hi= $('input:hidden');
	}
	hi.each(function(i, el)
	{
		hiddenType=$(el).attr('id');
		if(hiddenType)
			nameOfHidden = hiddenType.substring(0,8);
		else
			nameOfHidden = "";
		
		if(nameOfHidden=='formPost')
		{
			hiddenValue=$(el).val();
			nameOfInput = hiddenType.substring(8);
			//console.log(nameOfInput+'--'+hiddenValue);
			if(hiddenValue==2)
			{//console.log(nameOfInput+'here');
				//alert('2');
				errorSpan="#error"+nameOfInput;
				formErrorInput='#formPost'+nameOfInput
				$(formErrorInput).attr('value','2');
				//(formErrorInput).attr('value','2');
				//$(errorSpan).html('Enter Correct Value');
				inputId="#"+nameOfInput;
				$(inputId).focus()
				flag=0;
				return false;
			}
			else
			{//console.log('here2');
				//alert(nameOfInput);
				inputId="#"+nameOfInput;//alert(inputId);
				eventCalled=$(inputId).attr('eventcalled');
				//alert(eventCalled);
				if(eventCalled)
				{
					recheckValidation =	validateField(eventCalled,nameOfInput,1);//alert(recheckValidation);
					if(recheckValidation==true)
					{
						//alert('t');
						//alert('4');
						flag=1;
						//break ;
						//return true;
					}
					else
					{
						//alert('f');
						//alert('5');
						flag=0;
						//break ;
						return false;
					}
				}
			}
		}
		if(flag==1)
		return true;
		else
		return false;
	});
	/*var hi= $('input:hidden');
	hi.each(function(i, el) {
	hiddenType=$(el).attr('id');
	nameOfHidden = hiddenType.substring(0,8);
	//conole.log(nameOfHidden);
	if(nameOfHidden=='formPost'){
	hiddenValue=$(el).val();
	nameOfInput = hiddenType.substring(8);
	console.log(nameOfInput+'--'+hiddenValue);
	newname='#'+nameOfInput	;
	console.log(newname)
	if($(newname).attr('eventcalled')){	var f=$('#'+nameOfInput).attr('eventcalled');console.log(f)
	}
	}
	});
	*/
	//alert('7');
	if(flag==1)
	return true;
	else
	return false;
}


function checkSelect(selectID)
{

	currentInputId='#'+selectID;
	v=$(currentInputId).val();
	if(v=='')
	{
		document.getElementById('formPost'+selectID).value=2;
	}
	else
	{
		document.getElementById('formPost'+selectID).value=1;
		errorSpan="#error"+selectID;
		$('#errorTr'+selectID).hide();
		formErrorInput='#formPost'+selectID;
		$(formErrorInput).attr('value','1');
		$(errorSpan).html('');	
	}
	
}
