$(document).ready(function() {
 $('h1').corner("tr bl");
 $('h2').corner("tr tl");
 $('.menu a').corner("tr 15px");
});

function submitMini() {
 zip = document.qtfrm.zipcode.value;
 
 if (zip=='') {
  alert('Enter Zipcode');
  return;
 }
 
 if (document.qtfrm.moveto.value=='') {
  alert('Enter Moving To State');
  return;
 }

 document.qtfrm.To_State.selectedIndex = document.qtfrm.moveto.selectedIndex + 1;

 $('#movingSize').html(document.qtfrm.Move_Size.options[document.qtfrm.Move_Size.selectedIndex].value);
 $('#movingFrom').html(zip);
 document.qtfrm.From_Zip.value = zip;

 
 $('#almostDoneContent').css("top", document.compatMode=="CSS1Compat" ? document.documentElement.scrolltop+10+"px" : document.body.scrollTop+10+"px");
 $('#almostDone').height($(document).height());
 $('#almostDone').fadeIn();
}

function contactusOK() {
 if (document.contactus.name.value == '') {
  alert('Bad name');
  return false;
 }
 if (document.contactus.phone.value == '') {
  alert('Bad phone');
  return false;
 }
 if (!echeck(document.contactus.email.value))
  return false;
 if (document.contactus.comment.value == '') {
  alert('Please write your comment');
  return false;
 }
 return true;
}

function freeQuotesOK() {
 if (document.qtfrm.name.value == '') {
  alert('Bad name');
  return false;
 }
 if (document.qtfrm.Last_Name.value == '') {
  alert('Bad last name');
  return false;
 }
 if (document.qtfrm.phone.value == '') {
  alert('Bad phone');
  return false;
 }
 if (document.qtfrm.Contact_Preference.value == '') {
  alert('Bad Contact Preference');
  return false;
 }
 if (document.qtfrm.Contact_Time.value == '') {
  alert('Bad Contact Time');
  return false;
 }
 if (document.qtfrm.From_City.value == '') {
  alert('Bad field - from city');
  return false;
 }
 if (document.qtfrm.From_State.value == '') {
  alert('Bad field - from state');
  return false;
 }
 if (document.qtfrm.To_State.value == '') {
  alert('Bad field - to state');
  return false;
 }
 if (document.qtfrm.From_Zip.value == '') {
  alert('Bad field - from zip');
  return false;
 }
 if (document.qtfrm.To_Zip.value == '') {
  alert('Bad field - to zip');
  return false;
 }
 if (document.qtfrm.Move_Size.value == '') {
  alert('Bad move size');
  return false;
 }
 if (!echeck(document.qtfrm.email.value))
  return false;
 /*if (document.qtfrm.comment.value == '') {
  alert('Please write your comment');
  return false;
 }*/
 return true;
}

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")
		   return false
		}

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

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

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

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

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

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

 		 return true
	}


function FindObject(id, doc)
{
   var child, elem;
   if(!doc)
      doc=document;
   if(doc.getElementById)
      elem=doc.getElementById(id);
   else
   if(doc.layers)
      child=doc.layers;
   else
   if(doc.all)
      elem=doc.all[id];
   if(elem)
      return elem;
   if(doc.id==id || doc.name==id)
      return doc;
   if(doc.childNodes)
      child=doc.childNodes;
   if(child)
   {
      for(var i=0; i<child.length; i++)
      {
         elem=FindObject(id,child[i]);
         if(elem)
            return elem;
      }
   }
   var frm=doc.forms;
   if(frm)
   {
      for(var i=0; i<frm.length; i++)
      {
         var elems=frm[i].elements;
         for(var j=0; j<elems.length; j++)
         {
            elem=FindObject(id,elems[i]);
            if(elem) return elem;
         }
      }
   }
   return null;
}

function ShowObject(id, flag)
{
   var elem=FindObject(id);
   if(elem)
      elem.style.visibility=flag?'visible':'hidden';
}

function check(on) {
 switch (on) {
  case "on":
   $('input[type=checkbox]').attr("checked","checked");
   break;
  case "off":
   $('input[type=checkbox]').attr("checked","");
 }
}
