$(function() {
					// Use this example, or...
					$('a[@rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel
					// This, or...
					//$('#gallery a').lightBox(); // Select all links in object with gallery ID
					// This, or...
				//	$('a.lightbox').lightBox(); // Select all links with lightbox class
					// This, or...
					//$('a').lightBox(); // Select all links in the page
					// ... The possibility are many. Use your creative or choose one in the examples above
		//	    $("div.slogan").corner("round");
		//	    $("div.blueItems").corner("round");
		//	    $("div.greenItems").corner("round");
		//	    $("div.orangeItems").corner("round");
			  //	$('#rate1').rating('www.url.php', {maxvalue:5});
			 
			    
			 //   $('div.greyItems').shadow({ color: "#444", offset: 5, opacity: 0.2 });
			//    $('div.greyItems').corner("round");
			    
			
		
});
			

 function headline_rotate() {
   current_headline = (old_headline + 1) % headline_count; 
   $("div.headline:eq(" + old_headline + ")").animate({top: -205},"slow", function() {
     $(this).css('top','210px');
   });
   $("div.headline:eq(" + current_headline + ")").show().animate({top: 5},"slow");  
   old_headline = current_headline;
 }


function chkPrice(form) {
  var res= confirm('This change will increase the listing fee payable. Do you wish to continue?');
  if(res) {
    return true;
  } else {
    window.location= "http://schoolxchange.thepagesmith.com/sell/";
  }
}
			
			
function validateForm(form) {
  var mainCat = $("#mainCat").val();
  var name = $("#form_name").val(); 
  var price =$("#form_saleprice").val(); 
  var condition =$("#from_conditionid").val();
  var schoolID =$("#hiddenscID").val();
  var txtmsg="";
   if(mainCat == "") {
      txtmsg = "Please select a main category";
   //  $('#formMainCat'). html("Please select a main category");
    } else {
       /* var subCat =$("#subCat").val();
        if(subCat == "") {
          txtmsg = "Here into subCat";
       */
       
         var selected = $("#subCat option:selected");  
         txtmsg ="";     
         if(selected.val() == 0){  
               txtmsg = "Here into subCat";
          } else {
              if(mainCat == 1) {  
              var subCatL1 = $("#subCatL1 option:selected");
              txtmsg ="";
              if(subCatL1.val() == 0) {
                  txtmsg = "Please select a relevant SubcategoryL1";
                } 
           }
        }  
    }
    if(txtmsg.length > 0 ) {
      $("#formCatError").html("Please select a category"); 
      $("#formGenError") .html("Errors have occured please revalidate the missing fields");
      window.location= "#top";
      return false;
      
    }else if (name== "" || name.indexOf("/")!= -1 || name.indexOf("\\")!= -1 || name.indexOf("'")!= -1){  
      $('#formError').html("This field cannot have special characters like \,//,' etc");
      return false;
    }else if(price== ""){
      $('#formErrorPrice').html("Please select a valid price!");
      return false;
    }else if(condition == "") {
      $('#formStarError').html("Please select an Item condition");
      return false;
    }else if(schoolID == "" && mainCat== 1) {
    	$('#formSchoolError').html("Please select school or Select Any school for generic Items");
    	return false;
    } 
    else {
      return true;
    }
}			
			

function lookup(inputString) {
 // alert("dfgldjfgkd");
		if(inputString.length == 0) {
			// Hide the suggestion box.
							$('#suggestions').hide();
		} else {
			$.post("/store/rpc.php", {queryString: ""+inputString+""}, function(data){
				if(data.length >0) {
					$('#suggestions').show();
					$('#autoSuggestionsList').html(data);
				}
			});
		}
	} // lookup
	
	function fill(thisValue,hiddenID) {
					$('#inputString').val(thisValue);
					$('#hiddenscID').val(hiddenID);
					setTimeout("$('#suggestions').hide();", 200);
	}
	
	 // lookup
	 
/*------------------------------------------------*/	 
	function slookup(inputStringS) {
		if(inputStringS.length == 0) {
			// Hide the suggestion box.
							$('#suggestionsS').hide();
		} else {
			$.post("/store/spc.php", {queryStringS: ""+inputStringS+""}, function(data){
				if(data.length >0) {
					$('#suggestionsS').show();
					$('#autoSuggestionsListS').html(data);
				}
			});
		}
	} // lookup
	
	function sfill(thisValue,hiddenValue) {
					$('#inputStringS').val(thisValue);
					$('#hiddenS').val(hiddenValue);
					setTimeout("$('#suggestionsS').hide();", 200);
	}
	
/*----------------------------------------------------------------------------------*/		
	function droplookup(inputStringS, onpage) {
		if(inputStringS.length == 0) {
			// Hide the suggestion box.
			$('#newBox').hide();
			$('#newBox2').hide();
		} else {
		  if(onpage) {
		    var spage = "spc.php?onpage=1";
		  } else {
		    var spage = "spc.php"; 
		  }
		  
		  
			$.post("/store/spc.php", {queryStringS: ""+inputStringS+""}, function(data){
				if(data.length >0) {
				  if(onpage) {
					$('#newBox2').show();
					$('#autoSuggestionsListS2').html(data);
				} else {
					$('#newBox').show();
					$('#autoSuggestionsListS').html(data);
				}
				}
			});
		}
	} // lookup
	
function dropfill(thisValue,hiddenValue) {
 // alert(thisValue);
 // alert(hiddenValue);
  $('#inputStringS').val(thisValue);
	$('#hiddenS').val(hiddenValue);
	setTimeout("$('#newBox').hide();", 200);

}
	
	/*----------------------------------------------------------------------------------*/	

/*------------------------------------------------*/	

	function svlookup(inputStringSv) {
		if(inputStringSv.length == 0) {
			// Hide the suggestion box.
			$('#suggestionsSv').hide();
		} else {
			$.post("/store/sspc.php", {queryStringS: ""+inputStringSv+""}, function(data){
				if(data.length >0) {
					$('#suggestionsSv').show();
					$('#autoSuggestionsListSv').html(data);
				}
			});
		}
	} // lookup

	
	function sfillv(thisValue,hiddenValue) {
 // alert(thisValue);
 // alert(hiddenValue);
					$('#inputStringSv').val(thisValue);
					$('#hiddenSV').val(hiddenValue);
					setTimeout("$('#suggestionsSv').hide();", 200);
	}
	
/*----------------------------------------------------------------------------------*/	
	
	function sublookup(form_suburb) {
		if(form_suburb.length == 0) {
			// Hide the suggestion box.
							$('#suburbBox').hide();
		} else {
			$.post("/login/sub.php", {querySub: ""+form_suburb+""}, function(data){
				if(data.length >0) {
					$('#suburbList').show();
					$('#autoSuburbList').html(data);
				}
			});
		}
	} // lookup
	
	function subfill(thisValue) {
					$('#form_suburb').val(thisValue);
					setTimeout("$('#suburbList').hide();", 200);
	}
	
	function reload(form){
				var val=form.country.options[form.country.options.selectedIndex].value;
				self.location='/sell/index.php?mainCatID=' + val ;
			}
	
	
	function getXMLHTTP() { //fuction to return the xml http object
		var xmlhttp=false;	
		try{
			xmlhttp=new XMLHttpRequest();
		}
		catch(e)	{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}
		 	
		return xmlhttp;
	}
	
	
	function changeDropbox(form) {
		var val=form.mainCat.options[form.mainCat.options.selectedIndex].value;
		var strURL='/ajaxupload/categories.php?catID='+val;
		this.displayForm(val);
		//alert(strUrl);
	  var req = getXMLHTTP(); // fuction to get xmlhttp object
    if (req) {
      req.onreadystatechange = function() {
        if (req.readyState == 4) { //data is retrieved from server
          if (req.status == 200) { // which reprents ok status                    
            document.getElementById('subCat').innerHTML=req.responseText;     
          
          } else { 
            alert("There was a problem while using XMLHTTP:\n");
          }
        }            
      }        
      req.open("GET", strURL, true); //open url using get method
      req.send(null);
    }
    if(form.subCat) { 
    	this.changeDropbox2(form);
    	
    }
    
  }
  
  function clearBox(name,value) {
    textField = document.getElementById(name);
    if(value == textField.value) {
      textField.value = ""; 
    }
  }
	
	function validate(form) {
	 // var catID=form.mainCat.options[form.mainCat.options.selectedIndex].value;
   // textField = document.getElementById(name);
    var validateURL='/ajaxupload/validate.php?postData='+val;
		  if(textField.value== "") strURL +='&subCatID='+val1;
	    var req3 = getXMLHTTP(); // fuction to get xmlhttp object
      if (req3) {
        req3.onreadystatechange = function() {
        if (req3.readyState == 4) { //data is retrieved from server
          if (req3.status == 200) { // which reprents ok status                    
            errorTxt=req1.responseText;
            
          } else { 
            alert("There was a problem while using XMLHTTP:\n");
          }
        }            
      }        
        req3.open("GET", validateURL, true); //open url using get method
        req3.send(null);
      }      
   
  }
	
	
	
	function changeDropbox2(form) {
		var val=form.mainCat.options[form.mainCat.options.selectedIndex].value;
		var val1=form.subCat.options[form.subCat.options.selectedIndex].value;
		var strURL='/ajaxupload/subCategories.php?catID='+val;
		if(val1) strURL +='&subCatID='+val1;
		//alert(strUrl);
	  var req1 = getXMLHTTP(); // fuction to get xmlhttp object
    if (req1) {
      req1.onreadystatechange = function() {
        if (req1.readyState == 4) { //data is retrieved from server
          if (req1.status == 200) { // which reprents ok status                    
          document.getElementById('subCatL1').innerHTML=req1.responseText;
          } else { 
            alert("There was a problem while using XMLHTTP:\n");
          }
        }            
      }        
      req1.open("GET", strURL, true); //open url using get method
      req1.send(null);
    }
   
  }
	
	function changeState(form) {
		var val3=form.states.options[form.states.options.selectedIndex].value;
		var strURL3='/ajaxupload/states.php?stateID='+val3;
		//alert(strUrl);
	  var req2 = getXMLHTTP(); // fuction to get xmlhttp object
    if (req2) {
      req2.onreadystatechange = function() {
        if (req2.readyState == 4) { //data is retrieved from server
          if (req2.status == 200) { // which reprents ok status                    
          
          } else { 
            alert("There was a problem while using XMLHTTP:\n");
          }
        }            
      }        
      req2.open("GET", strURL3, true); //open url using get method
      req2.send(null);
    }
   
  }
	
	
	
	
	
	function displayForm(formcatID) {
		var frm_strURL='/ajaxupload/displayForm.php?catID='+formcatID;
		var req2 = getXMLHTTP(); // fuction to get xmlhttp object
    if (req2) {
      req2.onreadystatechange = function() {
        if (req2.readyState == 4) { //data is retrieved from server
          if (req2.status == 200) { // which reprents ok status                    
              document.getElementById('addForm').innerHTML=req2.responseText;     
     					//this.displayStars();      	
          } else { 
            alert("There was a problem while using XMLHTTP:\n");
          }
        }            
      }        
      req2.open("GET", frm_strURL, true); //open url using get method
      req2.send(null);
    }
			
	}
	
	function showSortForm(formcatID) {
		var sort_strURL='/ajaxupload/displaySortForm.php';
		var req3 = getXMLHTTP(); // fuction to get xmlhttp object
    if (req3) {
      req3.onreadystatechange = function() {
        if (req3.readyState == 4) { //data is retrieved from server
          if (req3.status == 200) { // which reprents ok status                    
              document.getElementById('sortForm').innerHTML=req3.responseText;     
     					//this.displayStars();      	
          } else { 
            alert("There was a problem while using XMLHTTP:\n");
          }
        }            
      }        
      req3.open("GET", sort_strURL, true); //open url using get method
      req3.send(null);
    }
			
	}
	
	
	function countChars(form) {
	  alert("dfgdf;lgdfl;kg");
	  var len = $('#form_snippet').value.length;
    alert(len);
    if (len >= 350) {
        $('#form_snippet').value = $('#form_snippet').value.substring(0, 350);
     }
     $('#charLeft').text(350 - len);
      //      }); 
	}