// JavaScript Document
//Free Car Trader (C)2010
//RAZOR WEB DESIGN

//****LOAD BRANDS
function loadBrands(curpage) {
	$.get(curpage + "includes/javaphp/showAllBrands", function(data) {
		var brandData = data;
		$("#brandBox").slideUp(500, function() {
			$("#brandBox").html(data);
			$("#brandBox").slideDown(1000);
		});
	});
}

//****FORM VALIDATE: contactus

function form_valid_contactus() {
	
	var validate_text = "Please enter...";
	
	//Check Empty
	if(document.contactus.name.value=="") {
		document.contactus.name.value = validate_text;
		return false;
	}
	if(document.contactus.email.value=="") {
		document.contactus.email.value = validate_text;
		return false;
	}
	if(document.contactus.message.value=="") {
		document.contactus.message.value = validate_text;
		return false;
	}
	
	//Check TO
	var email1 = isValidEmail(document.contactus.email.value);
	
	if(email1 == true) {
		//do nothing
	} else {
		alert("Invalid email address '" + document.contactus.email.value + "'!");
		return false;
	}
}

//****FORM VALIDATE: signin

function form_valid_signin() {
	
	var validate_text = "Please enter...";
	
	//Check Empty
	if(document.signin.username.value=="") {
		document.signin.username.value = validate_text;
		return false;
	}
	if(document.signin.password.value=="") {
		alert("Please enter your password!");
		return false;
	}
}

//****FORM VALIDATE: GetPass

function form_valid_getpass() {
	
	//Check TO
	var email1 = isValidEmail(document.getpass.email.value);
	
	if(email1 == true) {
		//do nothing
	} else {
		alert("Invalid email address '" + document.getpass.email.value + "'!");
		return false;
	}
}

//****Show Enter Btn
$(document).ready(function() {
	$('#Keyword').keyup(function(e) {
	//alert(e.keyCode);
	if(e.keyCode == 13) {
		$("#searchForm").submit();
	}
	});
	$('#Keyword').focus(function() {
		$("#searchtoggle").fadeIn(500);
	});
	$('#Keyword').blur(function() {
		$("#searchtoggle").fadeOut(500);
	});
});

//****SHOW ALL BRANDS
function smartTitle(aid) {
  var xmlhttp;
  if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
		
		xmlhttp.onreadystatechange=function()
        {
              if(xmlhttp.readyState == 3)
              {
				  document.getElementById("smartBox").innerHTML = "Processing...";
              }
			  if(xmlhttp.readyState == 4)
              {
				  var split_var = xmlhttp.responseText.split("&");
				  document.step3.title.value = split_var[1];
				  document.getElementById("smartBox").innerHTML = split_var[0];
              }
        }
   var url = "../includes/javaphp/listSmartTitle?AuctionID=" + aid;
   xmlhttp.open("GET",url,false);
   xmlhttp.send(null);
}

//****CHECK UNAME AVAILABLE
function checkUname(uname) {
  if(uname == null || uname == "" || uname == " ") {
	  document.getElementById("unameBox").innerHTML = "";
	  return false;
  }

  var xmlhttp;
  if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
		
		xmlhttp.onreadystatechange=function()
        {
              if(xmlhttp.readyState == 4)
              {
				  document.getElementById("unameBox").innerHTML = xmlhttp.responseText;
              }
        }
   var url = "../includes/javaphp/unameCheck?Name=" + uname;
   xmlhttp.open("GET",url,false);
   xmlhttp.send(null);
}


//****CHECK EMAIL @ SIGN
function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

//****OPEN POP UP
function openPopup(url_loc,pop_id) {
	window.open('' + url_loc,'PopUp','width=500,height=500,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no')
}

//****CHANGE EXPAND / SHRINK ICON
function changeIcon(ele,chknum) {
	if(document.getElementById(ele).title == "Expand Sidebox") {
		document.getElementById(ele).src = "../images/sidebox_shrink.gif";
		document.getElementById(ele).title = "Shrink Sidebox";
	} else {
		document.getElementById(ele).src = "../images/sidebox_expand.gif";
		document.getElementById(ele).title = "Expand Sidebox";
	}
}
