var HelpImgProduct = new Array;
function incrementor(number) {
	return(number+1)
}

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];}
}

var allOn = true;
function SelectAll(MyForm,MyBox){
var countBoxes = eval("document."+MyForm+"."+MyBox+".length");
	if(!countBoxes){
		eval("document."+MyForm+"."+MyBox+".checked =  allOn");
	}
	else{
		for (var i=0; i<countBoxes ;i++){
			eval("document."+MyForm+"."+MyBox+"[i].checked =  allOn");
		}
	}
allOn = !allOn;
}

function cleanField(obj){
	obj.value = obj.value.replace(/[^\d]/g,"");
	if(obj.value.length == 0 || obj.value == 0){obj.value=1}
}

function GetAjaxForm(ajaxPage, ajaxUrl, counterID, receivedID){	
	var $Count = incrementor(parseInt ($("#"+counterID).val()));	
	$("#"+counterID).val($Count);
	$.ajax({type: "GET",
			url: ajaxPage,
			data: ajaxUrl+"&index="+$Count,
			success: function(data){						
				$('#'+receivedID).append(data);									
			}
	});
}

function CheckBoxShowHide(checkBoxID, divID){
	if ($("#"+checkBoxID).attr('checked')) {
		$("#"+divID).show();
	}else{
		$("#"+divID).hide();
	}															
}

function Showing(ID){
	if ($("#"+ID) != null) {
		$("#"+ID).show();
	}														
}

function Hidding(ID){
	if ($("#"+ID) != null) {
		$("#"+ID).hide();
	}														
}

function UpdateElementField(urlString, urlScript){	
	$.ajax({type: "GET",
		url: urlScript,
		data: urlString,
		success: function(data){						
			eval(data);									
		}
	});
}

//Side Menu
function startSideMenu() {
	// code for IE
	if(!document.body.currentStyle) return;
	var subs = document.getElementsByName('SideMenu');
	for(var i=0; i<subs.length; i++) {
		var li = subs[i].parentNode;
		if(li && li.lastChild.style) {
			li.onmouseover = function() {
				this.lastChild.style.visibility = 'visible';
			}
			li.onmouseout = function() {
				this.lastChild.style.visibility = 'hidden';
			}
		}
	}
}

function SideMenuAction(menuItem, index){
	if(menuItem == 'SHAPE'){
		$("#MenuStyleItems"+index).hide();
		$("#MenuShapeItems"+index).show();
		$("#MenuVendorItems"+index).hide();
		$("#MenuMetalTypeItems"+index).hide();
		$("#MenuPriceRangeItems"+index).hide();
	}else if(menuItem == 'BRAND'){
		$("#MenuStyleItems"+index).hide();
		$("#MenuShapeItems"+index).hide();
		$("#MenuVendorItems"+index).show();
		$("#MenuMetalTypeItems"+index).hide();
		$("#MenuPriceRangeItems"+index).hide();
	}else if(menuItem == 'METALTYPE'){
		$("#MenuStyleItems"+index).hide();
		$("#MenuShapeItems"+index).hide();
		$("#MenuVendorItems"+index).hide();
		$("#MenuMetalTypeItems"+index).show();
		$("#MenuPriceRangeItems"+index).hide();
	}else if(menuItem == 'PRICERANGE'){
		$("#MenuStyleItems"+index).hide();
		$("#MenuShapeItems"+index).hide();
		$("#MenuVendorItems"+index).hide();
		$("#MenuMetalTypeItems"+index).hide();
		$("#MenuPriceRangeItems"+index).show();
	}
}

// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {	
	return LTrim(RTrim(value));	
}

function IsEmpty(sToCheck) {
   var sTest
   sTest = trim(sToCheck)
   if (sTest == null || sTest == "") {
      return true
   }
   return false
}

function SetParentFieldValue(ID, value){
	window.parent.SetFieldValue(ID, value);
}

function SetFieldValue(ID, value){
	$("#"+ID).val(value);
}

function submitForm(formID){	
	document.getElementById(formID).submit();	
}

function checkAll(rootID, howMany){
	var i;
	if(isAllChecked(rootID, howMany) == false){
		i = 1;
		for(i=1; i<=howMany; i++){
			$('#'+rootID+''+i).attr('checked', true);
		}
	}else{
		i = 1;
		for(i=1; i<=howMany; i++){
			$('#'+rootID+''+i).attr('checked', false);
		}
	}
}

function isAllChecked(rootID, howMany){
	var i;
	var allIsChk = true;
	for(i=1; i<=howMany; i++){
		if($('#'+rootID+''+i).attr('checked') == false){
			allIsChk = false;
			break;
		}
	}
	return allIsChk;
}

function focusCheck(label, id){
	var $Key = $('#'+id).val();
    if($Key == label){
		$('#'+id).val('');
	}
}
function blurCheck(label, id){
	var $Key = $('#'+id).val();
    if($Key == '' || trim($Key) == null){
		$('#'+id).val(label);
	}
}


//    var arrayHeaders  = ["tab-header1","tab-header2","tab-header3","tab-header4","tab-header5","tab-header6","tab-header7"];
//  var arrayContents = ["tab-content1","tab-content2","tab-content3","tab-content4","tab-content5","tab-content6","tab-content7"]; 

var arrayHeadersSpecs = ["specs-header1","specs-header2"];
var arrayContentsSpecs = ["specs-content1","specs-content2"];


window.onload = function(){
 //   var tabRelationship = 
   //     new ylib.widget.Tabs(arrayHeaders, arrayContents, 0);
	 var tabRelationshipSpecs = 
		new ylib.widget.Tabs(arrayHeadersSpecs, arrayContentsSpecs, 0);
}

$("#radio").change(function () {
  var str = "";
  $('#radios').submit();
})

var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;

function jsddm_open(){	
   jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');
}

function jsddm_sub_open(){	
	
  jsddm_canceltimer();
jsddm_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');
}

function jsddm_close(){	
	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
}

function jsddm_timer(){	
	closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer(){	
	if(closetimer){	
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

function js_show_sub(itm){
	$("#"+itm).css('visibility', 'visible');
}
function js_hide_sub(itm){
	$("#"+itm).css('visibility', 'hidden');
}

$(document).ready(function(){	
	$(document).pngFix(); 
	$("input[type=image]").pngFix(); 
	$('#header-search-button').pngFix(); 
	$.swapImage(".swapImage");
	$('#accordion').accordion({ active: false,
								autoHeight: false,
								clearStyle: true,
								collapsible: true,
								icons: { 'header': 'ui-icon-plus', 'headerSelected': 'ui-icon-minus' }
							 });
	$('#jsddm > li').bind('mouseover', jsddm_open);
	$('#jsddm > li').bind('mouseout',  jsddm_timer);
	//$('#jsddm > li > ul > li').bind('mouseover', jsddm_sub_open);
	//$('#jsddm > li > li').bind('mouseout',  jsddm_timer);
});

document.onclick = jsddm_close;
//Flash variables
AC_FL_RunContent = 0;

function CheckedDisabled(parentCHK, childCHK){
	if ($("#"+parentCHK).attr('checked')) {
		$("#"+childCHK).attr('disabled', '');
	}else{
		$("#"+childCHK).attr('disabled', 'disabled');
	}															
}
