function alertme(id, spid, title ) {
	var tmp_id="";
	if ( id != "" ){
		tmp_id = id;
	} else if ( spid != "" ){ 
		tmp_id = spid;
	}

	var lid="#" + tmp_id + ":first";
	var lid2="#" + tmp_id ;

	//document.write( " lid= " + lid );
     	if ($(lid).is(":hidden")) {
		var form_str = "<div id='alert_input' >	<form id='alert_form' style='display: inline;' method='POST' action='set_alert.php'><table border='0' cellspacing='0' cellpadding='0' style='color:#666666;'> <tr height=30px><td width=100px>Email ID </td><td> <input type='text' name='email_id' size='40' maxlength=60 value=''></td></tr> <tr height=30px><td width=100px>Alert Price </td><td><input type='text' name='price' size='5' maxlength=5 value=''> &nbsp;&nbsp;<input type='submit' value='Alert Me' name='submit'> </td></tr> </table> <input type='hidden' name='id' value=" + id + " > <input type='hidden' name='spid' value=" + spid + " > <input type='hidden' name='title' value='" + title + "' > </form> </div> <div id='alert_output'> </div> ";

		$("#alert_input").remove();
       		$("#alert_output").remove();
       		$(".alert").fadeOut("fast");

		$(lid2).append(form_str);
       		$(lid2).slideDown("slow");
      	} else {
       		$("#alert_input").remove();
       		$("#alert_output").remove();
       		$(lid2).fadeOut("slow");
      	}

	$('#alert_form').ajaxForm({
       		target: '#alert_output',
		beforeSubmit: alert_form_beforeSubmit,  // pre-submit callback
        	success: function() {
            		$('#alert_output').fadeIn('slow');
        	}
    	});
}

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "You didn't enter an email address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}

function alert_form_beforeSubmit ( formData, jqForm, options ){
	var queryString = $.param(formData);
	$("#alert_output").prepend("<div id='alert_loading'><img src='./images/ajax-loader-alert.gif' /></div>");
	$("#alert_loading")
			.ajaxStart(function() {$(this).show();})
			.ajaxStop(function() {$(this).hide();});
	return true;
}

function setSortURL( selection ) { 
	var idx, currentURL, URL;
	idx = selection.selectedIndex; 
	currentURL = location.href.replace(/\&s=\d+/,"");
	currentURL = currentURL.replace(/\?s=\d+/,"");
	currentURL = currentURL.replace(/\&p=\d+/,"");
	currentURL = currentURL.replace(/\?p=\d+/,"");
	
	isParamExist = currentURL.indexOf( '?' );
	if( isParamExist == -1 ){
		URL = currentURL + "?p=1" + "&s=" + selection.options[idx].value ;
	} else {
		URL = currentURL + "&p=1" + "&s=" + selection.options[idx].value ;
	}

        window.location.href = URL; 
}

function setDateSortURL( selection ) { 
	var idx, currentURL, URL;
	idx = selection;
	currentURL = location.href.replace(/\&t=\d+/,"");
	currentURL = currentURL.replace(/\?t=\d+/,"");
	currentURL = currentURL.replace(/\&p=\d+/,"");
	currentURL = currentURL.replace(/\?p=\d+/,"");
	
	isParamExist = currentURL.indexOf( '?' );
	if( isParamExist == -1 ){
		URL = currentURL + "?p=1&t=" + selection ;
	} else {
		URL = currentURL + "&p=1&t=" + selection ;
	}

        window.location.href = URL; 
}
function setDateSortURL1( selection ) { 
	var idx, currentURL, URL;
	idx = selection;
	currentURL = location.href.replace(/\&t=\d+/,"");
	currentURL = currentURL.replace(/\?t=\d+/,"");
	currentURL = currentURL.replace(/\&p=\d+/,"");
	currentURL = currentURL.replace(/\?p=\d+/,"");

	isParamExist = currentURL.indexOf( '?' );
	if( isParamExist == -1 ){
		URL = currentURL + "?p=1&t=" + selection ;
	} else {
		URL = currentURL + "&p=1&t=" + selection ;
	}

        window.location.href = URL; 
}

function leftString(str, n){
	if (n <= 0) 
		return ""; 
	else if (n > String(str).length) 
		return str; 
	else 
		return String(str).substring(0,n); 
}

function rightString(str, n){ 
	if (n <= 0) 
		return ""; 
	else if (n > String(str).length) 
		return str; 
	else { 
		var iLen = String(str).length; 
		return String(str).substring(iLen, iLen - n); 
	} 
}


