/**
 *  --------------------------------------------------------------------------------------
 *  Navigator Scripts
 *  ----------------------------------------------------
 *  Modified	April 16, 2009
 *  @author	Bree Emmerson <bree@navigatormm.com>
 *  ----------------------------------------------------
 *
 *  --------------------------------------------------------------------------------------
 */
 
/* HOME PAGE ANIMATION
--------------------------------------------------------------------------------------- */
$(function() {

$('#homeFade').cycle({ 
    fx:    'fade', 
    speed:  2500 
 });
});

$(function()
 {	
	var _height=$('.contentArea').innerHeight();
	$('.leftCol').css('height',_height);
	$('.rightCol').css('height',_height);
 });


function ReSizeSideBars(){
   new_height=$('.contentArea').innerHeight();
   $('.leftCol').css('height',new_height);
   $('.rightCol').css('height',new_height);
}


$(function() {
  $('a[rel*="gallery"]').lightBox({
  	overlayBgColor: '#000000',
	overlayOpacity: 0.8,
	imageLoading: 'http://www.prairiesedge.ca/images/lightbox/lightbox-ico-loading.gif',
	imageBtnClose: 'http://www.prairiesedge.ca/images/lightbox/lightbox-btn-close.gif',
	imageBtnPrev: 'http://www.prairiesedge.ca/images/lightbox/lightbox-btn-prev.gif',
	imageBtnNext: 'http://www.prairiesedge.ca/images/lightbox/lightbox-btn-next.gif',
	imageBlank: 'http://www.prairiesedge.ca/images/lightbox/lightbox-blank.gif',
	containerResizeSpeed: 400,
	txtImage: 'Photo',
	txtOf: 'of',
	keyToClose: 'c',
	keyToPrev: 'p',
	keyToNext: 'n'
   });
});

function enlargeImage(id,img){
	var inhtml='<a href="admin/FTP/inventory_images/'+id+'/orgi_'+img+'" rel="gallery"><img src="admin/FTP/inventory_images/'+id+'/larg_'+img+'" width="337" height="224" alt="" border="0" class="imgBorder" /></a>';
	$('#enlargedImage').html(inhtml);
	$(function() {
  $('a[rel*="gallery"]').lightBox({
  	overlayBgColor: '#000000',
	overlayOpacity: 0.8,
	imageLoading: 'http://www.prairiesedge.ca/images/lightbox/lightbox-ico-loading.gif',
	imageBtnClose: 'http://www.prairiesedge.ca/images/lightbox/lightbox-btn-close.gif',
	imageBtnPrev: 'http://www.prairiesedge.ca/images/lightbox/lightbox-btn-prev.gif',
	imageBtnNext: 'http://www.prairiesedge.ca/images/lightbox/lightbox-btn-next.gif',
	imageBlank: 'http://www.prairiesedge.ca/images/lightbox/lightbox-blank.gif',
	containerResizeSpeed: 400,
	txtImage: 'Photo',
	txtOf: 'of',
	keyToClose: 'c',
	keyToPrev: 'p',
	keyToNext: 'n'
   });
});
}




$(document).ready(function () {
	$('.basic2').click(function (e) {
		e.preventDefault();
		$('#basicModalContent2').modal();
	});
});

function IsNumeric(NumberToTest) 
{
 return /^-?\d+$/.test(NumberToTest);
}

function IsDecimal(strString)   
{
 var strValidChars = "0123456789.";
 var strChar;
 var blnResult = true;
 if (strString.length == 0) return false;
 for (i = 0; i < strString.length && blnResult == true; i++)
 {
  strChar = strString.charAt(i);
  if (strValidChars.indexOf(strChar) == -1)
   {
    blnResult = false;
   }
 }
 return blnResult;
}

function isValidEmailAddress(emailAddress) {   
var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);   
return pattern.test(emailAddress);   
} 


function validateSignUp(){
       
  if($('#email_address').val().replace(/^\s+|\s+$/g, '') == "")
    {
      alert("Please enter the Email");
      $('#email_address').focus();
      return false;
    }
 
  if($('#email_address').val().replace(/^\s+|\s+$/g, '') != "" && !isValidEmailAddress($('#email_address').val()))
    {
      alert("Please enter the correct Email");
      $('#email_address').focus();
      return false;
    }

  
  if($('#create_password').val().replace(/^\s+|\s+$/g, '') == "")
    {
      alert("Please enter the Password");
      $('#create_password').focus();
      return false;
    }
    
  if($('#create_password').val().replace(/^\s+|\s+$/g, '') != "" && $('#create_password').val().replace(/^\s+|\s+$/g, '').length<6)
    {
      alert("Please enter minimum 6 letters for the Password");
      $('#create_password').focus();
      return false;
    }
  if($('#password_check').val().replace(/^\s+|\s+$/g, '') == "")
    {
      alert("Please enter the Retype Password");
      $('#password_check').focus();
      return false;
    }
  if($('#create_password').val().replace(/^\s+|\s+$/g, '') != $('#password_check').val() && $('#create_password').val() != "")
  {
      alert("The Create Password and the Retype Password don't match");
      $('#password_check').focus();
      return false;
  }
  if($('#first_name').val().replace(/^\s+|\s+$/g, '') == "")
    {
      alert("Please enter the First Name");
      $('#first_name').focus();
      return false;
    }
  if($('#last_name').val().replace(/^\s+|\s+$/g, '') == "")
    {
      alert("Please enter the Last Name");
      $('#last_name').focus();
      return false;
    }
  
  if($('#country').val().replace(/^\s+|\s+$/g, '') == "")
    {
      alert("Please enter the Country");
      $('#country').focus();
      return false;
    }
  
  if($('#phone_number').val().replace(/^\s+|\s+$/g, '') == "")
    {
      alert("Please enter the Phone Number");
      $('#phone_number').focus();
      return false;
    }
  
  
  return true;  
}

function validateSendToFriend(c,sc,inv){
      if($('#your_name').val().replace(/^\s+|\s+$/g, '') == "")
       {
         alert("Please enter your Name");
         $('#your_name').focus();
        
       }
       else if($('#your_email').val().replace(/^\s+|\s+$/g, '') == "")
       {
         alert("Please enter your Email");
         $('#your_email').focus();
         
       }
    
      else if($('#your_email').val().replace(/^\s+|\s+$/g, '') != "" && !isValidEmailAddress($('#your_email').val()))
       {
         alert("Please enter your correct Email");
         $('#your_email').focus();
        
       }
       else if($('#friends_name').val().replace(/^\s+|\s+$/g, '') == "")
       {
         alert("Please enter your Friend's Name");
         $('#friends_name').focus();
         
       }
       else if($('#friends_email').val().replace(/^\s+|\s+$/g, '') == "")
       {
         alert("Please enter friend's Email");
         $('#friends_email').focus();
         
       }
    
      else if($('#friends_email').val().replace(/^\s+|\s+$/g, '') != "" && !isValidEmailAddress($('#friends_email').val()))
       {
         alert("Please enter friend's correct Email");
         $('#friends_email').focus();
         
       }
       else if($('#comments').val().replace(/^\s+|\s+$/g, '') == "")
       {
         alert("Please enter your comments");
         $('#comments').focus();
         
       }
       else {
              $.post(
		'send-to-friend.php',
		{captch:$('#security').val(),
                your_name:$('#your_name').val(),
                your_email:$('#your_email').val(),
                friends_name:$('#friends_name').val(),
                friends_email:$('#friends_email').val(),
                comments:$('#comments').val(),
                c:c,
                sc:sc,
                inv:inv
                }
		,function(result){
			if(result == 0){
                        alert('Please enter correct image code');
                        }
                        else {
                        //document.forms[4].submit();
                        alert('Product send to your friend successfully');
                        location.reload();
                        
                        }
                        
                       
	});
       }
}

function validateShipping(){
      
     if($('#first_name').val().replace(/^\s+|\s+$/g, '') == "")
       {
         alert("Please enter the First Name");
         $('#first_name').focus();
         return false;
       }
     if($('#last_name').val().replace(/^\s+|\s+$/g, '') == "")
       {
         alert("Please enter the Last Name");
         $('#last_name').focus();
         return false;
       }
     if($('#address').val().replace(/^\s+|\s+$/g, '') == "")
       {
         alert("Please enter the Address");
         $('#address').focus();
         return false;
       }
     if($('#city').val().replace(/^\s+|\s+$/g, '') == "")
       {
         alert("Please enter the City");
         $('#city').focus();
         return false;
       }
     if($('#province_state').val().replace(/^\s+|\s+$/g, '') == "")
       {
         alert("Please enter the Province/State");
         $('#province_state').focus();
         return false;
       }
     if($('#postal_zip_code').val().replace(/^\s+|\s+$/g, '') == "")
       {
         alert("Please enter the Postal Code/ZIP");
         $('#postal_zip_code').focus();
         return false;
       }
     if($('#country').val().replace(/^\s+|\s+$/g, '') == "")
       {
         alert("Please enter the Country");
         $('#country').focus();
         return false;
       }
}

function validateBid(page){
       if($('#bid_amount').val().replace(/^\s+|\s+$/g, '') == "" ){
              alert("Please enter your bid amount");
              $('#bid_amount').focus();
       }
       else if(!IsDecimal($('#bid_amount').val())){
               alert("Please enter correct bid amount");
              $('#bid_amount').focus();
       }
       else if($('#bid_amount').val() < parseFloat($('#next_bid').val())){
               alert("Please place higher bid amount");
              $('#bid_amount').focus();
       }
       else {
              $.post(
		page,
		{amount:$('#bid_amount').val(),
                inventory:$('#inventory').val(),
                opera:'submitbid'}
		,function(result){
			if(result == 0)
                        alert('Product is not available');
                        else if(result == 1){
                        alert('You bid submitted successfully');
                        location.reload();
                        }
                        else if(result == 14){
                        alert('You bid submitted successfully');
                        document.location="index.php";
                        }
                        else
                        alert('Please place higher bid amount');
	});
       }
       
}
function validateForgotPW(){
       if($('#pw_email').val().replace(/^\s+|\s+$/g, '') == "")
       {
         alert("Please enter your Email ");
         $('#pw_email').focus();
         return false;
       }
    
     if($('#pw_email').val().replace(/^\s+|\s+$/g, '') != "" && !isValidEmailAddress($('#pw_email').val()))
       {
         alert("Please enter the correct Email ");
         $('#pw_email').focus();
         return false;
       }
return true;
}

function validateWanted(){
       if($('#wna_title').val().replace(/^\s+|\s+$/g, '') == "")
       {
         alert("Please enter Title ");
         $('#wna_title').focus();
         
       }
    
     else if($('#wna_desc').val().replace(/^\s+|\s+$/g, '') == "")
       {
         alert("Please enter the Description ");
         $('#wna_desc').focus();
         
       }
       else {
            $.post(
		'wanted-items.php',
		{title:$('#wna_title').val(),
                desc:$('#wna_desc').val(),
                cat:$('#wna_cat option:selected').val(),
                submitwanted:'submitwanted'}
		,function(result){
			alert("Your request was submitted successfully");
                        location.reload();
	});  
       }

}

function validatePurchaser(){
       
 
  if($('#first_name').val().replace(/^\s+|\s+$/g, '') == "")
    {
      alert("Please enter the First Name");
      $('#first_name').focus();
      return false;
    }
  if($('#last_name').val().replace(/^\s+|\s+$/g, '') == "")
    {
      alert("Please enter the Last Name");
      $('#last_name').focus();
      return false;
    }
   if($('#email_address').val().replace(/^\s+|\s+$/g, '') == "")
    {
      alert("Please enter the Email");
      $('#email_address').focus();
      return false;
    }
 
  if($('#email_address').val().replace(/^\s+|\s+$/g, '') != "" && !isValidEmailAddress($('#email_address').val()))
    {
      alert("Please enter the correct Email");
      $('#email_address').focus();
      return false;
    }
  if($('#phone_number').val().replace(/^\s+|\s+$/g, '') == "")
    {
      alert("Please enter the Phone no.");
      $('#phone_number').focus();
      return false;
    }
  
  return true;
  
    
}

function unsubscribe(mainpage,referer,c,sc,i){
       
       var unscid=$('#auto_cat').val()
       if(confirm('Do you want to unsubscribe from this category?'))
       {
       document.location=mainpage+'?p='+referer+'&c='+c+'&sc='+sc+'&i='+i+'&usci='+unscid;
       }
       
}

function validateChangePassword(){
       if($('#old_psw').val().replace(/^\s+|\s+$/g, '') == "")
       {
         alert("Please enter Your Password ");
         $('#old_psw').focus();
         
       }
       else if($('#old_psw').val().replace(/^\s+|\s+$/g, '') != "")
       {
          $.post(
		'my-profile.php',
		{oldpsw:$('#old_psw').val(),
                check:'checkoldpsw'}
		,function(result){
                     if(result == '0')
			alert("Enter correct Password");
                     else {
                        if($('#new_psw').val().replace(/^\s+|\s+$/g, '') == "")
                            {
                              alert("Please enter new Password");
                              $('#new_psw').focus();
                              
                            }
                            
                          else if($('#new_psw').val().replace(/^\s+|\s+$/g, '') != "" && $('#new_psw').val().replace(/^\s+|\s+$/g, '').length<6)
                            {
                              alert("Please enter minimum 6 letters for the new Password");
                              $('#create_password').focus();
                              
                            }
                          else if($('#conf_new_psw').val().replace(/^\s+|\s+$/g, '') == "")
                            {
                              alert("Please enter the Retype Password");
                              $('#conf_new_psw').focus();
                              
                            }
                          else if($('#new_psw').val().replace(/^\s+|\s+$/g, '') != $('#conf_new_psw').val() && $('#new_psw').val() != "")
                          {
                              alert("The Create Password and the Retype Password don't match");
                              $('#conf_new_psw').focus();
                             
                          }
                          else {
                             $.post(
                                   'my-profile.php',
                                   {newpsw:$('#new_psw').val(),
                                   check:'changepsw'}
                                   ,function(result){
                                        if(result == '1'){
                                           alert("Your Password changed successfully");
                                           $('#basicModalContent2').hide();
                                            document.location='my-profile.php';
                                        }
                                        else {
                                          alert("There are some problems, please try again");
                                             }
                                   });
                            }
                     }
	});      
       }
     
}

function editProfile(){
       if($('#first_name').val().replace(/^\s+|\s+$/g, '') == "")
       {
         alert("Please enter the First Name");
         $('#first_name').focus();
         return false;
       }
     if($('#last_name').val().replace(/^\s+|\s+$/g, '') == "")
       {
         alert("Please enter the Last Name");
         $('#last_name').focus();
         return false;
       }
     /*if($('#address').val().replace(/^\s+|\s+$/g, '') == "")
       {
         alert("Please enter the Address");
         $('#address').focus();
         return false;
       }
     if($('#city').val().replace(/^\s+|\s+$/g, '') == "")
       {
         alert("Please enter the City");
         $('#city').focus();
         return false;
       }
     if($('#province_state').val().replace(/^\s+|\s+$/g, '') == "")
       {
         alert("Please enter the Province/State");
         $('#province_state').focus();
         return false;
       }
     if($('#postal_zip_code').val().replace(/^\s+|\s+$/g, '') == "")
       {
         alert("Please enter the Postal Code/ZIP");
         $('#postal_zip_code').focus();
         return false;
       }*/
     if($('#country').val().replace(/^\s+|\s+$/g, '') == "")
       {
         alert("Please enter the Country");
         $('#country').focus();
         return false;
       }
     if($('#phone_no').val().replace(/^\s+|\s+$/g, '') == "")
       {
         alert("Please enter the Phone Number");
         $('#phone_no').focus();
         return false;
       }
}
function navWanted(pageno,c){
       document.location="wanted-items.php?p=wanted-items&c="+c+"&pageno="+pageno;
}
function navProduct(page,c,sc){
       var url='products.php?p=products';
       if(c !='')
       url = url + '&c='+c;
       if(sc !='')
       url = url + '&sc='+sc;
       url = url + "&pageno="+page;
       document.location=url;
}
function navAuction(page,c,sc){
       var url='auction_item.php?p=auction_item';
       if(c !='')
       url = url + '&c='+c;
       if(sc !='')
       url = url + '&sc='+sc;
       url = url + "&pageno="+page;
       document.location=url;
}
function navMyitem(page,c,sc){
       var url='my-items.php?p=my-items';
       if(c !='')
       url = url + '&c='+c;
       if(sc !='')
       url = url + '&sc='+sc;
       url = url + "&pageno="+page;
       document.location=url;
}
function navSearch(page){
       var url='search-results.php?p=products';
       var searchstr=$('#search_area').val();
       url = url + '&search_area='+searchstr;
       url = url + "&pageno="+page;
       document.location=url;
}
function validateContactUs(){
       if($('#name').val().replace(/^\s+|\s+$/g, '') == "" ){
              alert('Please enter Contact Name');
              return false;
       }
       if($('#city').val().replace(/^\s+|\s+$/g, '') == "" ){
              alert('Please enter City');
              return false;
       }
       if($('#province option:selected').val().replace(/^\s+|\s+$/g, '') == "" ){
              alert('Please enter Province');
              return false;
       }
       if($('#postal').val().replace(/^\s+|\s+$/g, '') == "" ){
              alert('Please enter Postal Code');
              return false;
       }
       if($('#country option:selected').val().replace(/^\s+|\s+$/g, '') == "" ){
              alert('Please enter Country');
              return false;
       }
       if($('#email_address').val().replace(/^\s+|\s+$/g, '') == "" ){
              alert('Please enter Email');
              return false;
       }
       if($('#email_address').val().replace(/^\s+|\s+$/g, '') != "" && !isValidEmailAddress($('#email_address').val()))
       {
              alert("Please enter the correct Email");
              return false;
       }
       if($('#phone').val().replace(/^\s+|\s+$/g, '') == "" ){
              alert('Please enter Phone');
              return false;
       }
       if($('#security').val().replace(/^\s+|\s+$/g, '') == "" ){
              alert('Please enter Security Code');
              return false;
       }
       
       return true;
}