/**********************************************************************************/
var newwindow;
function poplinks(url)
{
	newwindow=window.open(url,'name','scrollbars=yes,height=500,width=800,left=0,top=0,resizable=yes');
	if (window.focus) {newwindow.focus()}
}

function confirmMsg(msg){
	if(!confirm(msg)){
		return false;

	} else {
		return true;

	}
}


function popimage(url)
{
	newwindow=window.open(url,'ImageDisplay','height=600,width=600,left=0,top=0,resizable=yes,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}
function OpenWin(url,winName,w,h,other)
	{
	var acc = "width=" + w + ",height=" + h + "," + other;
	window.open(url,winName,acc);
	}

function openchild()
	{
	var dof="val";
    document.form1.action="prospects.php?val="+dof;
    document.form1.submit();
	}
	function openchilddel(screen1,val,li,searchs,searchby)
	{
	var dof="delete";
    document.form1.action="prospects.php?delflag="+dof+"&screen="+screen1+"&val="+val+"&li="+li+"&search="+searchs+"&searchbyfor="+searchby;
    document.form1.submit();
	}
 
function changecat()
	{
	var catname=document.form1.comid.value;
	var dof="cusad";
		if (catname=="All")
			{
				window.location.href="prospects.php";
			}
		else
			{
				window.location.href="prospects.php?li="+document.form1.comid.value;
			}
	}
	
//Function Login validation
function login_validate(){

		 if (document.login.txtuser.value == "") 
		{
				alert ("Login name is empty");
				document.login.txtuser.focus();
				return false;
		}
		if (document.login.txtpass.value == "") 
		{
				alert ("Password is empty");
				document.login.txtpass.focus();
				return false;
		}
}

//Function Member Validation in the front panel
function adduser_validation(){
if (document.adduser.member_type.value == "") {
				alert ("Please select the membership type");
				document.adduser.member_type.focus();
				return false;
		}
if (document.adduser.firstname.value == "") {
				alert ("Please enter the first name");
				document.adduser.firstname.focus();
				return false;
		}
if (document.adduser.lastname.value == "") {
				alert ("Please enter the last name");
				document.adduser.lastname.focus();
				return false;
		}
if (document.adduser.address.value == "") {
				alert ("Please enter the address line1");
				document.adduser.address.focus();
				return false;
		}
if (document.adduser.city.value == "") {
				alert ("Please enter the city");
				document.adduser.city.focus();
				return false;
		}
if (document.adduser.state.value == "") {
				alert ("Please enter the state");
				document.adduser.state.focus();
				return false;
		}
if (document.adduser.country.value == "") {
				alert ("Please enter the country");
				document.adduser.country.focus();
				return false;
		}
if (document.adduser.zipcode.value == "") {
				alert ("Please enter the zipcode");
				document.adduser.zipcode.focus();
				return false;
		}
	phone=document.adduser.phone;
		if (checkInternationalPhone(phone.value)==false){
			alert("Please Enter a Valid Phone Number")
			phone.value=""
			phone.focus()
			return false
			}

if (!validateEmail(document.adduser.email.value,1,1)) 
		{
				document.adduser.email.focus();
				return false;
		}
if (document.adduser.username.value == "") {
				alert ("Please enter the user name");
				document.adduser.username.focus();
				return false;
		}
var username = document.adduser.username.value;
var entereduser = username.toUpperCase();
 if(entereduser == "TEMPLATE" || entereduser == "CAPTUREPAGES" || entereduser == "IMAGES"  || entereduser == "ADMIN" || entereduser == "SCRIPT" || entereduser == "CSS" || entereduser == "INCLUDE" || entereduser == "TEMPLATEIMAGES" ||  entereduser == "FILES_UPLOADED"){
	alert ("Please avoid the reserved keywords like template,admin etc...");
	document.adduser.username.focus();
	return false; 
 }
	
if (document.adduser.password.value == "") {
				alert ("Please enter the password");
				document.adduser.password.focus();
				return false;
		}

if (document.adduser.deposit_method.value == "") {
				alert ("Please enter the payment method");
				document.adduser.deposit_method.focus();
				return false;
		}	
}

//Function member validation

function member_validate(){
	if (document.addmember.txt_password.value == "") 
		{
				alert ("Password is empty");
				document.addmember.txt_password.focus();
				return false;
		}
	if (document.addmember.txt_password2.value == "") 
		{
				alert ("Confirm password is empty");
				document.addmember.txt_password2.focus();
				return false;
		}
	if (document.addmember.txt_password.value != document.addmember.txt_password2.value) 
		{
				alert ("Password mismatch");
				document.addmember.txt_password2.focus();
				return false;
		}
		
		if (document.addmember.txt_firstname.value == "") 
		{
				alert ("First name is empty");
				document.addmember.txt_firstname.focus();
				return false;
		}
		
		if (document.addmember.txt_lastname.value == "") 
		{
				alert ("Last name is empty");
				document.addmember.txt_lastname.focus();
				return false;
		}
		
			
		if (document.addmember.txt_address.value == "") 
		{
				alert ("Address line is empty");
				document.addmember.txt_address.focus();
				return false;
		}
		if (document.addmember.txt_city.value == "") 
		{
				alert ("City is empty");
				document.addmember.txt_city.focus();
				return false;
		}
		if (document.addmember.txt_state.value == "") 
		{
				alert ("State is empty");
				document.addmember.txt_state.focus();
				return false;
		}
		if (document.addmember.txt_zipcode.value == "") 
		{
				alert ("Zipcode is empty");
				document.addmember.txt_zipcode.focus();
				return false;
		}
		if (document.addmember.txt_country.value == "Choose") 
		{
				alert ("Please choose the country");
				document.addmember.txt_country.focus();
				return false;
		}
		if (document.addmember.txt_timezone.value == "Choose") 
		{
				alert ("Please choose your time zone");
				document.addmember.txt_timezone.focus();
				return false;
		}
		
}


	function contactus_validate(){
	if(document.frm_contactus.name.value == ""){
	alert("Please enter your name.");
	document.frm_contactus.name.focus();
	return false;
	}
	if(document.frm_contactus.email.value == ""){
	alert("Please enter your email..");
	document.frm_contactus.email.focus();
	return false;
	}
	if (!validateEmail(document.frm_contactus.email.value,1,1))  
	{
		document.frm_contactus.email.focus();
		return false;
	}
    if(document.frm_contactus.subject.value == ""){
	alert("Please enter Subject.");
	document.frm_contactus.subject.focus();
	return false;
	}
   	if(document.frm_contactus.message.value == ""){
	alert("Please enter message.");
	document.frm_contactus.message.focus();
	return false;
	}

}

//Function member configuration validation
function memberconfig_validate(){

		if (document.addmember.txt_firstname.value == "") 
		{
				alert ("First name is empty");
				document.addmember.txt_firstname.focus();
				return false;
		}
		
		if (document.addmember.txt_lastname.value == "") 
		{
				alert ("Last name is empty");
				document.addmember.txt_lastname.focus();
				return false;
		}
		
		phone=document.addmember.int_phonenumber;
		if (checkInternationalPhone(phone.value)==false){
			alert("Please Enter a Valid Phone Number")
			phone.value=""
			phone.focus()
			return false
			}
		
		if (!validateEmail(document.addmember.txt_email.value,1,1)) 
		{
				document.addmember.txt_email.focus();
				return false;
		}
		
		
}


//Function tell a friend validation
function tellafriend_validate(){
	if (document.tellafriend.yourname.value == "") 
		{
				alert ("Please fill your name");
				document.tellafriend.yourname.focus();
				return false;
		}
		
	if (!validateEmail(document.tellafriend.youremail.value,1,1)) 
		{
				document.tellafriend.youremail.focus();
				return false;
		}
		
	if (document.tellafriend.friendname.value == "") 
		{
				alert ("Please fill your friend name");
				document.tellafriend.friendname.focus();
				return false;
		}
		
	if (!validateEmail(document.tellafriend.friendemail.value,1,1)) 
		{
				document.tellafriend.friendemail.focus();
				return false;
		}
		
	if (document.tellafriend.subject.value == "") 
		{
				alert ("Please fill the subject");
				document.tellafriend.subject.focus();
				return false;
		}
}

function fpassword_validate(){
	if (document.frm_fpassword.username.value == "") 
		{
				alert ("User Name is empty");
				document.frm_fpassword.username.focus();
				return false;
		}
	if (!validateEmail(document.frm_fpassword.emailid.value,1,1)) 
		{
				document.frm_fpassword.emailid.focus();
				return false;
		}
}




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

 //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);
}

startList = function() {

	//code only for IE
	if(!document.body.currentStyle) return;
	var subs = document.getElementsByName('submenu');
	for(var i=0; i<subs.length; i++) {
		var li = subs[i].parentNode;
		if(li && li.lastChild.style) {
			li.onmouseover = function() {
				this.lastChild.style.visibility = 'visible';
			}
			li.onmouseout = function() {
				this.lastChild.style.visibility = 'hidden';
			}
		}
	}
}
function insertMoreUpload_form() 
{ 
	var nUploads = parseInt(document.getElementById('NumberOfUploads').value)+1;		 
	var tbody = document.getElementById("tabUpload").getElementsByTagName("tbody")[1]; 
	var row = document.createElement("TR"); 

	//insert second <td>
	var cell2 = document.createElement("TD");
	//cell2.setAttribute("colspan","2");
	cell2.setAttribute("valign","middle");
	cell2.setAttribute("align","center");
	//File
	var eInput = document.createElement("INPUT"); 
	eInput.setAttribute("type","text");
	eInput.setAttribute("name","labelname" + nUploads);
	eInput.setAttribute("id","Label");
	eInput.setAttribute("style", "FONT: 11px Verdana, Arial, Helvetica, sans-serif; text-decoration:none;");	
	cell2.appendChild(eInput);
	
	// append all <td> to <tr>
	//insert second <td>
	var cell3 = document.createElement("TD");
	cell3.setAttribute("valign","middle");
	cell3.setAttribute("align","center");
	//File
	/*var eInput = document.createElement("INPUT"); 
	eInput.setAttribute("type","text");
	eInput.setAttribute("name","fieldtype" + nUploads);
	eInput.setAttribute("id","fieldtype" + nUploads);
	eInput.setAttribute("style", "FONT: 11px Verdana, Arial, Helvetica, sans-seri; text-decoration:none; color: #006699;");	
	cell3.appendChild(eInput);*/
	
	//File
	listarray = new Array("TextBox","TextArea","ListBox","RadioButton","CheckBox","FileField");
	var eInput = document.createElement("select"); 
	eInput.setAttribute("name","fieldtype" + nUploads);
	eInput.setAttribute("id","Type");
	eInput.setAttribute("style", "FONT: 11px Verdana, Arial, Helvetica, sans-seri; text-decoration:none; color: #006699;");
		var doc = eInput.ownerDocument;
		if (!doc)
			doc = eInput.document;
		for(listindex = 0; listindex < 6; listindex++){
			var opt = doc.createElement('OPTION');
			opt.value = listarray[listindex];
			opt.text = listarray[listindex];
			eInput.options.add(opt,listindex);
		}

	//eInput.new Option("TextBox","TextBox");
	cell3.appendChild(eInput);
	
	

	var cell4 = document.createElement("TD");
	//cell2.setAttribute("colspan","2");
	cell4.setAttribute("valign","top");
	cell4.setAttribute("align","center");
	//File
	var eInput = document.createElement("INPUT"); 
	eInput.setAttribute("type","text");
	eInput.setAttribute("name","fieldvalue" + nUploads);
	eInput.setAttribute("id","FieldValue");
	eInput.setAttribute("style", "FONT: 11px Verdana, Arial, Helvetica, sans-seri; text-decoration:none; color: #006699;");	
	cell4.appendChild(eInput);
	

	row.appendChild(cell2); 
	row.appendChild(cell3); 
	row.appendChild(cell4); 
	tbody.appendChild(row);
	document.frm_updateform.NumberOfUploads.value = nUploads;
	return false;
}


function formvalidation()
{
if(document.frm_updateform.heading.value == "")	
{
	alert("Enter Heading");
	document.frm_updateform.heading.focus();
	return false;
}
	
	var upload=document.frm_updateform.NumberOfUploads.value;
	if(upload != ""){
		for(i=0; i<upload; i++){
				//alert(document.frm_updateform.Type[i].value);
				var labelname		=	document.frm_updateform.Label[i].value
				var fieldtype		=	document.frm_updateform.Type[i].value
				var fieldvalue     =	document.frm_updateform.FieldValue[i].value
				if(labelname == "")
				{
					alert("Enter Label Name");
					document.frm_updateform.Label[i].focus();
					return false;
				}
				if(fieldtype == "ListBox" && fieldvalue == "" || fieldtype == "RadioButton" && fieldvalue == ""  || fieldtype == "CheckBox" && fieldvalue == "")
				{
					alert("Enter Field Value");
					document.frm_updateform.FieldValue[i].focus();
					return false;
				}
			
			if(fieldvalue != "" && fieldtype == "ListBox" || fieldtype == "RadioButton" && fieldvalue != ""  || fieldtype == "CheckBox" && fieldvalue != "")
			{
				var atPos = fieldvalue.indexOf(';',0);
				if (atPos == 0) {
				   alert('Field value must not start with Semicolon');
				   document.frm_updateform.FieldValue[i].focus();
				   return false;
				}
				
			var len=fieldvalue.length;
			var atPos = fieldvalue.indexOf(';',(len-2));
			//alert(atPos);
			//alert((len-1));
						if (atPos == (len-1) ) {
				alert('Field value must not ends with ;');
				document.frm_updateform.FieldValue[i].focus();
			   return false;
			}
				var pos_colan = fieldvalue.indexOf(';;');
				if (pos_colan >= 0 ) {
				alert('More then one semicolan followed');
				document.frm_updateform.FieldValue[i].focus();
			   return false;
			}
				
			if(fieldvalue.indexOf("*") >= 0 || fieldvalue.indexOf("\\") >= 0 || fieldvalue.indexOf("/") >= 0  || fieldvalue.indexOf("\"") >= 0 || fieldvalue.indexOf("?") >= 0  || fieldvalue.indexOf(":") >= 0 || fieldvalue.indexOf("<") >= 0  || fieldvalue.indexOf(">") >= 0  || fieldvalue.indexOf("|") >= 0 || fieldvalue.indexOf(" ") >= 0 ) {
						alert("Field Value has invalid charactes such as space,/,\\,*,?,:,<,>,|,\"");
						document.frm_updateform.FieldValue[i].focus();
						return false;
						}
				}
		}
	}
	var check = 0;
	chklength = document.frm_updateform.displaymenu.length;
	for(chkindex = 0; chkindex < chklength; chkindex++){
		if (frm_updateform.displaymenu[chkindex].checked == false) {
			check += 1;
		}
	}
	if(chklength == check){
	alert("Please select any one of the mainmenu to display Form");
	return false;	
	}
	
return true;
}

function autoresponder_validate(){
		if (document.mailautoresponder.subject.value == "") 
		{
				alert ("Autoresponder subject is empty");
				document.mailautoresponder.subject.focus();
				return false;
		}
		if (document.mailautoresponder.days.value == "") 
		{
				alert ("Day to send mail is empty");
				document.mailautoresponder.days.focus();
				return false;
		}
		var days =document.mailautoresponder.days.value;
		if( isNaN(days) || days.indexOf('.') >= 0 || days.indexOf('-') >= 0){
				alert ("Please enter the day in numerals");
				document.mailautoresponder.days.focus();
				return false;
		}
}




window.onload=startList;