function trim(s) 
{
  while (s.substring(0,1) == ' ') 
  {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') 
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}
function validateUser(frmUser)
{	
	var stripped = document.frmUser.phone.value.replace(/[\(\)\.\-\ ]/g, '');     
	var email_str = document.frmUser.email.value;
	var filter=/^.+@.+\..{2,3}$/;
	var errorstr = '';
	var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
		if(document.frmUser.firstName.value=='')
		{
		errorstr+="- Please enter your First name.\n"
		}
		if(document.frmUser.lastName.value=='')
		{
		errorstr+="- Please enter your Last name.\n"
		}
		if(document.frmUser.email.value == '')
		{
	  	errorstr +=  "- Please enter your email id.\n"; 
		}
		else if(!(filter.test(email_str)))
		{
    	 errorstr +="- Please enter valid email id .\n";
		} 
		if(document.frmUser.phone.value=='')
		{
		errorstr+="- Please enter phone No.\n"
		}
		 else if (isNaN(parseInt(stripped))) 
		{
        errorstr+="- The phone number contains illegal characters.\n";
    	} 
		else if (!(stripped.length == 10)) 
		{
        errorstr+= "- The phone number must contain 10 digits.\n";
    	} 
		if(document.frmUser.country.value=='')
		{
		errorstr+="- Please select country.\n"
		}	
		if(document.frmUser.address.value=='')
		{
		errorstr+="- Please enter address.\n"
		}	
		if (errorstr != '')
		{
			msgstr = msgstr + errorstr;
			alert(msgstr);
			return false;
		}
		else
		{
			return true;
		}	
}
function validateContact(frmcontact)
{
	var stripped = document.frmcontact.mobile.value.replace(/[\(\)\.\-\ ]/g, '');     
	var email_str = document.frmcontact.email.value;
	var filter=/^.+@.+\..{2,3}$/;
	var errorstr = '';
	var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
		if(document.frmcontact.name.value=='')
		{
		errorstr+="- Please enter your name.\n"
		}		
		if(document.frmcontact.email.value == '')
		{
	  	errorstr +=  "- Please enter your email id.\n"; 
		}
		else if(!(filter.test(email_str)))
		{
    	 errorstr +="- Please enter valid email id .\n";
		} 
		if(document.frmcontact.mobile.value=='')
		{
		errorstr+="- Please enter mobile No.\n"
		}
		 else if (isNaN(parseInt(stripped))) 
		{
        errorstr+="- The mobile number contains illegal characters.\n";
    	} 
		else if (!(stripped.length == 10)) 
		{
        errorstr+= "- The mobile number must contain 10 digits.\n";
    	} 
		if(document.frmcontact.subject.value=='')
		{
		errorstr+="- Please enter subject.\n"
		}	
		if(document.frmcontact.comments.value=='')
		{
		errorstr+="- Please enter message.\n"
		}	
		if (errorstr != '')
		{
			msgstr = msgstr + errorstr;
			alert(msgstr);
			return false;
		}
		else
		{
			return true;
		}	
}
// function to validate admin user
function admin_form(frm)
{
	var email_str = document.frm.email.value;
	var filter=/^.+@.+\..{2,3}$/;
	var errorstr = '';
	var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
		if(trim(document.frm.userName.value)=='')
		{
		errorstr+="- Please Enter UserName.\n"
		}
		if(trim(document.frm.password.value)=='')
		{
		errorstr+="- Please Enter Password.\n"
		}
		if(trim(document.frm.email.value) == '')
		{
	  	errorstr +=  "- Please Enter Your Email Id.\n"; 
		}
		else if(!(filter.test(email_str)))
		{
    	 errorstr +="- Please Enter Valid Email Ed .\n";
		}    
		if (errorstr != '')
		{
			msgstr = msgstr + errorstr;
			alert(msgstr);
			return false;
		}
		else
		{
			return true;
		}	
} 

//function to validae email manager
function validate(frm)
{
	var email_str = document.frm.email.value;
	var filter=/^.+@.+\..{2,3}$/;
	var errorstr = '';
	var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
		if(trim(document.frm.subject.value)=='')
		{
		errorstr+="- Please Enter Your Subject .\n"
		}
		if(trim(document.frm.email.value) == '')
		{
	  	errorstr +=  "- Please Enter Your Email Id.\n"; 
		}
		else if(!(filter.test(email_str)))
		{
    	 errorstr +="- Please Enter Valid email Id .\n";
		}    
		if(trim(document.frm.fromText.value)=='')
		{
		errorstr+="- Please Enter Your Text.\n"
		}
		if(trim(document.frm.content.value)=='')
		{
		errorstr+="- Please Enter Your Content.\n"
		}
		if (errorstr != '')
		{
			msgstr = msgstr + errorstr;
			alert(msgstr);
			return false;
		}
		else
		{
			return true;
		}	
} 
//Function to validate PageAe
function validatePageAe(frm)
{
	var errorstr = '';
	var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
	

		if(trim(document.frm.pageName.value)=='')
		 { errorstr += "- Please enter page name.\n";}
		if(trim(document.frm.pageContent.value)=='') 
		{ errorstr += "- Please enter page content.\n";}
		
	if (errorstr != '')
	{
		msgstr = msgstr + errorstr;
		alert(msgstr);
		return false;
	}
	else
	{
		return true;
	}	
}
//Function to validate faqAe
function validatefaq(frm)
{
	var errorstr = '';
	var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
	
	if(trim(document.frm.question.value) == "")
	{
	  errorstr +=  "- Please enter the question.\n"; 
	}
   if(trim(document.frm.faqAns.value) == "")
	{
	  errorstr +=  "- Please enter the answer.\n"; 
	}
	if (errorstr != '')
	{
		msgstr = msgstr + errorstr;
		alert(msgstr);
		return false;
	}
	else
	{
		return true;
	}	
}

//Function to Select Records Using Checkbox
function checkall(objForm){
	len = objForm.elements.length;
	var i=0;
	for( i=0 ; i<len ; i++) {
		if (objForm.elements[i].type=='checkbox') {
			objForm.elements[i].checked=objForm.check_all.checked;
		}
	}
}
//Function for Confirmation to Delete a record
function del()
{
var x=confirm("Do you want to delete the selected record?");
if(x)
  {
return true;
  }
else
   {
return false;
   }
}
//function to validate Template
function validateTemplate(frm)
{
	var errorstr = '';
	var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
	
	if(trim(frm.template.value) == "")
	{
	  errorstr +=  "- Please enter the template name.\n"; 
	}
	
   if(trim(frm.noOfUsrInpt.value) == "")
	{
	  errorstr +=  "- Please enter the no. of attributes.\n"; 
	}
	else if(isNaN(trim(frm.noOfUsrInpt.value)))

		{
		errorstr +=  "- Please enter valid number.\n";
		}
/*	if(frm.logo[0].checked)
	{
	  if(trim(frm.logoHeight.value) == "")
		{
		  errorstr +=  "- Please enter logo height.\n"; 
		}
		else if(isNaN(trim(frm.logoHeight.value)))

		{
		errorstr +=  "- Please enter valid height.\n";
		}
		if(trim(frm.logoWidth.value) == "")
		{
		  errorstr +=  "- Please enter logo width.\n"; 
		}
		else if(isNaN(trim(frm.logoWidth.value)))

		{
		errorstr +=  "- Please enter valid width.\n";
		}
	}*/
	if (errorstr != '')
	{
		msgstr = msgstr + errorstr;
		alert(msgstr);
		return false;
	}
	else
	{
		return true;
	}	
}
function validateCover(frm)
{
	var errorstr = '';
	var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
	
	if(trim(frm.cover.value) == "")
	{
	  errorstr +=  "- Please enter the cover title.\n"; 
	}
	if (errorstr != '')
	{
		msgstr = msgstr + errorstr;
		alert(msgstr);
		return false;
	}
	else
	{
		return true;
	}	
}
function delAtt(obj1,obj2)
{
if(confirm("Are you sure you want to Delete Selected Record(s) "))
	{
		window.location.href="addAttribute.php?delflag=1&templateId="+obj2+"&attributeId="+obj1;
	}
	else
	{
	return false;
	}
}
function winPopUp (my_url, my_name, my_features) {
	win = window.open(my_url, my_name, my_features);
	win.focus();
}
function autoTab(element, nextElement) {
    if (element.value.length == element.maxLength && nextElement != null) {
        element.form.elements[nextElement].focus();
    }
}
function switch_product_img(div,totalImgs,rubber,coverId) {
	for (var i=1; i<=totalImgs; i++) {
		var photo = 'photo_' +rubber+'_'+ i;
		var cover = 'cover_' +rubber;
		//alert(photo)
		if (i==div)
		{
			//alert(photo)
			document.getElementById(photo).style.display = 'block';
			document.getElementById(cover).value = coverId;
			
		}
		else
		{
			document.getElementById(photo).style.display = 'none';
		}
		}
		
	}
function changeColor(obj,obj1)
{
	var fontTest = 'fontTest_' +obj1;
	var color = 'color_' +obj1;
	document.getElementById(fontTest).style.color=obj;
	document.getElementById(color).value = obj;
}
function changeFont(obj)
{
	document.getElementById('fontTest').style.fontFamily=obj
	document.getElementById('font').value = obj;
}
function validateRubberStamp(frm)
{	
	var errorstr = '';
	var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
	
	if(trim(frm.title.value) == "")
	{
	  errorstr +=  "- Please enter the title.\n"; 
	}
	if(trim(frm.size.value) == "")
	{
	  errorstr +=  "- Please enter the plate size.\n"; 
	}
	if(trim(frm.MPN.value) == "")
	{
	  errorstr +=  "- Please enter the MPN.\n"; 
	}
	if(trim(frm.price.value) == "")
	{
	  errorstr +=  "- Please enter the price.\n"; 
	}
	if(trim(frm.description.value) == "")
	{
	  errorstr +=  "- Please enter the description.\n"; 
	}
   
	if (errorstr != '')
	{
		msgstr = msgstr + errorstr;
		alert(msgstr);
		return false;
	}
	else
	{
		return true;
	}	
}
