

/*Check file extension*/

function validateFileExtesion(argfileExtesionArray,theFileUpload)
{  
	var extensions = argfileExtesionArray;/*new Array("jpg","JPG","JPEG","jpeg","gif","GIF","png","bmp");  */
	var image_file = theFileUpload.value;  
	var image_length = theFileUpload.value.length;     
	var pos = image_file.lastIndexOf('.') + 1;
	var ext = image_file.substring(pos, image_length);  
	var final_ext = ext.toLowerCase();  
	
	for (i = 0; i < extensions.length; i++)  
	{  
		 if(extensions[i] == final_ext)  
		 {  
			return true;  
		 }  
	}  
	alert("You must upload an image file with one of the following extensions: \n"+ extensions.join(', ') +".");  
 	
	return false;  	
}
	
/*Check all textbox*/
function checkAllTextBoxInForm(theForm)
{
	allInputElement = theForm.getElementsByTagName("input");
	isFalse = true;
	
	msg= '';
	
	for(var i=0;i<allInputElement.length;i++)
	{
		if(allInputElement[i].type != "text" && allInputElement[i].type != "password")
			continue;
		else
		{
			isClass = false;
			
			if(((trim(allInputElement[i].value) == trim(allInputElement[i].title)) || trim(allInputElement[i].value) == '') && allInputElement[i].alt.indexOf('TextBox') > -1)
			{ 
				if(allInputElement[i].alt == "OldPasswordTextBox")
					msg += "Enter old password " +"\n";
				else if(allInputElement[i].alt == "PasswordTextBox")
					msg += "Enter password " +"\n";
				else if(allInputElement[i].alt == "ConfirmPasswordTextBox")
					msg += "Enter confirm password " +"\n";
				else
					msg += allInputElement[i].title + "\n";
				
				if(isFalse){allInputElement[i].focus();}
				isFalse = false;
				isClass = true;
			}
			else if(allInputElement[i].alt == 'EmailTextBox' && !checkEmail(allInputElement[i],true))
			{	
				
				if(isFalse){allInputElement[i].focus();}isFalse = false;
				msg += "Invalid E-mail Address! Please re-enter.\n";
				isClass = true;
			}
			else if((allInputElement[i].alt.indexOf('PasswordTextBox') > -1) && allInputElement[i].value.length < 4)
			{	
				if(isFalse){allInputElement[i].focus();}
				msg += "Your password have aleast 4 charactes !!.\n"; 
				isFalse = false;
				isClass = true;
			}
			else if(allInputElement[i].alt == 'ConfirmPasswordTextBox' && allInputElement[i-1].value != allInputElement[i].value)
			{	
				
				if(isFalse){allInputElement[i-1].focus();}
				msg += "Please enter password and confirm password must be same.\n<br>"; 
				isFalse = false;
				isClass = true;
			}
			else if(allInputElement[i].alt == 'PostCodeTextBox' && checkPostcode(allInputElement[i]))
			{	
				if(isFalse){allInputElement[i].focus();}
				msg += "Postcode has must be 6 to 9 number.\n"; 
				isFalse = false;
				isClass = true;
			}	
			try
			{
				if(isClass)
				{
					$("#span" + allInputElement[i].id.substr(3)).addClass("errorText");
				}
				else
					$("#span" + allInputElement[i].id.substr(3)).removeClass("errorText");
			}
			catch(e)
			{
				alert("span" + allInputElement[i].name +" is not found");
			}
		}
	}
	
	if(!isFalse && msg != '')
		alert(msg);
	else
	{
		for(var i=0;i<allInputElement.length;i++)
		{
			if(allInputElement[i].className == 'smalltextboxMsg')
			{
				if(!(allInputElement[i].alt!=''))allInputElement[i].value='';
				if(allInputElement[i].alt.indexOf('TextBox') == -1)allInputElement[i].value='';
			}
		}		
	}
	return isFalse;
}
function checkAllTextBoxInForm2(theForm)
{
	allInputElement = theForm.getElementsByTagName("input");
	isFalse = true;
	
	msg= '';
	
	for(var i=0;i<allInputElement.length;i++)
	{
		if(allInputElement[i].type != "text" && allInputElement[i].type != "password")
			continue;
		else
		{
			isClass = false;
			
			if(((trim(allInputElement[i].value) == trim(allInputElement[i].title)) || trim(allInputElement[i].value) == '') && allInputElement[i].alt.indexOf('TextBox') > -1)
			{ 
				if(allInputElement[i].alt == "OldPasswordTextBox")
					msg += "Enter old password " +"\n";
				else if(allInputElement[i].alt == "PasswordTextBox")
					msg += "Enter password " +"\n";
				else if(allInputElement[i].alt == "ConfirmPasswordTextBox")
					msg += "Enter confirm password " +"\n";
				else
					msg += allInputElement[i].title + "\n";
				
				if(isFalse){allInputElement[i].focus();}
				isFalse = false;
				isClass = true;
			}
			else if(allInputElement[i].alt == 'EmailTextBox' && !checkEmail(allInputElement[i],true))
			{	
				
				if(isFalse){allInputElement[i].focus();}isFalse = false;
				msg += "Invalid E-mail Address! Please re-enter.\n";
				isClass = true;
			}
			else if((allInputElement[i].alt.indexOf('PasswordTextBox') > -1) && allInputElement[i].value.length < 4)
			{	
				if(isFalse){allInputElement[i].focus();}
				msg += "Your password have aleast 4 charactes !!.\n"; 
				isFalse = false;
				isClass = true;
			}
			else if(allInputElement[i].alt == 'ConfirmPasswordTextBox' && allInputElement[i-1].value != allInputElement[i].value)
			{	
				
				if(isFalse){allInputElement[i-1].focus();}
				msg += "Please enter password and confirm password must be same.\n"; 
				isFalse = false;
				isClass = true;
			}
			else if(allInputElement[i].alt == 'PostCodeTextBox' && checkPostcode(allInputElement[i]))
			{	
				if(isFalse){allInputElement[i].focus();}
				msg += "Postcode has must be 6 to 9 number.\n"; 
				isFalse = false;
				isClass = true;
			}	
			try
			{
				if(isClass)
				{
					$("#span" + allInputElement[i].id.substr(3)).addClass("errorText");
				}
				else
					$("#span" + allInputElement[i].id.substr(3)).removeClass("errorText");
			}
			catch(e)
			{
				alert("span" + allInputElement[i].name +" is not found");
			}
		}
	}
	
	return msg;
	
}


/*Check Email*/
function checkEmail1(theTextBox,isSetFocus) 
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(theTextBox.value))
		return (true);
	if(isSetFocus)theTextBox.focus();
	return (false);
}
function checkEmail(string) 
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(string))
		return (true);
	else
		return (false);
}

/*Check Postcode*/
function checkPostcode(theTextBox)
{
	if(theTextBox.value.length < 6 || theTextBox.value.length >10 )
	{
		spanName = "span" + theTextBox.id.substr(3);
		document.getElementById(spanName).className = "errorText";
	}
	return (theTextBox.value.length < 6 || theTextBox.value.length >10)
}

/*Match Password*/
function macthPassword(thePasswordTextBox,theConfirmPasswordTextBox)
{
	//alert((theConfirmPasswordTextBox.value == thePasswordTextBox.value));
	if(theConfirmPasswordTextBox.value != thePasswordTextBox.value)
	{
		alert('Please enter password and confirm password must be same');	
		thePasswordTextBox.focus();
		lblname = "span" + thePasswordTextBox.id.substr(3);
		document.getElementById(lblname).className = "errorText";
		lblname = "span" + theConfirmPasswordTextBox.id.substr(3);
		document.getElementById(lblname).className = "errorText";
	}
	return (theConfirmPasswordTextBox.value == thePasswordTextBox.value);
}


/*Check all textarea in Form*/
function checkAllTextareaInForm(theForm)
{
	allTextarea = theForm.getElementsByTagName("textarea");
	isFalse = true;
	msg='';
	for(var i=0;i<allTextarea.length;i++)
	{
		if(((trim(allTextarea[i].value) == trim(allTextarea[i].title)) || trim(allTextarea[i].value) == '')  && allTextarea[i].title != '')
		{
			if(isFalse){allTextarea[i].focus();}
			msg += allTextarea[i].title + "\n";
			
			$("#span" + allTextarea[i].id.substr(3)).addClass("errorText");
			
			isFalse = false;
		}
		else
			$("#span" + allTextarea[i].id.substr(3)).removeClass("errorText");
	}
	if(!isFalse && msg != '')
		alert(msg);
	return isFalse;
}

function checkAllTextareaInForm2(theForm)
{
	allTextarea = theForm.getElementsByTagName("textarea");
	isFalse = true;
	msg='';
	for(var i=0;i<allTextarea.length;i++)
	{
		if(((trim(allTextarea[i].value) == trim(allTextarea[i].title)) || trim(allTextarea[i].value) == '')  && allTextarea[i].title != '')
		{
			if(isFalse){allTextarea[i].focus();}
			msg += allTextarea[i].title + "\n";
			
			$("#span" + allTextarea[i].id.substr(3)).addClass("errorText");
			
			isFalse = false;
		}
		else
			$("#span" + allTextarea[i].id.substr(3)).removeClass("errorText");
	}

	return msg;
}

/*Check Combobox in form*/
function checkAllComboBox(theForm,value)
{
	allSelectElement = theForm.getElementsByTagName("select");
	isFalse = true;
	msg= '';
	
	for(var i=0;i<allSelectElement.length;i++)
	{ 
		if(allSelectElement[i].value == value || allSelectElement[i].value == '')
		{			
			$("#span" + allSelectElement[i].id.substr(3)).addClass("errorText");
			if(isFalse){allSelectElement[i].focus();}
			msg += allSelectElement[i].title + "\n";
			isFalse = false;
		}
		else
			$("#span" + allSelectElement[i].id.substr(3)).removeClass("errorText");
	}
	if(!isFalse)alert(msg);
	return isFalse;
}

function checkAllComboBox2(theForm,value)
{
	allSelectElement = theForm.getElementsByTagName("select");
	isFalse = true;
	msg= '';
	
	for(var i=0;i<allSelectElement.length;i++)
	{ 
		if(allSelectElement[i].value == value || allSelectElement[i].value == '')
		{			
			$("#span" + allSelectElement[i].id.substr(3)).addClass("errorText");
			if(isFalse){allSelectElement[i].focus();}
			msg += allSelectElement[i].title + "\n";
			isFalse = false;
		}
		else
			$("#span" + allSelectElement[i].id.substr(3)).removeClass("errorText");
	}
	return msg;
}

/*Make only Number input textbox*/
function restrictAlphabet(evt)
{
	evt = (evt) ? evt : window.event;
    var charCode = (evt.which) ? evt.which : evt.keyCode;
	
    if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46 && (charCode < 36 || charCode > 41)) {
        status = "This field accepts numbers only.";
        return false;
    }
    status = "";
    return true;
}


/*Make only Number input textbox*/
function LimitTextBox(evt)
{
	
}

/*Make only Number input textbox*/
function calenderTextBox(argTextBox,evt)
{
	evt = (evt) ? evt : window.event;
    var charCode = (evt.which) ? evt.which : evt.keyCode;
	
    if (charCode == 46 || charCode == 8) 
	{
        argTextBox.value="";
    }
}


/*Check Combobox in form*/
function checkAllRadioButton(theForm)
{
	allInputElement = theForm.getElementsByTagName("input");
	isFalse = true;
	msg= '';
	
	for(var i=0;i<allInputElement.length;i++)
	{ 
		if(allInputElement[i].type == "radio")
		{
			j=i;
			while(true)
			{
				if(allInputElement[i].id != allInputElement[j].id)
					break;
				j++;
			}
			isMsg=false;
			for(k=0;k<=(j-i)-1;k++)
			{
				if(allInputElement[k+i].checked)
				{	isMsg=true;break;}
			}
			if(!isMsg)
			{
				if(isFalse){allInputElement[i].focus();}
				msg+=allInputElement[i].title+"\n";
				isFalse=false;
			}
			i+= (j-i)-1;
		}
	}
	if(!isFalse)alert(msg);
	return isFalse;
}

function ValidateForm(FormName)
{
	msg='';
	msg1='';
/*	$("#frmExperience > *").css('border','1px solid red');*/
	
	damiObj='';
	isFocus = true;
	damiRadio = new Array();
	$.each(FormName,
		function(i,obj)
		{
			msg1+=obj.type+"\t";
			isClass=false;
			switch(obj.type)
			{
				case "hidden":
					/*if(obj.id=="FCKeditor" && $.trim(obj.value) == "")
					{	msg += obj.title+"\n";
					alert(obj.id);
						isClass=true;
					}*/
					break;
				case "text":
				case "password":
					if(($.trim(obj.value) == $.trim(obj.title) || $.trim(obj.value) == '') && obj.alt.indexOf('TextBox') > -1)
					{
						switch(obj.alt)
						{
							case "OldPasswordTextBox":
								msg += "Enter old password \n";
								break;
							case "PasswordTextBox":
								msg += "Enter password " +"\n";
								break;
							case "ConfirmPasswordTextBox":
								
								msg += "Please verify your password again. " +"\n";
								break;
							default:
								msg += obj.title + "\n";
						}
						isClass=true;
						if(isFocus)obj.focus();
						isFocus=false;
					}
					else if(obj.alt == "EmailTextBox" && !checkEmail1(obj,true))
					{						
						if(isFocus)obj.focus();
						isFocus=false;  isClass=true;
						msg += "Invalid email address. Please re-enter.\n";
					}
					else if(obj.alt == "MultipleEmailTextBox")
					{	
						arr = obj.value.split(",");
						for(i=0;i<arr.length;i++)
							if(!checkEmail(arr[i]) && arr[i] != '')msg += arr[i] + " -> Invalid email address. Please re-enter.\n";
						if(isFocus)obj.focus();
						
						isFocus=false;  isClass=true;
						
					}
					else if(obj.alt.indexOf('PasswordTextBox') > -1 && obj.value.length < 6)
					{	
						if(isFocus)obj.focus();
						isFocus=false; isClass=true;
						msg += "The password you entered is incorrect.\n"
					}
					else if(obj.alt == 'ConfirmPasswordTextBox' && damiObj.value != obj.value)
					{	if(isFocus)$("input[@alt=PasswordTextBox]").focus();
						isFocus=false; isClass=true;
						msg += "Please verify your password again.\n"; 
					}
					else if(obj.alt == 'PostCodeTextBox' && checkPostcode(obj))
					{	if(isFocus)obj.focus();
						isFocus=false;  isClass=true;
						msg += "Postal code should be of 6/9 digits.\n"; 
					}
					else if(obj.id == 'txtCell' && obj.value.length != 10)
					{	
						if(isFocus)obj.focus();
						isFocus=false;  isClass=true;
						msg += "Mobile no should be of 10 digits.\n"; 
					}
					/*if(obj.title === obj.value)
					{	obj.value="";$(obj).removeClass("Msg");}*/
					/*str=$("#"+obj.id+"_status").text() || false;
					
					if(str && (str == "Weak" || str == "Very weak" || str == "Too short"))
					{
						if(isFocus)obj.focus();
						isFocus=false; isClass=true;
						msg += "Your password should at least be of 6 characters.\n";
					}*/
					break;
				case "textarea":
					if(($.trim(obj.value) == $.trim(obj.title) || $.trim(obj.value) == '') && obj.title != '')
					{
						msg += obj.title + "\n";
						if(isFocus)obj.focus();
						isFocus=false;isClass=true;
					}					
					else if(obj.id.indexOf('MultipleEmailTextBox') > -1)
					{	
						
						arr = obj.value.split(",");
						for(i=0;i<arr.length;i++)
							if(!checkEmail($.trim(arr[i])) && arr[i] != '')msg += arr[i] + " -> Invalid E-mail Address! Please re-enter.\n";
						
						maxEmail = parseInt(obj.id.substring('MultipleEmailTextBox'.length),10);
						
						if(maxEmail < arr.length)
							msg += "Please enter only " + maxEmail + " email.\n"; 
						if(isFocus)obj.focus();
						isFocus=false;  isClass=true;
						
					}
					else if(obj.id.indexOf('txtMaxCharacter') > -1)
					{	
						maxCharacter = parseInt(obj.id.substring('txtMaxCharacter'.length),10);
						if(obj.value.length > maxCharacter )
						{
							if(isFocus)obj.focus();
							isFocus=false;  isClass=true;
							
							msg += obj.title.substring(obj.title.indexOf(' ')+1) + " does not excced " + maxCharacter + " character.\n"; 
						}
						
					}
					break;
				case "select-one":
					if(obj.title != '' && $.trim(obj.value) == '')
					{
						if(msg.indexOf(obj.title)==-1)
							msg += obj.title + "\n";
						if(isFocus)obj.focus();
						isFocus=false;isClass=true;
					}
					break;
				case "checkbox":
					if(obj.title)
					{
						if($.inArray(obj.alt,damiRadio)==-1 || damiRadio.length==0)
						{
							if($("input[alt='"+obj.alt+"']:checked").size() <= 0)
							{	
								msg += obj.title + "\n";
								if(isFocus)obj.focus();
								$("#span" + obj.alt).addClass("errorText");
								isFocus=false;
							}
							else
								$("#span" + obj.alt).removeClass("errorText");
							damiRadio=$.extend(damiRadio,new Array(obj.alt));
						}
					}
					break;
				case "radio":
					if($.inArray(obj.name,damiRadio)==-1 || damiRadio.length==0)
					{
						if($("input[name='"+obj.name+"']:checked").size() <= 0)
						{	
							msg += obj.title + "\n";
							if(isFocus)obj.focus();
							$("#span" + obj.name.substr(3)).addClass("errorText");
							isFocus=false;
						}
						else
							$("#span" + obj.name.substr(3)).removeClass("errorText");
						damiRadio=$.extend(damiRadio,new Array(obj.name));
					}				
				
			}	
			if(obj.type != 'radio' && obj.type != 'checkbox')
			{
				if(isClass)
				{
					$("#span" + obj.id.substr(3)).addClass("errorText");
				}
				else
					$("#span" + obj.id.substr(3)).removeClass("errorText");
			}
			if(obj.alt == 'PasswordTextBox')
				damiObj=obj
		}
	);
	/*alert(msg1);*/
			
	if(msg != '')
	{	alert(msg);return false;}
	else
		return true;
}

function setCboMonth(objComboBox,strId)
{

	var d = new Date();
	if(objComboBox.value == "Con.")
	{
		$("#"+strId,objComboBox.form).attr({disabled:"disabled"}).html('<option value="">Month</option><option value="Con." selected="selected">Continue</option>');
		//$("#"+strId +" option").eq(0).attr({value:"1"});
		//document.getElementById(strId).options.selectedIndex=1;
	}
	else
	{	
		$("#"+strId,objComboBox.form).removeAttr("disabled").html('<option value="">Month</option>');
		
		//objCom = document.getElementById(strId);
		//alert(objComboBox.form);
		/*$.each($("#"+strId +" option"),function()
		{if((objComboBox.value == d.getFullYear() && this.value > d.getMonth()+1 )|| this.value == 'Con.')
		 {	this.options[i] = new Option(i);
					this.options[i].text=i;
					this.options[i].value=i;i++;}
		});
		*/
		//$("#"+strId).append($('<option></option').val("1").html("d"));

		totMonth = objComboBox.value == d.getFullYear()?d.getMonth()+1:12;
		for(i=1; i<=totMonth; i++)
		{
			str = i < 10 ?"0"+i:i;
			
			val = "<option value="+str+">"+str+"</option>";
			$("#"+strId,objComboBox.form).html($("#"+strId,objComboBox.form).html()+val);
			/*<option value="">Month</option>
			objCom.options[i]=new Option(i);
			objCom.options[i].text=str;
			objCom.options[i].value=str;*/
		}
	}
}