// JavaScript Document

$(document).ready(function(){
	$(".artistBox:last").addClass("lastrec");	
	$(".newsBox:last").addClass("lastrec");		
});



function validate_forgepass()
 {
  
   if(trimA($("#email").val())=="")
	   {
		     $("#login_error").hide();
		  $("#login_error").html("Email should not be empty!");   
		  return error_action('email');
	   }
	  
	  if(!checkEmail($("#email").val()))
	   {
		   
		    $("#login_error").html("Email is invalid!");   
			$("#login_error").fadeIn("fast");
			$("#email").focus(); 
			return false;
	   }	
 }


function validate_login() 
 {
	 if(trimA($("#username").val())=="")
	   {
		  $("#login_error").html("Username should not be empty!");   
		  $("#login_error").fadeIn("fast");
		  $("#username").val("");
		   $("#username").focus();
		   return false;
	   }
	   if(trimA($("#password").val())=="")
	   {
		  $("#login_error").html("Password should not be empty!");   
		  $("#login_error").fadeIn("fast");
		  $("#password").val("");
		  $("#password").focus();
		   return false;
	   }
 }

function error_action(elem) 
 {
  $("#login_error").hide();
	$("#login_error").fadeIn("fast");
	$("#"+elem).val("");
	$("#"+elem).focus(); 
	return false;
 }
function validate_register()
  {
	
	if(trimA($("#firstname").val())=="")
	   {
		  $("#login_error").html("Firstname should not be empty!");   
		    return error_action('firstname');
      }
	   if(trimA($("#lastname").val())=="")
	   {
		  $("#login_error").html("Lastname should not be empty!");   
		  return error_action('lastname');
	   }
	   
	    if($("#device_id").val()=="")
	   {
		  $("#login_error").html("Please select a device!");   
		  $("#device_id").focus();
		  return false;
	   }
	   
	   if(trimA($("#email").val())=="")
	   {
		  $("#login_error").html("Email should not be empty!");   
		  return error_action('email');
	   }
	  
	  if(!checkEmail($("#email").val()))
	   {
		    $("#login_error").html("Email is invalid!");   
			$("#login_error").fadeIn("fast");
			$("#email").focus(); 
			return false;
	   }
	   
	   if(trimA($("#username").val())=="")
	   {
		  $("#login_error").html("Username should not be empty!");   
		   return error_action('username');
	   }
	   
	   if(trimA($("#password").val())=="")
	   {
		  $("#login_error").html("Password should not be empty!");   
		   return error_action('password');
	   } 
	 
	 if(trimA($("#cpassword").val())=="" || $("#cpassword").val()!=$("#password").val())
	   {
		  $("#login_error").html("Passwords do not match!");   
		   return error_action('cpassword');
	   } 
	   
  }
  
  function validate_reseller()
  {
	
	if(trimA($("#name").val())=="")
	   {
		  $("#login_error").html("Name should not be empty!");   
		    return error_action('name');
      }
	 
	   if(trimA($("#email").val())=="")
	   {
		  $("#login_error").html("Email should not be empty!");   
		  return error_action('email');
	   }
	  
	  if(!checkEmail($("#email").val()))
	   {
		    $("#login_error").html("Email is invalid!");   
			$("#login_error").fadeIn("fast");
			$("#email").focus(); 
			return false;
	   }
	   
	   if(trimA($("#phone").val())=="")
	   {
		  $("#login_error").html("Phone should not be empty!");   
		   return error_action('phone');
	   }
	 	   
  }
  
  
  function change_device(val)
    {
		if(val=="")
		return;
		
		var v=val.split("||");
		 $("#skin_installation").attr("href","device-"+v[0]+"-"+v[1]+"-skin-installation.html");
		  $("#wallpaper_installtion").attr("href","device-"+v[0]+"-"+v[1]+"-wallpaper-installation.html");
	}
  

function change_category(url,basepath)
  {
	   if(url=="")
	   return;
	  window.location.href=basepath+url;
  }
	
function openwindow(name,url,width,height)
{
		
var win=window.open(url,name,"width="+width+",height="+height+",scrollbars=yes,resizeable");
win.moveTo(100,100);
win.focus();
}

function checkExtensionImage (id)  {
	var VideoArray = new Array("jpg", "png", "gif", "JPG", "PNG", "GIF");
	_filename = document.getElementById(id);
	isValid = true;
	
	_f = trimA(_filename.value);
	if(_f.length==0) {
	   return false; 
	}
	_file = _f.split(".");

	_ext = _file[_file.length - 1];
	var re = new RegExp(_ext, "gi");

	var arrAsString = array2String(VideoArray);
	var result = arrAsString.match(re);
	if(!result)  {
		  isValid =false;
	} 

   return isValid;
}

function empty_postcode()
 {
	 if(trimA($("#postcode").val())=="POSTCODE") 
	  $("#postcode").val("");
	  
	  $("#postcode").blur(function(){
		if(trimA($("#postcode").val())=="")
	    $("#postcode").val("POSTCODE")
          });
	   
 }

function trimA(sString)
{
	if(sString && sString.length > 0)
	{
		while (sString.substring(0,1) == ' ')
		{
			sString = sString.substring(1, sString.length);
		}
		while (sString.substring(sString.length-1, sString.length) == ' ')
		{
			sString = sString.substring(0,sString.length-1);
		}
	}
	return sString;
}
function checkEmail(inputvalue){	
    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if(pattern.test(inputvalue)){         
		return true; 
    }else{   
		return false;
    }
}
  
 function checkNumeric(str) {
	 var pattern=/^ *[0-9]+ *$/;
        return pattern.test(str);
      }

  function checkFloat(str) {
    str = trim(str);
    return /^[-+]?[0-9]+(\.[0-9]+)?$/.test(str);
}


