// JavaScript Document
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }


function validateform1()
{
	if(document.form1.email.value == ""){
		alert("Please fill Email");
		document.form1.email.focus();
		//document.form1.email.select();
		return false;	
	}
	if(document.form1.email.value != "" ){	
				var EmailOk  = true
				var Temp     = document.form1.email.value
				var AtSym    = Temp.indexOf('@')
				var Period   = Temp.lastIndexOf('.')
				var Space    = Temp.indexOf(' ')
				var Length   = Temp.length - 1   // Array is from 0 to length-1

				if ((AtSym < 1) ||                     // '@' cannot be in first position
	    		(Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
	    		(Period == Length ) ||             // Must be atleast one valid char after '.'
	    		(Space  != -1))                    // No empty spaces permitted
	   		{
	    		  EmailOk = false;
	    		  alert('Please enter a valid e-mail address.');
				  document.form1.email.focus();
				  document.form1.email.select();
				  if(EmailOk == false)
	    		  return EmailOk;
	   	}
	}
	
	if(document.form1.title.value == ""){
		alert("Please enter Title");
		document.form1.title.focus();
		document.form1.title.select();
		return false; 
	}
	
	if(document.form1.desc.value == ""){
		alert("Please enter Description");
		document.form1.desc.focus();
		//document.form1.desc.select();
		return false; 
	}
	if(document.form1.category.value == ""){
		alert("Please select Category");
		document.form1.category.focus();
		//document.form1.catname.select();
		return false; 
	}
	if(document.form1.category.value == "select"){
		alert("Please select Category");
		document.form1.category.focus();
		//document.form1.catname.select();
		return false; 
	}
	if(document.form1.uploadedfile.value == ""){
		alert("Please provide an Image");
		document.form1.uploadedfile.focus();
		//document.form1.uploadedfile.select();
		return false; 
	}
	if(document.form1.url.value == ""){
		alert("Please enter URL");
		document.form1.url.focus();
		//document.form1.url.select();
		return false; 
	}
	return true;
}

function validateContact(){
	if(document.cntct.firstName.value == ""){
		alert("Please fill First Name");
		document.form1.firstName.focus();
		document.form1.firstName.select();
		return false;	
	}	
	if(document.cntct.lastName.value == ""){
		alert("Please fill Last Name");
		document.form1.lastName.focus();
		document.form1.lastName.select();
		return false;	
	}
	if(document.cntct.email.value != "" ){	
				var EmailOk  = true
				var Temp     = document.cntct.email.value
				var AtSym    = Temp.indexOf('@')
				var Period   = Temp.lastIndexOf('.')
				var Space    = Temp.indexOf(' ')
				var Length   = Temp.length - 1   // Array is from 0 to length-1

				if ((AtSym < 1) ||                     // '@' cannot be in first position
	    		(Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
	    		(Period == Length ) ||             // Must be atleast one valid char after '.'
	    		(Space  != -1))                    // No empty spaces permitted
	   		{
	    		  EmailOk = false;
	    		  alert('Please enter a valid e-mail address.');
				  document.cntct.email.focus();
				  document.cntct.email.select();
				  if(EmailOk == false)
	    		  return EmailOk;
	   	}
	}
	if(document.cntct.message.value == ""){
		alert("Please fill Message");
		document.form1.message.focus();
		document.form1.message.select();
		return false;	
	}
	return true;
}



function descLimiter()
{
	var limit = 150;
	var str = document.getElementById('desc').value;
	var strlen = str.length;
	if (strlen>limit)
	{
		var newstr = str.slice(0,limit);
		document.getElementById('desc').value = newstr;
	}
	str = document.getElementById('desc').value;
	descNew = limit - str.length;
	document.getElementById('descChar').innerHTML = "("+descNew+" chars)";
}
function titleLimiter()
{
	var limit = 50;
	var str = document.getElementById('title').value;
	var strlen = str.length;
	if (strlen>limit)
	{	var newstr = str.slice(0,limit);
		document.getElementById('title').value = newstr;
	}	
	str = document.getElementById('title').value;
	titleNew = limit - str.length;
	document.getElementById('titleChar').innerHTML = "("+titleNew+" chars)";
}