function validate_select_login_form(i)
{
	if(i==1)
	{
		document.getElementById("form_select").style.display='none';
		document.getElementById("form_registered_user").style.display='block';
		document.getElementById("form_new_user").style.display='none';
	}
else
	{
		document.getElementById("form_select").style.display='none';
		document.getElementById("form_registered_user").style.display='none';
		document.getElementById("form_new_user").style.display='block';
	}
}

function validate_user_login1()
{
	var g = document.form_login;
	if(trim(g.username.value)=="")
	{
		alert("Please enter Username.");
		g.username.value = trim(g.username.value);
		g.username.focus();
		return false;
	}
	if(trim(g.password.value)=="")
	{
		alert("Please enter Password.");
		g.password.value = trim(g.password.value);
		g.password.focus();
		return false;
	}
}

function validate_search_text()
{
	var g=document.form2;
	if(trim(g.search_text.value)=="")
	{
		alert("Please mention the Search Text.");
		g.search_text.focus();
		return false;
	}
}

function validate_add_search(i)
{
	if(trim(i.p_qnt.value)=="")
	{
		alert("Please mention the quantity.");
		i.p_qnt.focus();
		return false;
	}
}

function validate_add_search_acc(i)
{
	if(trim(i.p_qnt.value)=="")
	{
		alert("Please mention the quantity.");
		i.p_qnt.focus();
		return false;
	}
else if(trim(i.p_qnt.value)==0)
	{
		alert("Plaese enter the quantity greater then zero.");
		i.p_qnt.focus();
		return false;
	}
	if(!validString(trim(i.p_qnt.value)))
	{
		alert("Plaese enter a valid quantity.");
		i.p_qnt.focus();
		return false;
	}
	document.getElementById("add_product" + i.name).style.display='none';
	document.getElementById("product_accessory" + i.name).style.display='block';
}

function validate_height(pid)
{
	var g=document.form2;
	var height_value=g.height.value;
	document.getElementById("s_height").value=height_value;
	document.form1.action='product_menu.php?pi='+pid;
	document.form1.submit();
}

function validate_width(pid)
{
	var g=document.form2;
	var width_value=g.width.value;
	document.getElementById("s_width").value=width_value;
	document.form1.action='product_menu.php?pi='+pid;
	document.form1.submit();
}

function validate_swap_image(image_id,info_value)
{
	document.getElementById("img1").src="icon/blank.png";
	document.getElementById("img2").src="icon/blank.png";
	document.getElementById("img3").src="icon/blank.png";
	
	document.getElementById(image_id).src="icon/check.png";
	document.getElementById("user_info1").value=info_value;
	return true;
}

function validate_swap_image2()
{
	var img_src=document.getElementById("user_ntfy").src;
	var check_var1=img_src.search('blank.png');
	var check_var2=img_src.search('check.png');
	if(check_var2=="-1")
	{
		document.getElementById("user_ntfy").src="icon/check.png";
		document.getElementById("user_notify").value="1";
	}
else if(check_var1=="-1")
	{
		document.getElementById("user_ntfy").src="icon/blank.png";
		document.getElementById("user_notify").value="0";
	}
}

function validate_colour(pid)
{
	var g=document.form2;
	var colour_value=g.colour.value;
	document.getElementById("s_colour").value=colour_value;
	document.form1.action='product_menu.php?pi='+pid;
	document.form1.submit();
}

function validate_show_accessory()
{
	if(!validate_product())
	{
		return false;
	}
	document.getElementById("add_item1").style.display='none';
	document.getElementById("show_accessory").style.display='block';
	document.getElementById("add_item2").style.display='block';
}

function validate_product()
{
	var g=document.form2;
	if(trim(g.p_qnt.value)=="")
	{
		alert("Please enter the quantity.");
		g.p_qnt.focus();
		return false;
	}
else if(trim(g.p_qnt.value)==0)
	{
		alert("Plaese enter the quantity greater then zero.");
		g.p_qnt.focus();
		return false;
	}
	if(!validString(trim(g.p_qnt.value)))
	{
		alert("Plaese enter a valid quantity.");
		g.p_qnt.focus();
		return false;
	}
	return true;
}

function validate_add_accesssory(g)
{
	if(trim(g.p_qnt.value)=="")
	{
		alert("Please enter the quantity.");
		g.p_qnt.focus();
		return false;
	}
else if(trim(g.p_qnt.value)==0)
	{
		alert("Plaese enter the quantity greater then zero.");
		g.p_qnt.focus();
		return false;
	}
	if(!validString(trim(g.p_qnt.value)))
	{
		alert("Plaese enter a valid quantity.");
		g.p_qnt.focus();
		return false;
	}
}

function validate_product_update(g)
{
	if(g.p_qty.value=="" || g.p_qty.value==0)
	{
		if(confirm("This will delete this product from your quotation."))
		{
			return true;
		}
	else
		{
			return false;
		}
	}
}

function validate_delete_product(sess_id)
{
	if(confirm("Are you sure you want to delete this product from your quotation?"))
	{
		window.location.href='quotation_action.php?mode=delete_product&sessid=' + sess_id;
		return true;
	}
else
	{
		return false;
	}
}

function validate_accessory_update(g)
{
	if(g.p_qty.value=="" || g.p_qty.value==0)
	{
		if(confirm("This will delete this accessory from your quotation."))
		{
			return true;
		}
	else
		{
			return false;
		}
	}
}

function validate_delete_accessory(sess_id,code_id)
{
	if(confirm("Are you sure you want to delete this accessory from your quotation?"))
	{
		window.location.href='quotation_action.php?mode=delete_accessory&sessid=' + sess_id + '&codeid=' + code_id;
		return true;
	}
else
	{
		return false;
	}
}

function validate_pesonal_detail()
{
	var g=document.form_pd;
	if(trim(g.name.value)=="")
	{
		alert("Please fill the name.");
		g.name.focus();
		return false;
	}
	if(trim(g.position.value)=="")
	{
		alert("Please fill the position.");
		g.position.focus();
		return false;
	}
	if(trim(g.company.value)=="")
	{
		alert("Please fill the company.");
		g.company.focus();
		return false;
	}
	if(trim(g.address.value)=="")
	{
		alert("Please fill the address.");
		g.address.focus();
		return false;
	}
	if(trim(g.phone.value)=="")
	{
		alert("Please fill the telephone number.");
		g.phone.focus();
		return false;
	}
	if(trim(g.fax.value)=="")
	{
		alert("Please fill the fax number.");
		g.fax.focus();
		return false;
	}
	if(trim(g.email.value)=="")
	{
		alert("Please fill the Email address.");
		g.email.focus();
		return false;
	}
else
	{
		var demo		
		demo=g.email.value;

		var AtSym    = demo.indexOf('@')
		var period1  = demo.indexOf('.')
		var Period   = demo.lastIndexOf('.')
		var Space    = demo.indexOf(' ')
		var Length   = demo.length - 1  

		if ((AtSym < 1) ||                  // '@' cannot be in first position
		(Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
		(period1 < 1) ||
		(Period == Length ) ||             // Must be atleast one valid char after '.'
		(Space  != -1))                    // No empty spaces permitted
		{  
			 alert('Please enter a valid e-mail address! for eg. 11abc@yourcompany.com');
			 g.email.focus();
			 return(false)
		 }
	}
	if(trim(g.user_info1.value)=="")
	{
		alert("Please select one of the option.");
		return false;
	}
	return true;
}

function validate_show_response(i)
{
	document.getElementById("show_mode" + i).value="show_quot_response";
	return true;
}

function validString(myString)
{
	var valid_string = new String("1234567890");
	for(var i=0;i<myString.length;i++)
	{
		var search_exp=myString.substr(i,1);
		var answerIdx=valid_string.search(search_exp);
		if(answerIdx==0)
		{
			if(search_exp==".")
			{
				return false;
			}
		}
		if(answerIdx==-1)
		{
			return false;
		}
	}
	return true;
}
function trim(str)
{
	return str.replace(/^\s*|\s*$/g,"");
}