function confirmMsg(msg){
	if(!confirm(msg)){
		return false;
	} else {
		return true;
	}
}
function insertMoreUpload_form() 
{ 
	var nUploads = parseInt(document.getElementById('NumberOfUploads').value)+1;		 
	var tbody = document.getElementById("tabUpload").getElementsByTagName("tbody")[1]; 
	//alert(nUploads);
	var row = document.createElement("TR"); 
	//insert second <td>
	/*var cell1 = document.createElement("TD");
	cell1.setAttribute("valign","middle");
	cell1.setAttribute("align","right");*/
	
	var cell2 = document.createElement("TD");
	//cell2.setAttribute("colspan","2");
	cell2.setAttribute("valign","middle");
	cell2.setAttribute("align","left");
	cell2.setAttribute("height","27");
	//File
	var eInput = document.createElement("INPUT"); 
	eInput.setAttribute("type","file");
	eInput.setAttribute("class","button");
	eInput.setAttribute("name","item_file_"+nUploads);
	eInput.setAttribute("id","item_file_"+nUploads);
	eInput.setAttribute("style", "FONT: 11px Verdana, Arial, Helvetica, sans-serif; text-decoration:none;");
	
	cell2.appendChild(eInput);
	
	row.appendChild(cell2); 

	tbody.appendChild(row);
	document.ListForm.NumberOfUploads.value = nUploads;
	return false;
}

function deletemsg(){
document.mymessage.action="deletemsg.php";
document.mymessage.submit();
}
function Sdeletemsg(){
document.sentmessage.action="sentdeletemsg.php";
document.sentmessage.submit();
}
function trashmsg(){
	/*var msg="Are you sure you want to delete this message?";
	if(!confirm(msg)){
		return false;
	}
	 else {
		return true;
	 }*/
	 document.frm_delmsg.action="trashmsg.php";
	document.frm_delmsg.submit();
}

function deletemsg1(){

document.mymessage1.action="deletesmilemsg.php";
document.mymessage1.submit();

}
function poplinks(url)
{
	newwindow=window.open(url,'ImageDisplay','height=400,width=600,left=0,top=0,resizable=yes,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}

function login_validation(){
var txtUsername=document.Login.txtUsername.value;
	 if(txtUsername == "")
			 {
			 alert("Username is empty");
			 document.Login.txtUsername.focus();
			 return false;
			 }
var txtPassword=document.Login.txtPassword.value;
	 if(txtPassword == "")
			 {
			 alert("Password is empty");
			 document.Login.txtPassword.focus();
			 return false;
			 }
}

//Function phone validation Script
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function validateEmail(addr,man,db) {
	if (addr == '' && man) {
	   if (db) alert('Email address is mandatory');
	   return false;
	}
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  if (db) alert('Email address contains invalid characters');
		  return false;
	   }
	}
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  if (db) alert("Email address contains non ascii characters.");
		  return false;
	   }
	}
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   if (db) alert('Email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   if (db) alert('Email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   if (db) alert('Email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   if (db) alert('Email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   if (db) alert('period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   if (db) alert('period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	   if (db) alert('two periods must not be adjacent in email address');
	   return false;
	}
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   if (db) alert('invalid primary domain in email address');
	   return false;
	}
return true;
}

function validation_customer()
{
		
	var txtusername=document.form_addcustomer.txtusername.value;
	if(document.form_addcustomer.txtusername.value=="")
	{
		alert("Enter the User name");
		document.form_addcustomer.txtusername.focus();
		return false;
	}
	var txtpwd=document.form_addcustomer.txtpwd.value;
	if(document.form_addcustomer.txtpwd.value=="")
	{
		alert("Enter the Password");
		document.form_addcustomer.txtpwd.focus();
		return false;
	}
	var txtname=document.form_addcustomer.txtname.value;
	if(document.form_addcustomer.txtname.value=="")
	{
		alert("Enter the Full name");
		document.form_addcustomer.txtname.focus();
		return false;
	}
		
	var txtemail=document.form_addcustomer.txtemail.value;
	if(document.form_addcustomer.txtemail.value == "")
	{
	   alert("Please Enter  Email");
	   document.form_addcustomer.txtemail.focus();
	   return false;
	}
	if (!validateEmail(document.form_addcustomer.txtemail.value,1,1)) 
	 	{
		 document.form_addcustomer.txtemail.focus();
		 return false;
		 }
	var txtphone=document.form_addcustomer.txtphone.value;	 
	if(document.form_addcustomer.txtphone.value == "")
	{
	   alert("Please Enter The Phone Number");
	   document.form_addcustomer.txtphone.focus();
	   return false;
	}
	txtphone = document.form_addcustomer.txtphone;
	if (checkInternationalPhone(txtphone.value)==false){
		alert("Please Enter a Valid Phone Number")
		txtphone.value=""
		txtphone.focus()
		return false
	}
	var txtaddress=document.form_addcustomer.txtaddress.value;
	if(document.form_addcustomer.txtaddress.value=="")
	{
		alert("Enter the Address");
		document.form_addcustomer.txtaddress.focus();
		return false;
	}
	var txtcity=document.form_addcustomer.txtcity.value;
	if(document.form_addcustomer.txtcity.value=="")
	{
		alert("Enter the City");
		document.form_addcustomer.txtcity.focus();
		return false;
	}
	var txtstate=document.form_addcustomer.txtstate.value;
	if(document.form_addcustomer.txtstate.value=="")
	{
		alert("Enter the State");
		document.form_addcustomer.txtstate.focus();
		return false;
	}
	var txtCountry=document.form_addcustomer.txtCountry.value;
	if(document.form_addcustomer.txtCountry.value=="")
	{
		alert("Enter the City");
		document.form_addcustomer.txtCountry.focus();
		return false;
	}
	var txtpostal=document.form_addcustomer.txtpostal.value;
	if(document.form_addcustomer.txtpostal.value=="")
	{
		alert("Enter the Postal Code");
		document.form_addcustomer.txtpostal.focus();
		return false;
	}
}


function members_validate(){
	if (document.frmMembers.txtFirstName.value == "") {
		alert ("Please enter the first name");
		document.frmMembers.txtFirstName.focus();
		return false;
	}
	if (!(document.frmMembers.txtGender[0].checked) && !(document.frmMembers.txtGender[1].checked)){
		alert ("Select the Gender.");
		return false;
	}	
	var emailid = document.frmMembers.txtEmail.value;
	if ( emailid == "") 	{
		alert ("Please enter the email address");
		document.frmMembers.txtEmail.focus();
		return false;
	}			
	if (!validateEmail(emailid,1,1)){
		document.frmMembers.txtEmail.focus();
		return false;
	}	
	var CorrectFileFlag  = 0;
	var where_is_mytool=document.frmMembers.filethumb.value;
	var mytool_array=where_is_mytool.split(".");
	var lastvalue=0;
	lastvalue=mytool_array.length - 1;
	var filevalue=mytool_array[lastvalue];
	var filtypes = new Array('jpg','JPG','jpeg','JPEG','gif','GIF','bmp','BMP','png','PNG');
	filetypeval = filtypes.length;
	for(i=0; i<=filetypeval; i++){
		if(CorrectFileFlag == 0) {
			if((filevalue == filtypes[i])){
			   CorrectFileFlag = 1;
			}
		}
	}
	if(where_is_mytool != ""){
		if(CorrectFileFlag == 0) {
			alert("The file selected is not allowed for the type indicated. Please select the following Image file type.( .jpg, .jpeg, .gif, .bmp, .png)");
		   return false;
		}
	}
	if (document.frmMembers.txtUsername.value == ""){
		alert ("Please enter the Username");
		document.frmMembers.txtUsername.focus();
		return false;
	}

	var password = document.frmMembers.txtPassword.value;
	if ( password == "") {
		alert ("Please enter the password");
		document.frmMembers.txtPassword.focus();
		return false;
	}
	var sss = document.frmMembers.txtPassword.value.length;		
	if(sss < 6){
		alert ("Password must be minimum 6 characters");
		document.frmMembers.txtPassword.focus();
		return false;			
	}

	if(document.frmMembers.chkagree.checked == false){
	   alert("Please select  Allow this site to contact me check box");
	   return false;
	}
	
	if(document.frmMembers.chksiteagree.checked == false){
	   alert("Please select Allow this site's partners to contact me check box");
	   return false;
	}
	if(document.frmMembers.chkemailagree.checked == false){
	   alert("Please select Allow me to receive an email when a new internal message");
	   return false;
	}	
}


function updatemembers_validate(){
	if (document.frmMembers.txtFirstName.value == "") {
		alert ("Please enter the first name");
		document.frmMembers.txtFirstName.focus();
		return false;
	}
	if (document.frmMembers.txtLastName.value == "") {
		alert ("Please enter the last name");
		document.frmMembers.txtLastName.focus();
		return false;
	}
	if (!(document.frmMembers.txtGender[0].checked) && !(document.frmMembers.txtGender[1].checked)){
		alert ("Select the Gender.");
		return false;
	}	
	var emailid = document.frmMembers.txtEmail.value;
	if ( emailid == "") 	{
		alert ("Please enter the email address");
		document.frmMembers.txtEmail.focus();
		return false;
	}			
	if (!validateEmail(emailid,1,1)){
		document.frmMembers.txtEmail.focus();
		return false;
	}	
	if (document.frmMembers.txtAddress1.value == "") {
		alert ("Please enter the address line1");
		document.frmMembers.txtAddress1.focus();
		return false;
	}
	if (document.frmMembers.txtContact.value == "") {
		alert ("Please enter the phone number");
		document.frmMembers.txtContact.focus();
		return false;
	}
	if (document.frmMembers.txtCity.value == "") {
		alert ("Please enter the City");
		document.frmMembers.txtCity.focus();
		return false;
	}
	if (document.frmMembers.txtCountry.value == "") {
		alert ("Please enter the Country");
		document.frmMembers.txtCountry.focus();
		return false;
	}
	if (document.frmMembers.txtState1.value == "") {
		alert ("Please enter the State");
		document.frmMembers.txtState1.focus();
		return false;
	}
	if (document.frmMembers.txtZipCode.value == "") {
		alert ("Please enter the ZipCode");
		document.frmMembers.txtZipCode.focus();
		return false;
	}
	var CorrectFileFlag  = 0;
	var where_is_mytool=document.frmMembers.filethumb.value;
	var mytool_array=where_is_mytool.split(".");
	var lastvalue=0;
	lastvalue=mytool_array.length - 1;
	var filevalue=mytool_array[lastvalue];
	var filtypes = new Array('jpg','JPG','jpeg','JPEG','gif','GIF','bmp','BMP','png','PNG');
	filetypeval = filtypes.length;
	for(i=0; i<=filetypeval; i++){
		if(CorrectFileFlag == 0) {
			if((filevalue == filtypes[i])){
			   CorrectFileFlag = 1;
			}
		}
	}
	if(where_is_mytool != ""){
		if(CorrectFileFlag == 0) {
			alert("The file selected is not allowed for the type indicated. Please select the following Image file type.( .jpg, .jpeg, .gif, .bmp, .png)");
		   return false;
		}
	}
	if (document.frmMembers.txtUsername.value == ""){
		alert ("Please enter the Username");
		document.frmMembers.txtUsername.focus();
		return false;
	}

	var password = document.frmMembers.txtPassword.value;
	if ( password == "") {
		alert ("Please enter the password");
		document.frmMembers.txtPassword.focus();
		return false;
	}
	var sss = document.frmMembers.txtPassword.value.length;		
	if(sss < 6){
		alert ("Password must be minimum 6 characters");
		document.frmMembers.txtPassword.focus();
		return false;			
	}

	if(document.frmMembers.chkagree.checked == false){
	   alert("Please select  Allow this site to contact me check box");
	   return false;
	}
	
	if(document.frmMembers.chksiteagree.checked == false){
	   alert("Please select Allow this site's partners to contact me check box");
	   return false;
	}
	if(document.frmMembers.chkemailagree.checked == false){
	   alert("Please select Allow me to receive an email when a new internal message");
	   return false;
	}
}

