function toggleLogin(){
	$('nav_user_login').style.display=='none'?Element.show('nav_user_login'):Element.hide('nav_user_login');
}
function v(){
}
 
function clearText(theText) {
     if (theText.value == theText.defaultValue) {
         theText.value = ""
     }
}
 
function emlValid(theForm)
{
  if (theForm.mailFromAddress.value == "")
  {
    alert("Please enter your e-mail address.");
    theForm.mailFromAddress.focus();
    return (false);
  }
  Validemail = isEmail(theForm.mailFromAddress.value)
  if (!Validemail)
  {
    alert("It appears that you have entered an invalid e-mail address.  Please check it.");
    theForm.mailFromAddress.focus();
    return (false);
  }
  return (true);
}

function checkForm(form) {
		if (document.join.login.value == "") {
			alert("You must enter an Email Address.");
			document.join.login.focus();
			return false;
		}	
		
 
		if (emailCheck('join') == false) {
			return false;
		}
	  
	
}

function checkPaymentForm(form) {
		if (document.payment.email.value == "") {
			alert("You must enter an Email Address.");
			document.payment.email.focus();
			return false;
		}	
		
 
		if (emailCheck('payment') == false) {
			return false;
		}
	  
	
}

function emailCheck (page) {
	
	if (page == 'join') {

		emailStr = document.join.login.value;

	} else {
	
		emailStr = document.payment.email.value;
	
	}

	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */

	var emailPat=/^(.+)@(.+)$/;

	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ] */

	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/

	var validChars="\[^\\s" + specialChars + "\]";

	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */

	var quotedUser="(\"[^\"]*\")";

	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	/* The following string represents an atom (basically a series of non-special characters.) */

	var atom=validChars + '+';

	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */

	var word="(" + atom + "|" + quotedUser + ")";

	// The following pattern describes the structure of the user

	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	/* Finally, let's start trying to figure out if the supplied address is valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */

	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {

	/* Too many/few @'s or something; basically, this address doesn't
	even fit the general mould of a valid e-mail address. */

	alert("E-mail address seems incorrect (check @ and .'s).");
	return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	// Start by checking that only basic ASCII characters are in the strings (0-127).

	for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
	alert("The e-mail address contains invalid characters.");
	return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
	alert("The e-mail address domain name contains invalid characters.");
	return false;
	   }
	}

	// See if "user" is valid 

	if (user.match(userPat)==null) {

	// user is not valid

	alert("The e-mail address doesn't seem to be valid.");
	return false;
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {

	// this is an IP address

	for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
	alert("Destination IP address is invalid.");
	return false;
	   }
	}
	return true;
	}

	// Domain is symbolic name.  Check if it's valid.
	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
	alert("The e-mail address domain name does not seem to be valid.");
	return false;
	   }
	}

	// Make sure there's a host name preceding the domain.

	if (len<2) {
	alert("The e-mail address is missing a hostname.");
	return false;
	}

	// If we've gotten this far, everything's valid!
	return true;
}


function legalJargon(page) {
	if(typeof(page)=='undefined')page='/submitterms.html';
	var x = (screen.width/2) - 175;
	var y = (screen.height/2) - 225;
	var newWin = window.open(page,'legal','width=570,height=450,left='+x+',top='+y+',screenX='+x+',screenY='+y+',status=1,scrollbars=1');
	newWin.opener.name = "threadless";
}

var varidbuyit = 'notset';
function score(id,action,current,hash){
	if(action=='buy'){
		if(varidbuyit=='notset')varidbuyit=current;
		$('idbuyit').src='/imgs/score_buy'+(varidbuyit==0?'_o':'')+'.gif';
		varidbuyit=(varidbuyit==0?1:0);
	}else{
		$('scorechunk').innerHTML='<img src="/imgs/loading.gif" align="absmiddle"> Saving...';
		var myAjax = new Ajax.Request('/scripts/quicksub.php',{method: 'post', parameters: "id="+id+"&score="+action+"&idbuyit="+varidbuyit+"&hash="+hash, onComplete: score_done});
	}
}
function score_done(originalRequest){
	$('scorechunk').innerHTML= originalRequest.responseText;	
	
	valid.deactivate();
}
function type_score(id,score,hash){
	$('slogan_load_'+id).innerHTML='<img src="/imgs/loading.gif" style="margin-left:5px;margin-bottom:6px;">';
	setTimeout(function(){$('slogan_load_'+id).innerHTML=''},1000);
	$('slog'+id+'_no').src='/imgs/omg_no'+(score==0?'_r':'')+'.gif';
	$('slog'+id+'_wear').src='/imgs/omg_wear'+(score==1?'_r':'')+'.gif';
	var myAjax = new Ajax.Request('/scripts/slogans.rate.php',{method: 'get', parameters: "justscore=1&hash="+hash+"&sloganid="+id+"&rating="+(score==1?'yes':'no')});
}

var currentid;
function enlg(id){ 
	if(id!=currentid){
		Position.prepare();
		coords = Position.cumulativeOffset($('product_'+id));
		$('overlay_piece').style.left=coords[0]+168+'px';
		$('overlay_piece').style.top=coords[1]-10+'px';
		$('overlay_piece').innerHTML='<div id="stock_loading"></div>';
		Element.show('overlay_piece');
		var superAjax = new Ajax.Updater('overlay_piece',"http://eiuclothing.com/ajax/enlg.php",{method: 'get', parameters: "&id="+id});	
		currentid=id;
	}else{
		Element.hide('overlay_piece');
		currentid='';
	}
}
var currentid;
function showQuick(id){
	if(id!=currentid){
		Position.prepare();
		coords = Position.cumulativeOffset($('sub_'+id));
		$('overlay_piece').style.left=coords[0]-16+'px';
		$('overlay_piece').style.top=coords[1]+'px';
		$('overlay_piece').innerHTML='<div id="quick_piece"><a href="/scripts/quicksub.php?id='+id+'" class="lbOn"></a></div>';
		initialize();
		Element.show('overlay_piece');
		currentid=id;
	}
}

var currentstockid;
function reprint_show(stockid){
	if(stockid!=currentstockid){
		Position.prepare();
		coords = Position.cumulativeOffset($('reprintme_'+stockid));
		$('reprint_overlay').style.left=coords[0]-80+'px';
		$('reprint_overlay').style.top=coords[1]-180+'px';
		$('reprint_overlay').innerHTML='<img src="/imgs/loading.gif" align="absmiddle"> Loading...';
		Element.show('reprint_overlay');
		var thisAjax = new Ajax.Updater('reprint_overlay',"/scripts/reprintform.php",{method: 'get', parameters: "&id="+stockid});	
		currentstockid=stockid;
	}else{
		Element.hide('reprint_overlay');
		currentstockid='';
	}	
}
function reprint(id,emails){
	$('reprint_overlay').innerHTML='<img alt=\"Loading...\" src=\"/imgs/loading.gif\" width=\"18\" height=\"18\" align=\"absmiddle\"> Saving your request...';	
	var superAjax = new Ajax.Updater('reprint_overlay',"/scripts/reprintform.php",{method: 'post', parameters: "&id="+id+"&emails="+emails});		
}


function enterPromo(id){
	$('promo'+id).innerHTML='<img alt=\"Loading...\" src=\"/imgs/loading.gif\" width=\"18\" height=\"18\" align=\"absmiddle\"> Counting you in...';	
	var superAjax = new Ajax.Updater('promo'+id,"/scripts/enterpromo.php",{method: 'post', parameters: "&id="+id });		
}
function tellafriend(id,emails){
	$('tellafriend').innerHTML='<img alt=\"Loading...\" src=\"/imgs/loading.gif\" width=\"18\" height=\"18\" align=\"absmiddle\"> Sending email(s)...';	
	var superAjax = new Ajax.Updater('tellafriend',"/scripts/tellafriend.php",{method: 'post', parameters: "&id="+id+"&emails="+emails});		
}

/*---
Favorites Stuff
---*/
function watchToggle(type,id){
	url = "/scripts/watch.php";
	pars = "&id="+id+"&type="+type;
	
	if(type!='bf')$('fave_'+id).innerHTML="<img alt=\"Loading...\" src=\"/imgs/loading.gif\" width=\"18\" height=\"18\" align=\"absmiddle\">";
	else $('fave_'+id).innerHTML="<img alt=\"Loading...\" src=\"/imgs/loading.gif\" width=\"18\" height=\"18\" align=\"absmiddle\"> &nbsp; <span class=\"grey\">Please wait</span>";
	var myAjax = new Ajax.Updater(
		'fave_'+id,
		url, 
		{method: 'post', parameters: pars}
		);
}

function showPhoto(type,id,object){
	//$('product_photo').innerHTML="<img alt=\"Loading...\" src=\"/imgs/loading.gif\" width=\"18\" height=\"18\" align=\"absmiddle\"> &nbsp; Loading...";
	object.className='selected';
	if(type=='photo') {
		if(id >= photoArray.length) id = 0;
		else if(id < 0) id = photoArray.length-1;			
		photoIndex=id;
		id = photoArray[id];
	}
	var superAjax = new Ajax.Updater('product_photo',"/scripts/productphoto.php",{method: 'get', parameters: "&type="+type+"&id="+id});	
}

function loadPresence(id){
	flickr_url = "/scripts/profile_flickr.php";
	flickr_pars = "&id="+id;
	var flickrAjax = new Ajax.Updater('profile_flickr',flickr_url,{method: 'post', parameters: flickr_pars}	)
	
	delicious_url = "/scripts/profile_delicious.php";
	delicious_pars = "&id="+id;
	var deliciousAjax = new Ajax.Updater('profile_delicious',delicious_url,{method: 'post', parameters: delicious_pars}	)
	
	lastfm_url = "/scripts/profile_lastfm.php";
	lastfm_pars = "&id="+id;
	var lastfmAjax = new Ajax.Updater('profile_lastfm',lastfm_url,{method: 'post', parameters: lastfm_pars}	)

	myspace_url = "/scripts/profile_myspace.php";
	myspace_pars = "&id="+id;
	var myspaceAjax = new Ajax.Updater('profile_myspace',myspace_url,{method: 'post', parameters: myspace_pars}	);	
		
	rssentries_url = "/scripts/profile_rss.php";
	rssentries_pars = "&id="+id;
	var rssentriesAjax = new Ajax.Updater('profile_rss',rssentries_url,{method: 'post', parameters: rssentries_pars}	)
}


function showTab(show){
	$(show).style.display='';
	$('nav_'+show).className='active';
	var args = showTab.arguments;	  
	for (var i = 1; i < args.length; i++) {		
		$(args[i]).style.display='none';
		$('nav_'+args[i]).className = $('nav_'+args[i]).className.replace('active','');
	}
	
} 


var form_submitted = false;

function isDoubleSubmit ( msg )
{
  if ( form_submitted )
  {
    alert ( msg );
    return false;
  }
  else
  {
    form_submitted = true;
    return true;
  }
}

function roll(img_name, img_src)
   {
   document[img_name].src = img_src;
   }



function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function question(URL) {
	aWindow=window.open(URL, "thewindow","resizable=yes,toolbar=yes,width=900,height=600,status=no,scrollbars=yes,menubar=no");
}

function enlarge(url) {
	aWindow=window.open(url, "thewindow","resizable=yes,toolbar=no,width=620,height=680,status=no,scrollbars=no,menubar=no");
}
