// JavaScript Document

function confirmSubmit() 
	     { 
		
		if (document.getElementById("votefor").value == "")
		{
		     var agree=confirm("Please select an entry before voting."); 
		    
		}
		
	     }

function callpage(id)
{
	var url = "listingproducts.php?id="+id;
	
	sample(url,'products_td');
}
function res_pro(){
   document.getElementById("add_list").reset();
 } 
function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
}

function subm()
{
var flag=0;
var name = document.getElementById('name').value;
var emailid = document.getElementById('emailid').value;
var contactnumber = document.getElementById('contactnumber').value;
var productname = document.getElementById('productname').value;
var productdescription = document.getElementById('productdescription').value;
if (name=='')
   {
    alert('Enter Your Name!')
    document.add_list.name.focus();
	return false;
    flag=1;
   }
   
   if (emailid=='')
   {
    alert('Enter Your E-Mailid!')
    document.add_list.emailid.focus();
	return false;
    flag=1;
   }
   var spos = emailid
var anum  = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;

    if (anum.test(spos))
	testresult=true;
    else
    {
         alert("Invalid Emailid!")
         document.add_list.emailid.focus();
				 return false;
         flag=1
    }
	
	if (contactnumber=='')
   {
    alert('Enter Your Contact Number!')
   document.add_list.contactnumber.focus();
    return false;
	flag=1;
   }
   if (contactnumber!="")
   {
	  var i;
	s = contactnumber.toString();
      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);
         if (isNaN(c)) 
	   {
		alert("Given contact details is not a number");
		document.add_list.contactnumber.focus();
		return false;
		flag=1;
	   }
      }
     
   }
     
	
	if (productname=='')
   {
    alert('Product name cannot be left blank!')
   document.add_list.productname.focus();
    return false;
	flag=1;
   }
   
   if (productdescription=='')
   {
    alert('Product Description cannot be left blank!')
   document.add_list.productdescription.focus();
   return false;
	flag=1;
	
   }
  
	
	if(flag==0)
   {
	  document.add_list.action ='submit_insert.php';
	  document.add_list.onsubmit = null;
	  document.add_list.submit();
	
   }
   
  
}



function sample(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadfileshare(page_request, containerid)
}
page_request.open('GET', url, true)
page_request.send(null)
}

function loadfileshare(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
{

document.getElementById(containerid).innerHTML=page_request.responseText;
}
if(page_request.readyState == 1 || page_request.readyState == 2 || page_request.readyState == 3 )
document.getElementById(containerid).innerHTML="<br>&nbsp;&nbsp;<p align ='left'><img src='small_loading.gif'></p>";
}











function add()
{
	flag=1;
	var vote='0';
	var vote_length=document.vote_form.vot_rad.length;

	if(parseInt(vote_length)>0)
	{
	for(var i=0; i<vote_length; i++)
	{
		if(document.vote_form.vot_rad[i].checked==true)
		{
		vote=document.vote_form.vot_rad[i].value;	
		}
	}
	}
	if(vote==0)
	{
		flag=0;
	}

if(flag==1)
{
document.vote_form.action="add_record.php";
document.vote_form.submit();	
}	
else
{
alert('cheak all files');	
}		
}
function added_this()
{
	alert('inserted sucessfully');

	
}



// contact

function valid()
{
var flag=0;
var name = document.getElementById('name').value;
var emailid = document.getElementById('email_ads').value;
var contactnumber = document.getElementById('contactnumber').value;
var message = document.getElementById('message').value;
if (name=='')
   {
    alert('Enter Your Name!')
    document.contact_us.name.focus();
	return false;
    flag=1;
   }
   if (message=='')
   {
    alert('Enter Your Name!')
    document.contact_us.message.focus();
	return false;
    flag=1;
   }
   if (emailid=='')
   {
    alert('Enter Your E-Mailid!')
    document.contact_us.email_ads.focus();
	return false;
    flag=1;
   }
   var spos = emailid
var anum  = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;

    if (anum.test(spos))
	testresult=true;
    else
    {
         alert("Invalid Emailid!")
         document.add_list.emailid.focus();
				 return false;
         flag=1
    }
	
	if (contactnumber=='')
   {
    alert('Enter Your Contact Number!')
   document.add_list.contactnumber.focus();
    return false;
	flag=1;
   }
   if (contactnumber!="")
   {
	  var i;
	s = contactnumber.toString();
      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);
         if (isNaN(c)) 
	   {
		alert("Given contact details is not a number");
		document.contact_us.contactnumber.focus();
		return false;
		flag=1;
	   }
      }
     
   }
     

  
	
	if(flag==0)
   {
	document.contact_us.action="register.php";
	document.contact_us.submit();
	alert('Email Sent Successfully');
	
   }
   
  
}


function resetForm(){
   document.getElementById("contact_us").reset();
 } 
function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
}
