// JavaScript Document
	
	function validateFields()
	{
	
	
	
	  //document.frm.state.disabled=false;
	
	if (trim(document.frm.name.value)=="")
			{
			alert("Name is Required");
			document.frm.name.focus();
			return false;	
			}
			
		if (trim(document.frm.address.value) == "")
			{
			alert("Address is Required");
			document.frm.address.focus();
			return false;	
			}
		if (trim(document.frm.country.value) == "")
			{
			alert("Country is Required");
			document.frm.country.focus();
			return false;	
			}	
		if (document.frm.city.value == "")
			{
			alert("City is Required");
			document.frm.city.focus();
			return false;	
			}
		if (document.frm.state.value == "")
			{
			alert("State is Required");
			document.frm.state.focus();
			return false;	
			}
		 if (document.frm.zip.value == "")
			{
			alert("Zip /Post Code is Required");
			document.frm.zip.focus();
			return false;	
			}
		
	if (trim(document.frm.cellphone.value)=="")
			{
			alert("Cell Phone Number is Required");
			document.frm.cellphone.focus();
			return false;	
			}
		else if(isNaN(document.frm.cellphone.value))
		{
		alert("Invalid Cellphone No.");
			document.frm.cellphone.focus();
			return false;
		}	
		 if (trim(document.frm.email.value) == "")
			{
				alert("Email is Required");
				document.frm.email.focus();
				return false;
			}
		else if (echeck(document.frm.email.value) == false){
				document.frm.email.value="";
				document.frm.email.focus();
				return false;
			}	
		if (trim(document.frm.upassword.value)== "")
		{
			alert("Password missing.");
			document.frm.upassword.focus();
			return false;	
		}
		if (document.frm.upassword.value != document.frm.repass.value)
		{
			alert("Password doesn't match. Please enter again.!");
			document.frm.upassword.focus();
			return false;	
		}	
		if ((document.frm.upassword.value.length<=5) || (document.frm.upassword.value.length>=19))
		{
			alert("Password should be greater than 6 and less than 20 digit!");
			return false;	
		}
		
}
  function trim(str)
  {
  	return str.replace(/^\s+|\s+$/g,'');
  }
  function echeck(str) {

		//alert(str);
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail")
		    return false
		 }

 		 return true					
	}

//fn to check Date in mm/dd/yyyy

////////////////////////
var field_main;
function do_blink(field)
{
	var errorcolor="#EAEAEA";
	field.focus();
	field.select();
	field.style.background=errorcolor;
    field_main=field;
	setInterval("temp()",500);
}
function expandmenu(name) 
{
	document.getElementById('attribute_sub_menu').style.display = 'none';
	if(name=='attribute')
	{
		document.getElementById('attribute_sub_menu').style.display = '';
	}
	else
	{
		return;
	}
}
function temp(field)
{
var okcolor="#ffffff";
field_main.style.background=okcolor;
}

function validate(field)
{
	try
	{
	valiclass=field.getAttribute("valiclass");
	valimessage=field.getAttribute("valimessage");
	//alert(valiclass);
	if(valiclass=="required")
	{
	
	req=field.getAttribute("req");
	
	pattern="\\w{"+req+",}";
	if(!field.value.match(pattern))
	{
	alert(valimessage);do_blink(field);return false;
	}
	}
	if(valiclass=="username")
	{
	
	pattern="^[A-z0-9]{1,20}$";
	if(!field.value.match(pattern))
	{
	alert(valimessage);do_blink(field);return false;
	}
	}
	else if(valiclass=="alphabets")
	{
	
	req=field.getAttribute("req");
	
	pattern="\^[A-Za-z]{"+req+",}$";
	if(!field.value.match(pattern))
	{
	alert(valimessage);do_blink(field);return false;
	}
	}
	else if(valiclass=="alphanumeric")
	{
	req=field.getAttribute("req");
	
	pattern="\^[A-Za-z0-9\\s]{"+req+",}$";
	if(!field.value.match(pattern))
	{
	alert(valimessage);do_blink(field);return false;
	}
	}
	else if(valiclass=="password_verification")
	{
	if(field.value != document.frm_registration.password.value)
	{
	alert(valimessage);do_blink(field);return false;
	}
	}
	else if(valiclass=="email")
	{
	pattern="^\\w{1,}(\\.\\w{1,})*@\\w{1,}(\\.\\w{1,}){1,}$";
	if(!field.value.match(pattern))
	{
	alert(valimessage);do_blink(field);return false;
	}
	}
	else if(valiclass=="emails")
	{
	temp_axe = field.value.split(',');
	temp_cnt = temp_axe.length;
	for(var j=0; j<temp_cnt; j++)
	{
	pattern="^(\\s)*\\w{1,}(\\.\\w{1,})*@\\w{1,}(\\.\\w{1,}){1,}(\\s)*$";
	tmp_val = 0;	
	if(temp_axe[j].match(pattern))
	{
	tmp_val = 1;
	}	
	}
	if(tmp_val == 0)
	{
	alert(valimessage);do_blink(field);return false;
	}
	}
	else if(valiclass=="number")
	{
		
	if((field.value.length<1)||isNaN(field.value))
	{
	alert(valimessage);do_blink(field);return false;
	}
		
	}
	else if(valiclass=="number_nr")
	{
		
	if((field.value.length>1) && isNaN(field.value))
	{
	alert(valimessage);do_blink(field);return false;
	}
		
	}
	else if(valiclass=="creditcard")
	{
	pattern="^[0-9]{16}$";
	if(!field.value.match(pattern))
	{
	alert(valimessage);do_blink(field);return false;
	}
	
	}
	else if(valiclass=="zip")
	{
	pattern="^[0-9]{5}$";
	if(!field.value.match(pattern))
	{
	alert(valimessage);do_blink(field);return false;
	}
	
	}
	
	else if(valiclass=="code")
	{
	req=field.getAttribute("req");
	pattern="^[0-9]{"+req+"}$";
	if(!field.value.match(pattern))
	{
	alert(valimessage);do_blink(field);return false;
	}
	
	}
	else if(valiclass=="year")
	{
	pattern="^[1-9][0-9]{3}$";
	if(!field.value.match(pattern))
	{
	alert(valimessage);do_blink(field);return false;
	}
	
	}
	
	else if(valiclass=="url" && (field.value.length!=0))
	{	
	pattern="^http:\/\/www\\.\\w{1,}\\.";
	if(!field.value.match(pattern))
	{
	alert(valimessage);do_blink(field);return false;
	}
	
	}
	
	else if(valiclass=="url_required")
	{	
	pattern="^\\w{1,}\\.\\w{1,}\\.?\\w{1,}?";
	if(!field.value.match(pattern))
	{
	alert(valimessage);do_blink(field);return false;
	}
	
	}
	
	else if(valiclass == "embed")
	{
		if(document.uu_embed.loc_url.value.length == 0 && field.value.length == 0){
			alert(valimessage);
			do_blink(document.uu_embed.loc_url);
			return false;
		}
		
		else if(document.uu_embed.loc_url.value.length != 0 && field.value.length != 0){
			alert(valimessage);
			do_blink(field);
			return false;
		}
		
		else if(document.uu_embed.loc_url.value.length == 0 && field.value.length != 0){
			req=field.getAttribute("req");
			pattern="\\w{"+req+",}";
			if(!field.value.match(pattern))
			{
			alert(valimessage);do_blink(field);return false;
			}
		}
	}
	else if(valiclass=="select")
	{
	if(field.value=="NA")
	{
	alert(valimessage);
	field.focus();
	return false;
	}
		
	}
	
	
	else if(valiclass=="date")
	{
	pattern="[0-9]{4}\\-[0-9]{1,2}\\-[0-9]{1,2}$";
	if(!field.value.match(pattern))
	{
	alert(valimessage);do_blink(field);return false;
	}
}
else if(valiclass=="integer")
{
	$bool=field.value.match("^[0-9]{1,4}$");	
	if($bool==0)
	{
		alert("Please enter a non-zero number");
		do_blink(field);
		return false;
	}
	if((!$bool)||isNaN(field.value)||(field.value.indexOf(".")!=-1))
	{
	alert(valimessage);
	do_blink(field);
	return false;	
	}
}

else if(valiclass=="qty")
{
	$bool=field.value.match("^[1-9]{1,4}$");
	
	if((!$bool)||isNaN(field.value)||(field.value<12))
	{
	alert(valimessage);do_blink(field);return false;
	}
}

else if(valiclass=="check")
{
	if(field.checked == false)
	{
	alert(valimessage);do_blink(field);return false;
	}
}

else if(valiclass == "checks")
{
	a = field.name;
	b = document.getElementsByName(a);
	c = b.length;
	d = "";
	for(i = 0; i < c; i++)
	{
		if(b[i].checked)
		{
		 d="checked";
		 break;
		}
	}
	if(d != "checked")
	{
	alert(valimessage);do_blink(field);return false;
	}
}

else if(valiclass=="radio")
{
	a = field.name;
	b = document.getElementsByName(a);
	c = b.length;
	d = "";
	for(i = 0; i < c; i++)
	{
		if(b[i].checked)
		{
		 d="checked";
		 break;
		}
	}
	if(d != "checked")
	{
	alert(valimessage);do_blink(field);return false;
	}
}
else if(valiclass=="video_required")
{
	values=field.value.toLowerCase();
	if(!ends_with(values,".mov") && !ends_with(values,".wmv") && !ends_with(values,".mpeg") && !ends_with(values,".mp4") && !ends_with(values,".avi"))
	{
	alert("You must select a valid video file.");do_blink(field);return false;
	}

}
else if(valiclass=="picture_required")
{
	values=field.value.toLowerCase();
	if(!ends_with(values,".jpg") && !ends_with(values,".gif") && !ends_with(values,".png"))
	{
	alert("Please select a JPG/GIF/PNG image.");do_blink(field);return false;
	}

}
else if(valiclass=="picture")
{
	if(field.value.length<1)
	return true;
	values=field.value.toLowerCase();
	if(!ends_with(values,".jpg") && !ends_with(values,".gif") && !ends_with(values,".png"))
	{
	alert("You must select a JPG/GIF/PNG image.");do_blink(field);return false;
	}
}
else if(valiclass=="ads")
{
	values=field.value.toLowerCase();
	if(!ends_with(values,".jpg") && !ends_with(values,".gif") && !ends_with(values,".png") && !ends_with(values,".swf"))
	{
	alert("Please select a JPG/GIF/PNG/SWF image.");do_blink(field);return false;
	}

}
return true;
}
catch(ex)
{
alert(ex.message);
return true;
}
}



function call_validate(form,from,to)
{
for(counter=from;counter<to;counter++)
{
bool=validate(form[counter]);
if(!bool)
{
return false;
break;
}
}
return true;
//form.submit();
}

function call_validate_ajax(form,from,to)
{
for(counter=from;counter<to;counter++)
{
bool=validate(form[counter]);
if(!bool)
{
return false;
break;
}
}
return true;
}


/////////////////////
function getIndex(what,form) {
    for (var i=0;i<form.length;i++)
        if (what == form[i])
            return i;
    return -1;
}
////////////////////////////////////

function ends_with(hay,neddle)
{
hay=hay.replace(/^\s*|\s*$/g,"");
neddle_length=neddle.length;
hay_length=hay.length;
hay_part=hay.substring((hay_length-neddle_length),hay_length);
return (hay_part==neddle)
}


function  enable_form(form,bools)
{
	
for(counter=0;counter<form.length;counter++)
{
form[counter].disabled=!bools;	
}
}


function validate_range()
{
//alert(validate_range.arguments.length);	
for(counter=0;counter<validate_range.arguments.length;counter++)
{
bool=validate(validate_range.arguments[counter]);
if(!bool)
{
return false;
break;
}
}
validate_range.arguments[0].form.submit();
return true;
}


