function isInt(x) {
   var y=parseInt(x);
   if (isNaN(y)) return false;
   return x==y && x.toString()==y.toString();
 } 

function submitIt(target,formID,indicator)
{
new Ajax.Updater(target, 'http://www.stylastic.com/fashion', {onComplete:function(request, json){Element.hide(indicator)}, onLoading:function(request, json){Element.show(indicator),Element.hide(formdID)},parameters:Form.serialize(formID),method:'post',asynchronous:true}); 
return false;
}
function rateit(target,rating,formID,indicator)
{

$('rating').value = rating;
var myform = $(formID);
//myform.return.value = myform.return.value+'/'+rating;
newReturn = Form.getInputs(myform, 'hidden','return')[0];
newReturn.value += '/'+rating;
new Ajax.Updater(target, 'http://www.stylastic.com/fashion', {onComplete:function(request, json){Element.hide(indicator)}, onLoading:function(request, json){Element.show(indicator),Element.hide(formdID)},parameters:Form.serialize(formID),method:'post',asynchronous:true}); 
return false;
}

function rateItSubmit(rating,formID,indicator)
{
$('rating').value = rating;
var myform = $(formID);
newReturn = Form.getInputs(myform, 'hidden','return')[0];
newReturn.value += '/'+rating;
Element.show(indicator);
$(formID).submit();
Form.disable(formID);
return false;
}

function addautocomplete(indicator)
{
new Autocompleter.Local('title', 'autocomplete_choices', ['aloha shirt','another hat','argyle socks','army fatigues','backpack','bag','baseball cap','baseball hat','belt','belt buckle','bikini','bikini bottoms','bikini top','blazer','boots','boxers','bracelet','button down shirt','canvas bag','canvas sneakers','cap','cardigan','cargo pants','chemise','chic','chucks','coat','cowboy boots','crocs','cropped pants','cut-offs','dress','dress shirt','earrings','flannel','fur coat','gators','glasses','glove','halter top','handbag','hat','head scarf','headband','hightops','hoddie','hoodie','hoop earrings','iphone','ipod','jacket','jeans','jumper','jumper dress','knee-highs','leather jacket','leggings','legwarmers','long wrap sweater','messenger bag','mini skirt','necklace','nurse hat','pajama bottoms','pants','plaid shirt','puma shoes','pumps','purse','sandals','sarong','scarf','shirt','shoes','shorts','shoulder bag','skirt','slacks','slippers','sneakers','snorkel','socks','sport coat','sports jacket','stockings','strapless top','suit','sunglasses','sunglassses','suspenders','sweater','sweater dress','sweatpants','swim suit','t-shirt','tank top','thong','tie','tights','toque','trainers','tunic','turtleneck','vest','wallet chain','wool hat',], {minChars: 1, indicator: indicator});
}
function autoStyles(ID,choices,indicator)
{
new Autocompleter.Local(ID, choices, ['50s','60s','70s','80s','90s','anime','bohemian','boho','chic','classic','classy','comfortable','disco','diy','dominatrix','dressy','eclectic','eco','emo','ethereal','evening','formal','fun','funky','glam','goth','grunge','haute','hippie','indie','lingerie','mod','neon','preppy','professional','punk','raver','retro','rock','rockabilly','sophisticated','street','thrift','trendy','tribal','uniform','urban','vintage','warrior',], {minChars: 1, indicator: indicator,tokens: ','});
}

function additem(target,formID,indicator) 
{
new Ajax.Updater(target, 'http://www.stylastic.com/fashion', {onComplete:function(request, json){Element.hide(indicator)}, onLoading:function(request, json){Element.show(indicator)},parameters:Form.serialize($(formID)),method:'post',asynchronous:true}); return false;
}

function addtag(target,formID,entry)
{
indicator = 'indicator-'+entry;
submit = 'submit'+entry;
$(submit).toggle();
new Ajax.Updater(target, 'http://www.stylastic.com/fashion', {onComplete:function(request, json){Element.hide(indicator)}, onLoading:function(request, json){Element.show(indicator)},parameters:Form.serialize($(formID)),method:'post',asynchronous:true}); return false;
}

function sendForm(target,formID, indicator, submit)
{
if (submit) {$(submit).toggle();}

new Ajax.Updater(target, 'http://www.stylastic.com/fashion', {onComplete:function(request, json){Element.hide(indicator)}, onLoading:function(request, json){Element.show(indicator)},parameters:Form.serialize($(formID)),method:'post',asynchronous:true}); return false;
}

function cancelAddItems() {
    new Effect.Fade('addItemForm');
  	new Effect.Appear('addItemsLink');

}

function sendAjax(url,indicator,formID) {
 if (formID) {
  new Ajax.Request(url, {onComplete:function(request, json){Element.hide(indicator)}, onLoading:function(request, json){Element.show(indicator)},parameters:Form.serialize($(formID)),method:'post',asynchronous:true});} else {
  new Ajax.Request(url, {onComplete:function(request, json){Element.hide(indicator)}, onLoading:function(request, json){Element.show(indicator)}, asynchronous:true}); 
 }
return false;
}

function getByAjax(target, page,indicator,removeThis,replaceForThis)
{
    var url='';
    if (replaceForThis) {
        url = page.replace(removeThis,replaceForThis);
    } else if (removeThis) {
        url = page.replace(removeThis,'');
    } else {
        url = page;
    }    	
    new Ajax.Updater(target, url, {onComplete:function(request, json){Element.hide(indicator)}, onLoading:function(request, json){Element.show(indicator)},asynchronous:true});}



function surpriseIbox(url,title, h, w) {

        //sets width and height of outer window
        if (w=='') w = 800;
        if (h=='') h = 600;

        if(showIbox(url,title,{width:w, height:h})) {
            showBG();
            window.onscroll = maintPos;
            window.onresize = maintPos;
        }
        return false;
} //end surpriseIbox


function tagGuide(target,tag_name,sourceLink) {
	var tagtext = $(target).value;
	
	if (tagtext.match(tag_name)) {
		toreplace = tag_name+',';
		$(target).value = tagtext.replace(toreplace,"");
		$(sourceLink).style.opacity='1';
	} else {
		$(target).value+=tag_name+',';
		$(sourceLink).style.opacity='0.2';
	}
}
	



//gives focus to the first text box, text area, or button that starts with an s
//do not use unless the form is the main purpose of the page - interferes with firefox's type-to-search and other big usabilty problems
function setFormFocus(formID) {

var field;
if (formID == "") {
	if (document.forms.length > 0) {
		field = document.forms[0];
	}
else {
	
	field = $A(formID);
}
for (i = 0; i < field.length; i++) {
if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
document.forms[0].elements[i].focus();
break;
}
}
}
}










//Alerts user if their input is invlad in a field.
//Sets different classname per valid or invalid input

function verify(inputID,chars,targetID) {
if (!chars){characters=4}else {characters=chars}
if(!targetID){target=inputID}else {target=targetID}
if ($(inputID).value.length >= characters) 
{$(target).className='validInput';} else {$(target).className='invalidInput';}
}


function showRatingMessage(message) {
	var msg = (message)?message:'';
	$('ratingMessage').innerHTML = msg;
}


//  UTILITY FUNCTIONS


//use this to add a function to onload
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {oldonload();}
      func();
    }
  }
}


function insertAfter(newElem, targetElem) {
	var parent = targetElem.parentNode;
	if (parent.lastChild == targetElem) {parent.appendChild(newElem);}
	else {
		parent.insertBefore(newElem, targetElem.nextSibling);
	}
}

function isMouseLeaveOrEnter(e, handler) { if (e.type != 'mouseout' && e.type != 'mouseover') return false; var reltg = e.relatedTarget ? e.relatedTarget : e.type == 'mouseout' ? e.toElement : e.fromElement; while (reltg && reltg != handler) reltg = reltg.parentNode; return (reltg != handler); }
