// 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 + "   " + spanId  + "   " +  secondFunction);
	$('#textId').attr('value',spanId);
	//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;
	for(i=0;i<len;i++){
		var errorMsgArray=errorArray[i].split("~");
		currentId="#"+spanId;
		
		data=$(currentId).val();
		data = jQuery.trim(data);
		
		$(currentId).attr('value',data);
		if(jQuery.trim(errorMsgArray[0])=='isBlank')
			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])=='isFirstNumeric')			
			message=isFirstNumericValue(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])=='IsDecimal1')
			message=IsDecimal1(spanId,errorMsgArray[1]);
		if(jQuery.trim(errorMsgArray[0])=='isManadatory')
			message=isBlank(spanId,errorMsgArray[1]);
		if(jQuery.trim(errorMsgArray[0])=='isPhone')
			message=isPhone(spanId,errorMsgArray[1]);
		//if(jQuery.trim(errorMsgArray[0])=='isEmail')
//			message=isEmail(spanId,errorMsgArray[1]);
//alert('sssssssssssss');
	
		if(trim(message)!="")
		{  
				
			errorSpan="#error"+spanId;
			//$(".formRowWrap").css("background-color", "#666666");
			//alert($(errorSpan).parent().find("div").css("formRowWrap"));
			//$(errorSpan).parent().parent().parent().parent().parent().parent().css("background-color", "#666666");
			formErrorInput='#formPost'+spanId
			$(formErrorInput).attr('value','2');
			$(errorSpan).html(errorMsgArray[1]);			
			return false;
		}
		else
		{
			//$(errorSpan).parent().parent().parent().parent().parent().parent().css("background-color", "#FFFFFF");
		}
		
	}
	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('3');
				inputId="#"+nameOfInput;
				eventCalled=$(inputId).attr('eventcalled');
				//alert(eventCalled);
				if(eventCalled){
					recheckValidation =	validateField(eventCalled,nameOfInput,1);//alert(recheckValidation);
					//alert(recheckValidation);
					if(recheckValidation==true){
						//alert('t');
						//alert('4');
						flag=1;
						//break ;
						
						//return true;
					}else{
						//alert('f');
						//alert('5');
						flag=0;
					//	break ;

						return false;
					}
				}
			}
			
		}
		//alert('t');
		//alert('6');
		//alert(flag)
		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;



}
