// populates select list from array of items given as objects: { name: 'text', value: 'value' }

function populateSelect(el, items,sel) {

el.options.length = 0;

   if (items.length > 0)
        el.options[0] = new Option('-- Please Select --', '');

    $.each(items, function () {
        el.options[el.options.length] = new Option(jQuery.trim(this.name), jQuery.trim(this.value));
    });
	$(el).val(sel);

}


function toJSON(string1,string2) {
 	
	if (!string2) string2=string1;
	//string1 = string1.split(",");
	//string2 = string2.split(",");
  
	var jsonObj = new Array();
    for (var i = 0; i < string1.length; i++) {
    jsonObj.push({name: string1[i], value: string2[i]});}
	return jsonObj;
	
}
function openFM(id,closeFM) {
//console.log(id);
if (!closeFM) {
	$('#'+id).parent().parent().show();
	//$('#'+id).parent().parent().show();
	len = $('#'+id + ' LI').length;
	if (len <6){
	$('#'+id).animate({height: 180}, 500);
	} else {
	$('#'+id).animate({height: 315}, 1000);
	}
	$('.popup').popupwindow(profiles); 
} else {
		$('#'+id).animate({height: 0}, 1000);
		
		$('#'+id).parent().parent().hide();
	}
}

$.urlParam = function(name,str){
	if (!str) str = window.location.hrefl
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(str);
return results[1] || 0;
}
function exeAjax(url,div,func) {

$.ajax({
		url: url,
		success: function(responseText){
		var $response=$(responseText);
		divs = div.split(",");
			for (var q=0;q<divs.length;q++){
				
				$("#"+divs[q]).html($response.find('#'+divs[q]).html());
			}
			if (func) setTimeout(func,0); 
		}

   });
}


$(document).ready(function(){
	//queue all requests
	$.ajaxSetup({mode: 'queue'});
$(document).ajaxStart($.blockUI).ajaxStop($.unblockUI);

$("select[class^='get_']").live("change",function(e, param) {
												  
 if ($(this).find("option:selected").attr("class") != "") { b= $(this).find("option:selected").attr("class");} else {b = ($(this).val()); }
 a= ($(this).attr("class"));

 a = a.substring(4,a.length);
 c = ($(this).attr("id"));
 table = a.split("|")[0];
 where_clause=a.split("|")[1] + ' IN (' + b + ')';
 
	if (b != ""){
		$.ajax({
		  url: '/cfc/ajax.cfc?wsdl&method=GetTable&returnformat=json&queryformat=column&table='+table+'&where='+where_clause,
		  dataType: 'json',
		  success:  function(json){var record = [];record[c+"_"+table] = json.DATA;handleStruct(record,c,param,a.split("|")[2]);}
		});
	}
});

$(".qty").live('change',function (e) {
	if ($(this).val() !="") {
		if ($(this).val()=="more"){
			var newLength=(this.options.length-2)+10;
			$(this).find('option').remove().end();
			$(this).append( new Option('0','0') );
			for (y=1;y<=newLength;y++){	
				$(this).append( new Option(y,y) );
			}
			$(this).append( new Option('more..','more') );
		}
	}
});

});

//function initContentSub() {//Shadowbox.init();
//Shadowbox.clearCache();
//Shadowbox.setup("a.gallery", {gallery:"gallery"});}

Array.prototype.clean = function(deleteValue) {
  for (var i = 0; i < this.length; i++) {
    if (this[i] == deleteValue) {this.splice(i, 1);i--;}
  }
  return this;
};

jQuery.fn.fadeThenSlideToggle = function(speed, easing, callback) {
    if (this.is(":hidden")) {
        return this.slideDown({duration: 500, easing: "easeInOutCirc"}).animate({opacity: 1},700, "easeInOutCirc", callback);
    } else {
        return this.fadeTo(450, 0, "easeInOutCirc").slideUp({duration: 500, easing: "easeInOutCirc", complete: callback});
    }
};

function reloadParent(url) {
if (!url) url = window.opener.document.location.href;
window.opener.document.location.href = url;
}

function errorBlur(errorfields){
		for (var index=0;index<errorfields.length;index++) {
	$("#"+errorfields[index]).addClass("error_focus_Field");
			$("#"+errorfields[index]).blur(function() {$(this).removeClass("error_focus_Field");});
	}
}
