// JavaScript Document

function MM_findObj(n, d) 
{ 
	file://v4.0
	 var p,i,x;  if(!d) d=document;	
	 if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document;
	 n=n.substring(0,p);}
   if(!(x=d[n])&&d.all) x=d.all[n]; for
 	(i=0;!x&&i<d.forms.length;i++) x=d.forms[n];
   for(i=0;!x&&d.layers&&i<d.layers.length;i++)
 x=MM_findObj(n,d.layers.document);
   if(!x && document.getElementById)
 x=document.getElementById(n); return x;
 }
 
function popup(url)
{
	var popup  = window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=700,height=520,screenX=50,screenY=50,top=50,left=50');
	popup.focus();
}
function popupCFBD(url)
{
	var popup  = window.open(url,'cfbdpopupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=890,height=750,screenX=50,screenY=50,top=50,left=50');
	popup.focus();
}
function popupCFBD1(url)
{
	var popup  = window.open(url,'cfbdpopupWindow1','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=775,height=750,screenX=50,screenY=50,top=50,left=50');
	popup.focus();
}
function popupCFBD2(url)
{
    var popup  = window.open(url,'cfbdpopupWindow2','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=890,screenX=50,screenY=50,top=50,left=50');
    popup.focus();
}
//used in opening search results only
function popupBigWindow(url)
{
	var bigPopup  = window.open(url,'bigPopupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=700,height=820,screenX=50,screenY=50,top=50,left=50');
	bigPopup.focus();
}

//used in opening bible chapters and search tools only
function popupBibleChapter(url)
{
	var chapterPopup  = window.open(url,'chapterPopupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=1200,height=700,screenX=50,screenY=50,top=50,left=50');
	chapterPopup.focus();
}

function popupBibleChapter(url)
{
	var chapterPopup  = window.open(url,'sponsor','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=950,height=500,screenX=50,screenY=50,top=50,left=50');
	chapterPopup.focus();
}

function newpopup(url)
{
	var newpopup  = window.open(url,'newpopupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=700,height=520,screenX=50,screenY=50,top=50,left=50');
	newpopup.focus();
}

function bible_search( url ) 
{
	var bibleSearchPopup  = window.open(url,'bibleSearchWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=950,height=500,screenX=50,screenY=50,top=50,left=50');
	bibleSearchPopup.focus();
}

//function newpopup1(url)
//{
//	var newpopup  = window.open(url,'newpopupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=700,height=520,screenX=50,screenY=50,top=50,left=50');
//	newpopup.focus();
//}

function open_in_new_window( url )
{
	var checkStr	=		url.substr(0,4);
	if( checkStr   ==  'http')
	{
		window.open( url , 'popup', ',type=fullWindow,fullscreen,scrollbars=yes');
	}
	else
	{
		location.href = url;
	}
}

var PositionX = 100;
var PositionY = 100;
var defaultWidth  = 500;
var defaultHeight = 500;
var AutoClose = true;
if (parseInt(navigator.appVersion.charAt(0))>=4)
{
	var isNN=(navigator.appName=="Netscape")?1:0;
 	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;
}
 	var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
 	var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;

function popImage(imageURL,imageTitle)
{
   if (isNN){imgWin=window.open('about:blank','',optNN);}
   if (isIE){imgWin=window.open('about:blank','',optIE);} 
   with (imgWin.document)
   {
		 writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
		 writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		 writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		 writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
		 writeln('width=100-(document.body.clientWidth-document.images[0].width) + 150;');
		 writeln('height=100-(document.body.clientHeight-document.images[0].height);');
		 writeln('window.resizeTo(width,height);}');writeln('if (isNN){');      
		 writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
		 writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
		 if (!AutoClose) 
			writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
		 else
			writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" >');
			writeln('<img name="George" src='+imageURL+' style="display:block" usemap="#Map"><map name="Map" id="Map"><area shape="rect" coords="21,36,366,71" href="http://www.completecomm.net"  alt="Completecomm.net" target="_blank"/></map></body></html>');
		close();         
 	}
}


function match_password ( )
{	
	var frm = document.forms["signupForm"];
	if( frm.password1.value != frm.password2.value)
  	{
    	return false;
  	}
}

function checkbox_validation()
{
	var frm = document.forms["signupForm"];
	if( frm.privacy.checked != true )
	{
		return false;
	}
}

function DoCustomRegisterValidation()
{
  var frm = document.forms["signupForm"];
  if(false == match_password())
  {
    alert('The Password and confirm password does not match!');
    return false;
  }
  else if(false == checkbox_validation())
  {
    alert('Please accept terms and services!');
    return false;
  }
  else
  {
    return true;
  }
}

// JavaScript Document

// ################################### Common Ajax Functions with GET Method Starts Here ###########################
var xmlHttp
function showContents(divID,url)
{
	//alert(url);
	//return false;
	
	document.getElementById(divID).innerHTML="";
 
	xmlHttp		=	GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	//var url="getcity.php"
	//url=url+"?q="+str
	url=url+"&pid="+Math.random()

	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	
	function stateChanged() 
	{ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 		{ 
 			document.getElementById(divID).innerHTML=xmlHttp.responseText 
 		} 
	}

}
// ################################### Common Ajax For Check Availability Starts Here ###########################
function showavl(user,email)
{
	var url="chkavailablity.php";
	xmlHttp		=	GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	url=url+"?user="+user+"&email="+email;
    xmlHttp.onreadystatechange=stateChanged1 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	
	function stateChanged1() 
	{ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 		{
				document.getElementById('userAvl').innerHTML	=	xmlHttp.responseText;
 		}
		else
		{
			document.getElementById('userAvl').innerHTML	=	"Checking.....";
		}
	}

}

function hitcounter(id)
{
   var url="hitcounter.php";
   xmlHttp        =    GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    }
    url=url+"?id="+id;
    xmlHttp.onreadystatechange=stateChanged1 
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
    
    function stateChanged1() 
    { 
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
         {
                //document.getElementById('userAvl').innerHTML    =    xmlHttp.responseText;
                return true;
         }
        else
        {
              //document.getElementById('userAvl').innerHTML    =    "Checking.....";
              return true;
        }
    } 
}
function bannercounter(id)
{
   var url="bannercounter.php";
   xmlHttp        =    GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    }
    url=url+"?id="+id;
    xmlHttp.onreadystatechange=stateChanged2 
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
    
    function stateChanged2() 
    { 
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
         {
                //document.getElementById('userAvl').innerHTML    =    xmlHttp.responseText;
                return true;
         }
        else
        {
              //document.getElementById('userAvl').innerHTML    =    "Checking.....";
              return true;
        }
    } 
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		//Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
function checkSearchField(searchField)
{
		if(document.getElementById(searchField).value=='')
		{
			alert('Please enter a keyword to search.');
			return false;
		}
}

function openSearchTools(value)
{
	//var string =   value.substr(0,4);
    if(value   ==  'index.php')
    {
        location.href = "index.php";
    }
    else if(value.substr(0,4)   !=  'http')
    {
        popup( value );
    } 
	else
	{
		popupBibleChapter('search_tools.php?action=modal&url='+value);
	}
}

function change_free_listing( imgID )
{
	var imgID	=	document.getElementById( imgID );
	var src		=	imgID.src;
	var divID	=	document.getElementById( 'freeImage');
	var src		=	src.substr(src.lastIndexOf('/')+1, src.length );
	if( src == 'free_listing1.gif')
	{
		divID.innerHTML='<img src="images/free_listing2.gif" id="freeListing" name="freeListing" usemap="#Map" border="0" align="center" alt="Free CFBD Listing" title="Free CFBD Listing"/>';
		Set_Cookie( 'cookie_free_cfbd_img','images/free_listing2.gif', '30', '/', '', '' );
	}
	else
	{
		divID.innerHTML='<img src="images/free_listing1.gif" id="freeListing" name="freeListing" usemap="#Map" border="0" align="center" alt="Free CFBD Listing" title="Free CFBD Listing"/>';
		Set_Cookie( 'cookie_free_cfbd_img','images/free_listing1.gif', '30', '/', '', '' );
	}
}

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}
// ################################### Common Ajax Functions with GET Method Ends Here ###########################

//////////////////////////////   Sanjay Code    ////////////////////////////////////////////////////
function showAgg(v1)
{
	if(v1=="2")
	{
		document.getElementById('agg').style.display="inline";
	}
	else
	{
		document.getElementById('agg').style.display="none";
	}
}

function allValidChars(email)
{
  
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}


function validateForm(frm)
{
	if((frm.fName.value=="") || (frm.fName.value=="Your First Name"))
	{
		alert("Enter Your First Name");
		frm.fName.focus();
		return false;
	}
	if((frm.lName.value=="") || (frm.lName.value=="Your last Name"))
	{
		alert("Enter Your Last Name");
		frm.lName.focus();
		return false;
	}
	if((frm.title.value=="") || (frm.title.value=="Your Title"))
	{
		alert("Enter Your Title");
		frm.title.focus();
		return false;
	}
	if((frm.phoneNo_1.value=="") || (frm.phoneNo_1.value=="000"))
	{
		alert("Enter Phone Number");
		frm.phoneNo_1.focus();
		return false;
	}
	if((frm.phoneNo_2.value=="") || (frm.phoneNo_2.value=="000"))
	{
		alert("Enter Phone Number");
		frm.phoneNo_2.focus();
		return false;
	}
	if((frm.phoneNo_3.value=="") || (frm.phoneNo_3.value=="0000"))
	{
		alert("Enter Phone Number");
		frm.phoneNo_3.focus();
		return false;
	}
	if((frm.email.value=="") || (frm.email.value=="Your Email"))
	{
		alert("Enter Your Email");
		frm.email.focus();
		return false;
	}
	if (! allValidChars(frm.email.value))
    {
        alert("Enter Your Email in valid format");
        return false;
    }
    if (frm.email.value.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        alert("Enter Your Email in valid format");
        frm.email.focus(); 
        return false;
    } else if (frm.email.value.lastIndexOf(".") <= frm.email.value.indexOf("@")) {  // last dot must be after the @
        alert("Enter Your Email in valid format");
        frm.email.focus(); 
        return false;
    } else if (frm.email.value.indexOf("@") == frm.email.value.length) {  // @ must not be the last character
        alert("Enter Your Email in valid format");
        frm.email.focus(); 
        return false;
    } else if (frm.email.value.indexOf("..") >=0) { // two periods in a row is not valid
        alert("Enter Your Email in valid format");
        frm.email.focus(); 
        return false;
    } else if (frm.email.value.indexOf(".") == frm.email.value.length) {  // . must not be the last character
        alert("Enter Your Email in valid format");
        frm.email.focus(); 
        return false;
    }
    
    if((frm.compName.value=="") || (frm.compName.value=="Advertiser’s Organizational Name"))
	{
		alert("Enter Company Name");
		frm.compName.focus();
		return false;
	}
	if((frm.bizType.value==""))
	{
		alert("Select Biz Type");
		frm.bizType.focus();
		return false;
	}
	if((frm.compPhoNo_1.value=="") || (frm.compPhoNo_1.value=="000"))
	{
		alert("Enter Advertiser Phone");
		frm.compPhoNo_1.focus();
		return false;
	}
	if((frm.compPhoNo_2.value=="") || (frm.compPhoNo_2.value=="000"))
	{
		alert("Enter Advertiser Phone");
		frm.compPhoNo_2.focus();
		return false;
	}
	if((frm.compPhoNo_3.value=="") || (frm.compPhoNo_3.value=="0000"))
	{
		alert("Enter Advertiser Phone");
		frm.compPhoNo_3.focus();
		return false;
	}
	
	if((frm.streetAdd.value=="") || (frm.streetAdd.value=="Street Name/P.O.Box: UPS will not deliver to a P.O. Box"))
	{
		alert("Enter Street Name");
		frm.streetAdd.focus();
		return false;
	}
	if((frm.compCity.value=="") || (frm.compCity.value=="City"))
	{
		alert("Enter City");
		frm.compCity.focus();
		return false;
	}
	if((frm.compState.value==""))
	{
		alert("Select Advertiser State");
		frm.compState.focus();
		return false;
	}
	if((frm.compZip.value=="") || (frm.compZip.value=="Zip"))
	{
		alert("Enter Zip Code");
		frm.compZip.focus();
		return false;
	}
	if((frm.compCounty.value=="") || (frm.compCounty.value=="County"))
	{
		alert("Enter County");
		frm.compCounty.focus();
		return false;
	}
	if((frm.compCountry.value==""))
	{
		alert("Select Advertiser Country");
		frm.compCountry.focus();
		return false;
	}
	if((frm.compMarkArea.value==""))
	{
		alert("Select Advertiser Marketing Area");
		frm.compMarkArea.focus();
		return false;
	}
	if((frm.compEmail.value=="") || (frm.compEmail.value=="Advertiser Email"))
	{
		alert("Enter Advertise Email");
		frm.compEmail.focus();
		return false;
	}
    if (! allValidChars(frm.compEmail.value))
    {
        alert("Enter Company Email in valid format");
        return false;
    }
    if (frm.compEmail.value.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        alert("Enter Company Email in valid format");
        frm.email.focus(); 
        return false;
    } else if (frm.compEmail.value.lastIndexOf(".") <= frm.email.value.indexOf("@")) {  // last dot must be after the @
        alert("Enter Company Email in valid format");
        frm.email.focus(); 
        return false;
    } else if (frm.compEmail.value.indexOf("@") == frm.email.value.length) {  // @ must not be the last character
        alert("Enter Company Email in valid format");
        frm.email.focus(); 
        return false;
    } else if (frm.compEmail.value.indexOf("..") >=0) { // two periods in a row is not valid
        alert("Enter Company Email in valid format");
        frm.email.focus(); 
        return false;
    } else if (frm.compEmail.value.indexOf(".") == frm.compEmail.value.length) {  // . must not be the last character
        alert("Enter Company Email in valid format");
        frm.email.focus(); 
        return false;
    }
	if((frm.compUrl.value=="") || (frm.compUrl.value=="Advertiser Website"))
	{
		alert("Enter Advertise Website");
		frm.compUrl.focus();
		return false;
	}
	for(var i = 0; i < frm.aar.length; i++)
	{
		if(frm.aar[i].checked)
		{
			if(frm.aar[i].value==2)
			{
				if((frm.agName.value=="") || (frm.agName.value=="Name of Ad Agency"))
				{
					alert("Enter Agency Name");
					frm.agName.focus();
					return false;
				}
				if((frm.agPhone_1.value=="") || (frm.agPhone_1.value=="000"))
				{
					alert("Enter Agency Phone");
					frm.agPhone_1.focus();
					return false;
				}
				if((frm.agPhone_2.value=="") || (frm.agPhone_2.value=="000"))
				{
					alert("Enter Agency Phone");
					frm.agPhone_2.focus();
					return false;
				}
				if((frm.agPhone_3.value=="") || (frm.agPhone_3.value=="0000"))
				{
					alert("Enter Agency Phone");
					frm.agPhone_3.focus();
					return false;
				}
				if((frm.agStreetAdd.value=="") || (frm.agStreetAdd.value=="Street Name/P.O.Box"))
				{
					alert("Enter Agency Street Name");
					frm.agStreetAdd.focus();
					return false;
				}
				if((frm.agCity.value=="") || (frm.agCity.value=="City"))
				{
					alert("Enter Agency City");
					frm.agCity.focus();
					return false;
				}
				if((frm.agZip.value=="") || (frm.agZip.value=="Zip"))
				{
					alert("Enter Agency Zip");
					frm.agZip.focus();
					return false;
				}
				if((frm.agState.value==""))
				{
					alert("Select Agency State");
					frm.agState.focus();
					return false;
				}
				if((frm.agUrl.value=="") || (frm.agUrl.value=="Advertiser Website"))
				{
					alert("Enter Agency Website");
					frm.agUrl.focus();
					return false;
				}
			}
		}
	}
	var marLen		=	document.getElementById('marketingArr[]').length;
	for(i=0; i<marLen; i++)
	{
		document.getElementById('marketingArr[]').options[i].selected = true;
	}
    return true;
}

function populate_services( ID, url )
{
	url			=	url+'?ID='+ID;
	var myAjax 	= 	new Ajax.Request( url, {method: 'post', onLoading: servicesLoad , onComplete: servicesResponse} );
}

function servicesLoad () 
{
	$('servicesLoad').style.display = 'block';
}
function servicesResponse (originalRequest) 
{
	$('servicesLoad').style.display = 	'none';
	$('compMarkArea1').innerHTML	=	originalRequest.responseText;	
}

function addList(id)
{
	if(id==4)
	{
		document.getElementById("marketingArr[]").options.add(new Option(document.getElementById ("markState[]").options[document.getElementById("markState[]").selectedIndex].text,'st_'+document.getElementById ("markState[]").options[document.getElementById("markState[]").selectedIndex].value));
		document.getElementById("markState[]").options[document.getElementById("markState[]").selectedIndex]=null;
	}
	else if(id==5)
	{
		document.getElementById("marketingArr[]").options.add(new Option(document.getElementById ("markRegion[]").options[document.getElementById("markRegion[]").selectedIndex].text,'rn_'+document.getElementById ("markRegion[]").options[document.getElementById("markRegion[]").selectedIndex].value));
		document.getElementById("markRegion[]").options[document.getElementById("markRegion[]").selectedIndex]=null;
	}
	else
	{
		document.getElementById("marketingArr[]").options.add(new Option(document.getElementById ("markCountry[]").options[document.getElementById("markCountry[]").selectedIndex].text,'cn_'+document.getElementById ("markCountry[]").options[document.getElementById("markCountry[]").selectedIndex].value));
		document.getElementById("markCountry[]").options[document.getElementById("markCountry[]").selectedIndex]=null;
	}
	
}

function removeList()
{
	document.getElementById("marketingArr[]").options[document.getElementById("marketingArr[]").selectedIndex]=null;
}

function imagePreview()
{
	document.getElementById('preview').src=document.getElementById('fileName').value;
}

function validateImageForm(frm)
{
	if((frm.fileName.value)=="")
	{
		alert("Browse Ad");
		return false;
	}
	return true;
}

//////////////////////////  End Sanjay Code   //////////////////////////////////////////////////////



