//  header.js - JavaScript Document

function display_state1() {
  //alert(document.register.state.selectedIndex);
  if(document.register.state.selectedIndex == 52) {
    document.getElementById("other_state").style.display = '';
  }
  else {
    document.getElementById("other_state").style.display = 'none';
  }
}

function displayIndustry() {
  //alert(document.register.industry.selectedIndex);
  if(document.register.industry.selectedIndex == 65) {
    document.getElementById("other_industry").style.display = '';
  }
  else {
    document.getElementById("other_industry").style.display = 'none';
  }
}

function changeAmount(amt) {
  document.getElementById('amount').value = amt;
}

function select_region(url)
{
	alert(url);
	for(i=0;i<count(region);i++)
	{
		if(region_name==region.options[i].value)
		{
			region.options[i].selected=true;
		}
	}
}
function change_url(url_local,region_index,region_name)
{

	//alert(url_local);
	//alert(region_name);
	hash_index=url_local.indexOf("/")+2;
	//alert(hash_index);
	dot_index=url_local.indexOf(".");
	//alert(dot_index);

	url_remove=url_local.substr(hash_index,dot_index-hash_index);
	//alert(url_remove);
	if(url_remove=="dbusinessnews")
	{
		url_http=url_local.substr(0,hash_index);
		url_region=url_http+region_name+"."+url_local.substr(hash_index,url_local.length)
		//alert(url_http);
		alert(url_region);
	}
	else
	{
		url_region=url_local.replace(url_remove,region_name);
	}
	//alert(url_region);
	document.location.href=url_region;

}

function change_ind_url(url_local,industry_index,industry_name)
{

	//alert(url_local);
	//alert(industry_name);
	hash_index=url_local.indexOf("/")+2;
	//alert(hash_index);
	dot_index=url_local.indexOf(".");
	//alert(dot_index);

	url_remove=url_local.substr(hash_index,dot_index-hash_index);
	//alert(url_remove);
	if(url_remove=="dbusinessnews")
	{
		url_http=url_local.substr(0,hash_index);
		url_industry=url_http+industry_name+"."+url_local.substr(hash_index,url_local.length)
		//alert(url_http);
	}
	else
	{
		url_industry=url_local.replace(url_remove,industry_name);
	}
	//alert(url_industry);
	document.location.href=url_industry;

}

function search_valid()
{
  if (document.f1.keyword.value == "")
   {
   alert("Please enter any keyword to search");
   return false;
   }

   document.f1.submit();
}

function search_news(news_txt)
{
  if (news_txt == "")
   {
   alert("Please enter any keyword to search");
   return false;
   }

  document.location.href="./newsresults.php?keyword_only&keyword="+news_txt;
}

function sendmail(newsid)
{

	//alert(newsid);
	var id=eval(newsid);
	window.open('./mailfriend.php?newsid='+id,'Mail','width=500,height=350');
}
function printnews(id)
{

	//alert("hello");
	document.location.href="./printnews.php?newsid="+id;
}
function printfront(id)
{

	//alert("hello");
	document.location.href="./printfront.php?articleid="+id;
}
function prod_desc(compid,home_page)
{
	//alert(home_page);
	window.open('./directorydesc.php?companyid='+compid,'home_page','width=400,height=300,resizable,scrollbars=yes');
}
function event_desc(eventid,home_page)
{
	//alert(home_page);
	window.open('./eventdesc.php?eventid='+eventid,'home_page','width=400,height=300,resizable,scrollbars=yes');
}
function classified_desc(adid,home_page)
{
	//alert(home_page);
	window.open('./classifieddesc.php?adid='+adid,'home_page','width=400,height=300,resizable,scrollbars=yes');
}
function inquiry(compname,home_page)
{
	//alert(home_page);
	window.open('./inquiryform.php?companyname='+compname,'home_page','width=400,height=500,scrollbars=yes');
}
function openjob(jobId,companyid)
{
	window.open('./more_results_job.php?jobid='+jobId+'&companyid='+companyid,'home_page','width=400,height=500,scrollbars=yes');
}
function opennews(newsid)
{
	window.open('./more_results_news.php?newsid='+newsid,'home_page','width=500,height=500,scrollbars=yes');
}
function openindnews(indnewsid)
{
	window.open('./more_results_news.php?indnewsid='+indnewsid,'home_page','width=500,height=500,scrollbars=yes');
}
function writestock(field)
{
	//alert(field);
	stock_value=stock_quote.options[field].value;
	window.open('./stock_ticker.php?stock_quote='+stock_value,'home_page','width=300,height=200');
}
/*function previewnews(content,title,region)
{
	window.open('./preview.php?content='+content+'&title='+title+'&region='+region,'home_page','width=500,height=500,resizable');
}*/

function previewnews()
{
	WYSIWYG.updateTextArea('contentnews');
	document.submit_news.action="preview.php";
	document.submit_news.target = '_new';
    document.submit_news.submit();
	//window.open('document.submit_news.submit();','home_page','width=500,height=500,resizable');
}
function preview_ind_news()
{
	document.submit_ind_news.action="preview.php";
	document.submit_ind_news.target = '_new';
    document.submit_ind_news.submit();
	//window.open('document.submit_news.submit();','home_page','width=500,height=500,resizable');
}
function news()
{
	//WYSIWYG.updateTextArea('contentnews');
	document.submit_news.action="submit_news.php";
	document.submit_news.target = '_self';
    document.submit_news.submit();
}
function news1(val)
{
	document.submit_news.Submit.value=val;
	document.submit_news.action="submit_news.php";
	document.submit_news.target = '_self';
    document.submit_news.submit();
}
function ind_news()
{
	document.submit_ind_news.action="submit_ind_news.php";
	document.submit_ind_news.target = '_self';
    document.submit_ind_news.submit();
}

function selectAll() {
		state=document.f1.editionall.checked;
		var checkbox = document.f1.elements['edition[]'];
		var cnt=checkbox.length;
		for (i = 0; i < cnt; i++) {
		checkbox[i].checked = state;
		}

}

function indselectAll() {
		state=document.f1.indeditionall.checked;
		var checkbox = document.f1.elements['indedition[]'];
		var cnt=checkbox.length;
		for (i = 0; i < cnt; i++) {
		checkbox[i].checked = state;
		}

}

// trim string
function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}
	// state for usa
function display_state(val)
{
	if(val == "United States")
	{
		document.getElementById("hidethis").style.display = '';
		//document.getElementById("displaythis").style.display = 'none';
		}
	else
	{
	document.getElementById("hidethis").style.display = 'none';
	//document.getElementById("displaythis").style.display = '';
	}
}

// state for usa
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true
	}

var digits = "0123456789";
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 IsNumeric(strString)
   //  check for valid numeric strings
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function chars(field,str)
{
	var valid;
	var ok = true;
	var temp;

	valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_.-";

	for (var i=0; i<field.value.length; i++)
	{
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = false;
	}
	if (!ok)
	{
		alert(str);
		field.focus();
		return false;
	}
	else
	{
		return true;
	}
}
function onchars(field,str)
{
	var valid;
	var ok = true;
	var temp;

	valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

	for (var i=0; i<field.value.length; i++)
	{
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = false;
	}
	if (!ok)
	{
		alert(str);
		field.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function ValidateForm(){

	var bl=" ";

	var FName=document.register.FName
	if (trim(FName.value)==""){
		alert("Please Enter your First Name")
		FName.focus()
		return false
	}
	else if((FName.value).indexOf(bl)!=-1){
	alert("First Name can't contain space between characters");
	FName.focus()
	return false;
	}
	else if (!chars(FName,"Enter only characters for First Name"))
		return false;

	var LName=document.register.LName
	if (trim(LName.value)==""){
		alert("Please Enter your Last Name")
		LName.focus()
		return false
	}
	else if((LName.value).indexOf(bl)!=-1){
	alert("Last Name can't contain space between characters");
	LName.focus()
	return false;
	}
	else if (!chars(LName,"Enter only characters for Last Name"))
		return false;

	var Title=document.register.Title
	if (trim(Title.value)==""){
		alert("Please Enter your Title")
		Title.focus()
		return false
	}
	else if((Title.value).indexOf(bl)!=-1){
	alert("Title can't contain space between characters");
	Title.focus()
	return false;
	}
	else if (!chars(Title,"Enter only characters for Title"))
		return false;

	var Company=document.register.Company
	if (trim(Company.value)==""){
		alert("Please Enter your Company Name")
		Company.focus()
		return false
	}
	else if (isInteger(Company.value))
	{
	   alert("Error!!! Please Check your Company");
	   Company.focus();
	   return false;
	}

	var Address=document.register.Address
	if (trim(Address.value)==""){
		alert("Please Enter your Address")
		Address.focus()
		return false
	}
	else if (isInteger(Address.value))
	{
	   alert("Error!!! Please Check your Address");
	   Address.focus();
	   return false;
	}

	var City=document.register.City
	if (!chars(City,"Enter only characters for City"))
		return false;

	//if (!chars(State,"Enter only characters for State"))
		//return false;

	var Zip=document.register.Zip
	if ((Zip.value==null)||(Zip.value=="")){
		alert("Please Enter your Zip Code")
		Zip.focus()
		return false
	}
	else if (!isInteger(Zip.value))
	{
	   alert("Error!!! Zip code must be Number only");
	   Zip.focus();
	   return false;
	}

	var country=document.register.country
	if (country.value==""){
		alert("Please Select your Country")
		country.focus()
		return false;
	}

	if (country.value=="United States")
	{
		var State=document.register.State
		if (State.value=="")
		{
			alert("Please Select the State of USA")
			State.focus()
			return false
		}
	}


	var Phone=document.register.Phone
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Phone Number")
		Phone.focus()
		return false;
	}
	else if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid Phone Number, Valid format Ex: 919-349-8192")
		Phone.focus()
		return false
	}

	if(Phone.value) {
		var pattern = /\d{3}-\d{3}-\d{4}/;
		if(!pattern.test(Phone.value)) {
		alert("Please Enter a Valid Phone Number, Valid format Ex: 919-349-8192")
		Phone.focus()
		return false
	}

	var emailID=document.register.Email
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}

	return true
 }
 }




function change_ind_url_onlinedirectory(url_local,industry_index,industry_name,categoryid,subcategoryid)
{

	if ( 0 ) alert('url_local is '+url_local);
	if ( 0 ) alert('industry_index is '+industry_index);
	if ( 0 ) alert('industry_name is '+industry_name);
	hash_index=url_local.indexOf("/")+2;
	if ( 0 ) alert('hash_index is: '+hash_index);
	dot_index=url_local.indexOf(".");
	if ( 0 ) alert('dot_index is: '+dot_index);

	url_remove=url_local.substr(hash_index,dot_index-hash_index);
	if ( 0 ) alert('url_remove is: '+url_remove);
	if(url_remove=="dbusinessnews")
	{
		url_http=url_local.substr(0,hash_index);
		url_industry=url_http+industry_name+"."+url_local.substr(hash_index,url_local.length)
		if ( 0 ) alert('url_http is: '+url_http);
	}
	else
	{
		url_industry=url_local.replace(url_remove,industry_name);
	}
	url_industry += '/onlinedirectory.php?categoryid='+categoryid+'&subcategoryid='+subcategoryid;
	if ( 0 ) alert('url_industry is: '+url_industry);
	document.location.href=url_industry;

}


function change_url_onlinedirectory(url_local,region_index,region_name,categoryid,subcategoryid)
{

	if ( 0 ) alert('url_local is '+url_local);
	if ( 0 ) alert('region_name is '+region_name);
	hash_index=url_local.indexOf("/")+2;
	if ( 0 ) alert('hash_index is '+hash_index);
	dot_index=url_local.indexOf(".");
	if ( 0 ) alert('dot_index is '+dot_index);

	url_remove=url_local.substr(hash_index,dot_index-hash_index);
	if ( 0 ) alert('url_remove is '+url_remove);
	if(url_remove=="dbusinessnews")
	{
		url_http=url_local.substr(0,hash_index);
		url_region=url_http+region_name+"."+url_local.substr(hash_index,url_local.length)
		if ( 0 ) alert('url_http is '+url_http);
		alert(url_region);
	}
	else
	{
		url_region=url_local.replace(url_remove,region_name);
	}
	url_region += '/onlinedirectory.php?categoryid='+categoryid+'&subcategoryid='+subcategoryid;
	if ( 0 ) alert('url_region is: '+url_region);
	document.location.href=url_region;

}




function change_url_categories_directory(url_local,region_index,region_name)
{

	if ( 0 ) alert('url_local is '+url_local);
	if ( 0 ) alert('region_name is '+region_name);
	hash_index=url_local.indexOf("/")+2;
	if ( 0 ) alert('hash_index is '+hash_index);
	dot_index=url_local.indexOf(".");
	if ( 0 ) alert('dot_index is '+dot_index);

	url_remove=url_local.substr(hash_index,dot_index-hash_index);
	if ( 0 ) alert('url_remove is '+url_remove);
	if(url_remove=="dbusinessnews")
	{
		url_http=url_local.substr(0,hash_index);
		url_region=url_http+region_name+"."+url_local.substr(hash_index,url_local.length)
		if ( 0 ) alert('url_http is '+url_http);
		alert(url_region);
	}
	else
	{
		url_region=url_local.replace(url_remove,region_name);
	}
	url_region += '/categories_directory.php';
	if ( 0 ) alert('url_region is: '+url_region);
	document.location.href=url_region;

}

