// JavaScript Document
// ------------- This is Script For Admin Pages----------------------//


//Login Validation
function login_validate(){
	if(document.Login.UserName.value == "")
	{
		alert("Plase enter the Username.");
		document.Login.UserName.focus();
		return false;
	}
	if(document.Login.Password.value == "")
	{
		alert("Plase enter the password.");
		document.Login.Password.focus();
		return false;
	}
}


//
function calldel(m)
{
  if(!confirm(m))
  {
    return false;
  }
  else
  return true;
}

// Valid Email  Script
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;
}

//script for add member
function member_reg(type)
{	
	 var Name = document.CustomersForm.Name.value;
	 if (Name == "" )
	 { 
	 alert ("Please enter Your Name");
	 document.CustomersForm.Name.focus();
	 return false;
	 }
	 var emailid = document.CustomersForm.Emailid.value;
	 if (emailid == "")
	 { 
	 alert ("Please enter the Email Address");
	 document.CustomersForm.Emailid.focus();
	 return false;
	 }	
	 if (!validateEmail(document.CustomersForm.Emailid.value,1,1)) 
	 {
	 document.CustomersForm.Emailid.focus();
	 return false;
	 }
	var Brand = document.CustomersForm.Brand.value;
	 if (Brand == "" )
	 { 
	 alert ("Please enter Your Brand");
	 document.CustomersForm.Brand.focus();
	 return false;
	 }
	 var termscheck = document.CustomersForm.termscheck.checked;
	 if (document.CustomersForm.termscheck.checked == false )
	 { 
	 alert ("Please Agree the terms and conditions");
	 return false;
	 }
	  var CreativeImage1 = document.CustomersForm.CreativeImage1.value;
	 if (CreativeImage1 == "" )
	 { 
	 alert ("Please Upload Your Thumb CreativeImage");
	 document.CustomersForm.CreativeImage1.focus();
	 return false;
	 }
	 
	
}
//location
function addbanner(){
		location.href="submit.php";
	}
	
function search_validate(){

	if((document.frm_search.Agency.value == "") && (document.frm_search.Brand.value == "") && (document.frm_search.Category.value == ""))
	{
		alert("Plase Choose the Category or Agency or Brand");
		document.frm_search.Agency.focus();
		return false;
	}
	
}
function post_frm1()
{	

	 
	 var name = document.post_frm.name.value;
	 if (name == "" )
	 { 
	 alert ("Please enter Your Name");
	 document.post_frm.name.focus();
	 return false;
	 }
	 var email = document.post_frm.email.value;
	 if (email == "")
	 { 
	 alert ("Please enter the Email Address");
	 document.post_frm.email.focus();
	 return false;
	 }	
	 if (!validateEmail(document.post_frm.email.value,1,1)) 
	 {
	 document.post_frm.email.focus();
	 return false;
	 }
	
	  var comments = document.post_frm.comments.value;
	 if (comments == "" )
	 { 
	 alert ("Please enter Your comments");
	 document.post_frm.comments.focus();
	 return false;
	 }
}
function insertMoreUploadcoms() 
{ 
	
	var nUploads = parseInt(document.getElementById('NumberOfUploadcoms').value)+1;		 
	var tbody    = document.getElementById("tabUploadcoms").getElementsByTagName("tbody")[1]; 
	var row      = document.createElement("TR"); 
	var cell1    = document.createElement("TD");
	cell1.setAttribute("valign","top");
	cell1.setAttribute("align","right");
	cell1.setAttribute("width","38%");
	cell1.setAttribute("style", "FONT: 10px Verdana, Arial, Helvetica, sans-serif; text-decoration:none; color: #FFFFFF;");
	//cell1.innerHTML = "upload File&nbsp;"+nUploads;
	cell1.setAttribute("style", "FONT: 10px Verdana, Arial, Helvetica, sans-serif; text-decoration:none; color: #FFFFFF;");
	

	//insert second <td>
	var cell2 = document.createElement("TD");
	//cell2.setAttribute("colspan","2");
	cell2.setAttribute("valign","top");
	//File
	var eInput = document.createElement("INPUT"); 
	eInput.setAttribute("type","file");
	eInput.setAttribute("name","downloadfilcom" + nUploads);
	eInput.setAttribute("id","downloadfilcom" + nUploads);
	eInput.setAttribute("style", "FONT: 11px Verdana, Arial, Helvetica, sans-seri; text-decoration:none; color: #006699;");	
	cell2.appendChild(eInput);
	
	// append all <td> to <tr>
	row.appendChild(cell1); 
	row.appendChild(cell2); 
	
	tbody.appendChild(row);
	document.CustomersForm.NumberOfUploadcoms.value = nUploads;
	return false;
}

//call view submit

function callagency(value){

		location.href="search.php?Agency=" +value;
	}
function callbrand(value){

		location.href="search.php?Brand=" +value;
	}
function callcategory(value){

		location.href="search.php?Category=" +value;
	}
function call_single_all(){

		var value=document.frm_search1.single.value;
		location.href="search.php?searchtype=single&single=" +value;
	}