function SetDefaultColors() {
		 parent.frame1.document.form_input.header_bg.options[9].selected = 1;
		 parent.frame1.document.form_input.header_font_color.options[0].selected = 1;
		 parent.frame1.document.form_input.header_bold.value = 1;
		 parent.frame1.document.form_input.body_bg.options[22].selected = 1;
		 parent.frame1.document.form_input.body_font_color1.options[1].selected = 1;
		 parent.frame1.document.form_input.body_font_color2.options[1].selected = 1;

		 return ;


}

function switch_font(a) {
		 if (document.form_input.elements[a].value == 1) {document.form_input.elements[a].value = 0;}
		 else {document.form_input.elements[a].value = 1;}
		 return ;

}


function changeCSSproperty() {
	
	 var str="";
	 var id = 0;
	 var align;
	 var bold = 0;
	 var italic = 0;
	 var font;
	 var font_color;
	 var font_size;
	 var height;
	 var h=0;
	 var body_h=0;
	 var row_h;
	 var lines = parent.frame1.document.form_input.lines.value;
	 var header = parent.frame1.document.form_input.header_text.value ;
	 var def_text = 'Header Text';
	 if (header==def_text) {header = header+' ...Edit This Line In Text Box Below';}

   var msie = (navigator.userAgent.toLowerCase().indexOf('msie') != -1);
   var ns6 = (navigator.userAgent.toLowerCase().indexOf('netscape6') != -1);
   if (msie || ns6){

	 }else{
 	  if(lines="null") {lines=2;}
         }

	 // Check chars number

	 font_size = parent.frame1.document.form_input.header_font_size.selectedIndex + 10;
	 if (!CheckString(header, parent.frame1.document.form_input.header_font.selectedIndex, font_size)) {return false;}
	

	 // Determine height
	/* if (parent.frame1.document.form_input.height.length==4)
	 {
		for (var i = 0; i < parent.frame1.document.form_input.height.length; i++)
		{
		 if(parent.frame1.document.form_input.height[i].checked==true)   { height =parent.frame1.document.form_input.height[i].value;}
		}
	 }

	 else {height =parent.frame1.document.form_input.height.value;}
	 
	 */

	 
	 
	 
	 for (var i = 0; i < document.form_input.height.length; i++)
	 {
	  if(parent.frame1.document.form_input.height[i].checked==true)
		{ height = parent.frame1.document.form_input.height[i].value ; }
	 }

	 if(!height) height=document.form_input.height.value ;


	 row_h = height/(lines+ 1);


 	 for (i=1; i<=lines; i++)
	 {
	  id = "adtext"+i;
	  bold="body_bold"+i;
	  italic="body_italic"+i;
	  font="body_font"+i;
	  font_size="body_font_size"+i;
	  body_text = parent.frame1.document.getElementById(id).value;
	  def_text = 'Body Text Line '+i;
		if (body_text==def_text) {body_text = body_text+' ...Edit This Line In Text Box Below';}
	 // if (!CheckString(body_text, parent.frame1.document.getElementById(font).selectedIndex, parent.frame1.document.getElementById(font_size).selectedIndex+10)) {return false;}
	  if (parent.frame1.document.getElementById(bold).value==1) { body_text="<b>"+body_text+"</b>" ;}
	  if (parent.frame1.document.getElementById(italic).value==1) { body_text="<i>"+body_text+"</i>" ;}

	  str= str+"<tr><td id='adtext"+i+"' width=100% height="+row_h+" >" + body_text + "</td></tr>";
	  body_h=body_h + 4 + parent.frame1.document.getElementById(font_size).selectedIndex + 9 ;
	 }



	 h = parent.frame1.document.form_input.header_font_size.selectedIndex + 10 + 6 + body_h;
	 if ( h > height)
	 {
		 alert ('Font is too big for this ad size\nPlease choose a smaller font!'); return;
	 }

	if (parent.frame1.document.form_input.header_bold.value==1) { header="<b>"+header+"</b>" ;}
	if (parent.frame1.document.form_input.header_italic.value==1) { header="<i>"+header+"</i>" ;}


     parent.frame0.document.write("<html><body topmargin=10 bgcolor=#E1DDC6><div align=center><center><table border=0 cellpadding=0 cellspacing=0 width=100% height=100%><tr><td valign=middle><div align=center><table id=body border=0 cellpadding=2 cellspacing=0 width=468 height="+height+"><tr><td width=100% id=header bgcolor='#93203D' height="+row_h+">" + header + "</td></tr>" + str + "</table></div></td></tr></table></center></div></body></html>");
     parent.frame0.document.close();

	 parent.frame0.document.getElementById('body').style['height']= height;
	 parent.frame0.document.getElementById('header').style['background']=parent.frame1.document.form_input.header_bg.options[parent.frame1.document.form_input.header_bg.selectedIndex].value;
     parent.frame0.document.getElementById('header').style['color']=parent.frame1.document.form_input.header_font_color.options[parent.frame1.document.form_input.header_font_color.selectedIndex].value;
     parent.frame0.document.getElementById('header').style['font']=parent.frame1.document.form_input.header_font_size.options[parent.frame1.document.form_input.header_font_size.selectedIndex].value + " " + parent.frame1.document.form_input.header_font.options[parent.frame1.document.form_input.header_font.selectedIndex].value;
     parent.frame0.document.getElementById('header').align=parent.frame1.document.form_input.header_align.value;

	for (i=1; i<=lines; i++)
    {
     id = "adtext"+i;
	 align="body_align"+i;
	 font="body_font"+i;
	 font_color="body_font_color"+i;
	 font_size="body_font_size"+i;
	 parent.frame0.document.getElementById('body').style['background']=parent.frame1.document.form_input.body_bg.options[parent.frame1.document.form_input.body_bg.selectedIndex].value;
	 parent.frame0.document.getElementById(id).style['background']=parent.frame1.document.form_input.body_bg.options[parent.frame1.document.form_input.body_bg.selectedIndex].value;
	 parent.frame0.document.getElementById(id).style['font']=parent.frame1.document.getElementById(font_size).options[parent.frame1.document.getElementById(font_size).selectedIndex].value + " " + parent.frame1.document.getElementById(font).options[parent.frame1.document.getElementById(font).selectedIndex].value;
	 parent.frame0.document.getElementById(id).style['color']=parent.frame1.document.getElementById(font_color).options[parent.frame1.document.getElementById(font_color).selectedIndex].value;
	 parent.frame0.document.getElementById(id).align=parent.frame1.document.getElementById(align).value;

    }

     return;
}


//////////////////////////////// Print Body Form//////////////////////////////////////////

function CheckString(str, font,font_size)
{
var multiplier;
var text='Text is too long... WARNING! Ads will be rejected if any individual text line exceeds one line!';

if (font==0) {multiplier = 1;}				// Verdana
else if (font==1) {multiplier = 1.1;}		// Comic Sans MS
else if (font==2) {multiplier = 1.16;}		// Arial
else if (font==3) {multiplier = 0.6;}		// Courier
else if (font==4) {multiplier = 1.35;}		// Times Roman
else			  {multiplier = 1;}			// others

if (font_size==9  && str.length>90*multiplier)		{alert(text);return false;}
if (font_size==10 && str.length>86*multiplier)		{alert(text);return false;}
if (font_size==11 && str.length>76*multiplier)		{alert(text);return false;}
if (font_size==12 && str.length>75*multiplier)		{alert(text);return false;}
if (font_size==13 && str.length>69*multiplier)		{alert(text);return false;}
if (font_size==14 && str.length>63*multiplier)		{alert(text);return false;}
if (font_size==15 && str.length>60*multiplier)		{alert(text);return false;}
if (font_size==16 && str.length>57*multiplier)		{alert(text);return false;}
if (font_size==17 && str.length>49*multiplier)		{alert(text);return false;}
if (font_size==18 && str.length>47*multiplier)		{alert(text);return false;}
if (font_size==19 && str.length>45*multiplier)		{alert(text);return false;}
if (font_size==20 && str.length>43*multiplier)		{alert(text);return false;}
if (font_size==21 && str.length>41*multiplier)		{alert(text);return false;}
if (font_size==22 && str.length>38*multiplier)		{alert(text);return false;}
if (font_size==23 && str.length>36*multiplier)		{alert(text);return false;}
if (font_size==24 && str.length>34*multiplier)		{alert(text);return false;}
if (font_size==25 && str.length>33*multiplier)		{alert(text);return false;}

return true;
}

function ReloadForm(def)
{
 if (def) {parent.frame1.document.form_input.h_change.value = 1;}

//SetCost();

parent.frame1.document.form_input.action='frame1.php';
parent.frame1.document.form_input.submit();

}


function ProcessSubmit()
{
 if (!CheckText()) { return false; }
 for (var i = 0; i < parent.frame1.document.form_input.height.length; i++)
 {
  if(parent.frame1.document.form_input.height[i].checked==true)   { parent.frame1.document.form_input.height.value =parent.frame1.document.form_input.height[i].value;  }
 }

//SetCost();

 parent.frame1.document.form_input.action="advertiser_info.php";
 parent.frame1.document.form_input.submit();
}

function CheckText()
{
 if (parent.frame1.document.form_input.header_text.value=='Header Text' ) { alert('Please enter your header text'); return false;}
 for (var i = 1; i <= parent.frame1.document.form_input.lines.value; i++)  {
        id = "adtext"+i;
	body_text = parent.frame1.document.getElementById(id).value;
        def_text = 'Body Text Line '+i;
        if ( body_text==def_text ) { alert('Please enter your body text line '+i); return false;}
        }
 return true;
}


function CheckAgreeTerms()
{
	var radioSelected = false;
	for (i = 0;  i < document.form_input.agree.length;  i++)
	{
        if ((document.form_input.agree[i].value == 'agree') && (document.form_input.agree[i].checked))
			{
			radioSelected = true;
			}
	}

	if (!radioSelected)
		{
		alert("Please read and agree to the \"Term of Advertising\" options.");
		return (false);
		}
	return true;
}



function CheckUserData()
{  
  if (document.form_input.login_email.value.length>1)   {  LogIn(); return false; }

  if ((document.form_input.fname.value == "") || (document.form_input.fname.value.length < 1))
  {
    alert("Please enter your First Name.");
    document.form_input.fname.focus();
    return (false);
  }


  if ((document.form_input.lname.value == "") || (document.form_input.lname.value.length < 1))
  {
    alert("Please enter your Last Name");
    document.form_input.lname.focus();
    return (false);
  }

  if ((document.form_input.address1.value == "") || (document.form_input.address1.value.length < 1))
  {
    alert("Please enter Address 1");
    document.form_input.address1.focus();
    return (false);
  }

  if ((document.form_input.city.value == "") || (document.form_input.city.value.length < 1))
  {
    alert("Please enter your City");
    document.form_input.city.focus();
    return (false);
  }


  if (document.form_input.state.selectedIndex < 0)
  {
    alert("Please select your State");
    document.form_input.state.focus();
    return (false);
  }

  if (document.form_input.zip.value == "") {
    alert("Please enter your Zip");
    document.form_input.zip.focus();
    return (false);
  }
  else 
 {
	  if (document.form_input.country.value == "US")
	  {
		  if (document.form_input.zip.value.length < 5)  { alert("Please enter at least 5 characters in the \"Zip\" field.");document.form_input.zip.focus();	return (false); }
		  else 
			  { 
			     if ( !isZIPCode (document.form_input.zip.value) ) 	  {	alert("US zip code should contain 5 or 9 digits.");document.form_input.zip.focus();	return (false);   }
			     else { var z =StripDigits(document.form_input.zip.value) ; if ( z.length==9)	{	z =z.charAt(0)+z.charAt(1)+z.charAt(2)+z.charAt(3)+z.charAt(4)+"-"+z.charAt(5)+z.charAt(6)+z.charAt(7)+z.charAt(8) ;    }  document.form_input.zip.value = z;  }   
			  }
	  }

  }

  if (document.form_input.country.selectedIndex < 0)
  {
    alert("Please select your Country");
    document.form_input.country.focus();
    return (false);
  }

  if (document.form_input.phone.value == "")
  {
    alert("Please enter your Phone");
    document.form_input.phone.focus();
    return (false);
  }
  
  if (document.form_input.country.value == "US")
  {
	var t, f;
	if  (t = CheckPhone(document.form_input.phone.value)) { document.form_input.phone.value =  t ;}
	else { alert(" Phone number must be 10 digits !"); document.form_input.phone.focus(); return (false); }

	if (document.form_input.fax.value != "")
	{
			if  (f = CheckPhone(document.form_input.fax.value)) { document.form_input.fax.value =  f ;}
			else { alert(" Fax number must be 10 digits !"); document.form_input.fax.focus(); return (false); }
	}

  }


  if (!CheckEmail(document.form_input.emailname.value))
  {document.form_input.emailname.focus(); return false; }
   

  if (document.form_input.password.value == "")
  {
    alert("Please enter a Password");
    document.form_input.password.focus();
    return (false);
  }

  if (document.form_input.password.value.length < 6)
  {
    alert("Please enter at least 6 characters in the Password field.");
    document.form_input.password.focus();
    return (false);
  }

  if (document.form_input.password.value.length > 20)
  {
    alert("Please enter at most 20 characters in the Password field.");
    document.form_input.password.focus();
    return (false);
  }

  //if (document.form_input.password.value != document.form_input.password1.value)
  //{
  //  alert("Password and Confirm Password don't match !");
  //  document.form_input.password.focus();
  //  return (false);
  //}


  document.form_input.action="add_banner.php";
  return true; 
}

function isZIPCode (s)
{	
   s = StripDigits(s) ;
   return  ((s.length == 5)  ||  (s.length == 9))
}


function CheckPhone(str)
{
   var n =   StripDigits(str) ;
   if (n.length != 10)  {  return false; }
   else
   {
     var t =  "(" + n.charAt(0) + n.charAt(1)+ n.charAt(2)+") "+ n.charAt(3)+ n.charAt(4)+ n.charAt(5)+ "-"+n.charAt(6)+ n.charAt(7) + n.charAt(8)+ n.charAt(9) ;
   }
   return t;
}


function StripDigits(str)
{  
   var s="";
   for (i=0; i<str.length; i++)
   {
      if (!isNaN(str.charAt(i)) && (str.charAt(i) != " ")) { s = s + str.charAt(i); }
   }   
   return s ;
}


function LogIn()
{
  if (!CheckEmail(document.form_input.login_email.value))
  {document.form_input.login_email.focus(); return false; }


  if (document.form_input.login_password1.value == "")
  {
    alert("Please enter a Password");
    document.form_input.login_password1.focus();
    return (false);
  }

  if (document.form_input.login_password1.value.length < 6)
  {
    alert("Please enter at least 6 characters in the Password field.");
    document.form_input.login_password1.focus();
    return (false);
  }

  document.form_input.login.value=1;
  document.form_input.submit();

}


function SendLostPassword()
{
	document.form_input.lost_psw.value=1; 
	if (CheckEmail(document.form_input.login_email.value)) 
	{ document.form_input.submit();} 
	else {}
}


function SubmitDelete()
{

if (confirm("Are You Sure to Remove This Ad?"))
	{
	return true; 
	}

return false;
}


function CheckEmail(email)
{
  if (email == "")
  {
    alert("Please enter your Email");
    return (false);
  }
  else
  {
  	// Check the syntax
	var e = 0;
	for (i=0; i<email.length; i++) 
		{   if (email.charAt(i)  == '@' ) {  e = 1; }  		}  
	if ((email.length < 5) || !e) 
		{
		    alert("Please enter valid Email");
			return (false);
		}
  }

  return true;

}




function newWin(url,windowname,width,height) 
{
	width=(width)?width:screen.width/3;
	height=(height)?height:screen.height/3;
	var screenX = (screen.width/2 - width/2);
	var screenY = (screen.height/2 - height/2);
	var features= "width=" + width + ",height=" + height;
	features += ",screenX=" + screenX + ",left=" + screenX;
	features += ",screenY=" + screenY  +",top=" + screenY;
    features += ",scrollbars=0,resizable=0,location=0";
    features += ",menubar=0,toolbar=0,status=0";
  	var mywin=window.open(url, windowname, features);
	if (mywin)  
		mywin.focus();

	return mywin;
}