navHover = function() {
	var lis = document.getElementById("navmenu").getElementsByTagName("LI");
	for (var i=0; i<lis.length; i++) {
		lis[i].onmouseover=function() {
			this.className+=" iehover";
		}
		lis[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", navHover);

$(document).ready(function(){
	
	$(function() {
		if(jQuery.browser.msie && jQuery.browser.version < 7.0)
			$(document.body).append("<iframe id='alert-back-box' src='' frameborder='0' style='position:absolute; z-index:100;top:200px; left:300px;height:500px;width:358px;display:none'></iframe>");

	    $('#container-1').tabs();
	    $('#container-2').tabs(2);
	    $('#container-3').tabs({ fxSlide: true });
	    $('#container-4').tabs({ fxFade: true, fxSpeed: 'fast' });
	    $('#container-5').tabs({ fxSlide: true, fxFade: true, fxSpeed: 'normal' });
	    $('#container-6').tabs({
	        fxFade: true,
	        fxSpeed: 'fast',
	        onClick: function() {
	            alert('onClick');
	        },
	        onHide: function() {
	            alert('onHide');
	        },
	        onShow: function() {
	            alert('onShow');
	        }
	    });
	    $('#container-7').tabs({ fxAutoHeight: true });
	    $('#container-8').tabs({ fxShow: { height: 'show', opacity: 'show' }, fxSpeed: 'normal' });
	    $('#container-9').tabs({ remote: true });
	    $('#container-10').tabs();
	    $('#container-11').tabs({ disabled: [3] });
	
	    $('<p><a href="#">Disable third tab<\/a><\/p>').prependTo('#fragment-28').find('a').click(function() {
	        $(this).parents('div').eq(1).disableTab(3);
	        return false;
	    });
	    $('<p><a href="#">Activate third tab<\/a><\/p>').prependTo('#fragment-28').find('a').click(function() {
	        $(this).parents('div').eq(1).triggerTab(3);
	        return false;
	    });
	    $('<p><a href="#">Enable third tab<\/a><\/p>').prependTo('#fragment-28').find('a').click(function() {
	        $(this).parents('div').eq(1).enableTab(3);
	        return false;
	    });
	
	});
});

function changeLanguage(languageBox)
{
	var strHref = window.location.href;
	var iso = $(languageBox).val();
	strHref = getURLParam();
	window.location = strHref + "la=" + iso;
};

function getURLParam(){
	var strHref = window.location.href.split("?");
	var aParams;

	if ( strHref[1]){
		var strQueryString = strHref[1].toLowerCase();
		var strNewQueryString = "?";
		var aQueryString = strQueryString.split("&");
		for( var iParam = 0; iParam < aQueryString.length; iParam++ ){
			aParams = aQueryString[iParam].split("=");
			if (aParams[0] != "la") {
				strNewQueryString = strNewQueryString + aParams[0] + "=" + aParams[1] + "&";
			}
	    }
	}
	return unescape(strNewQueryString);
};

function getSubOption(parentNo, section, page, action, lang, contentBox, loadingBox)
{
	var i = contentBox.substr(5,2);
	for(i; i<10; i++)
		$('#child'+i).hide();

	if(parseInt(parentNo) == parseInt($("input[name=id]").val()))
		$("input[name=parentno]").val($("input[name=oldparent]").val());
	else
		$("input[name=parentno]").val(parentNo);
	
	if(parentNo){
		$('#'+contentBox).hide();
		$('#'+loadingBox).show();
		$.get('index.php?section=' + section + '&page=' + page + '&cmd=' + action + '&la='+ lang + '&parentno=' + parentNo+ '&contentBox=' + contentBox,
			function(data){
				$('#'+loadingBox).hide();
				$('#'+contentBox).html(data);
				$('#'+contentBox).show();
			});
	}else {
		$('#'+contentBox).hide();
	}
};

function getParent(positionNo, section, page, action, lang, contentBox, loadingBox)
{
	$("input[name=parentno]").val("");
	$('#'+contentBox).hide();
	
	if(positionNo){
		$('#'+loadingBox).show();
		$.get('index.php?section=' + section + '&page=' + page + '&cmd=' + action + '&la='+ lang + '&positionno=' + positionNo,
			function(data){
				$('#'+loadingBox).hide();
				$('#'+contentBox).html(data);
				$('#'+contentBox).show();
			});
	};
};

function createUrl(page)
{
	var strHref = window.location.href.split("?")[0];
	if(page) {
		if(!parseInt(page))
		 {
			$("input[name=url]").val(strHref + "?page=" + page);
			$("input[name=pagename]").val(page);
			$("input[name=cmdname]").val("*");
			//get list of group
			var lang = $("#lang").val();
			runGet(page, 'admin', page, 'getgroupoption', lang, 'group-opt', 'group-loadingbox', viewGroup);

		}else {
			$("input[name=url]").val(strHref + "?page=static&cmd=" + page);
			$("input[name=pagename]").val("static");
			$("input[name=cmdname]").val(page);
		}
	}else {
		$("input[name=url]").val("http://");
		$("input[name=pagename]").val("");
		$("input[name=cmdname]").val("");
	}
};

function setCmd(page, cmd, groupId)
{
	var strHref = window.location.href.split("?")[0];

	if(groupId) {
		$("input[name=cmdname]").val(cmd);
		$("input[name=url]").val(strHref + "?page=" + page + "&cmd=" + cmd + "&id=" + groupId);
	}else {
		$("input[name=cmdname]").val("*");
		$("input[name=url]").val(strHref + "?page=" + page);
	}
	
}

function clearPage()
{
	$("select[name=pageno]").val("");
	$("select[name=pageoption]").hide();
	$("input[name=pagename]").val("");
	$("input[name=cmdname]").val("");
};

function runGet(id, section, page, action, lang, contentBox, loadingBox, callback)
{
	if(id){
		$("#"+contentBox).hide();
		$('#'+loadingBox).show();
		$.get('index.php?section=' + section + '&page=' + page + '&cmd=' + action + '&la='+ lang + '&id=' + id,
			function(data){
				callback(data, contentBox, loadingBox);
			});
	};
}

function getScore(id, contentBox)
{
$.get('index.php?section=' + 'user' + '&page=' + 'product' + '&cmd=' + 'getscore' + '&id=' + id ,
			function(data){
				$("#"+contentBox).html(data);
			});
}

function runG(id,id2, section, page, action, lang, contentBox, loadingBox)
{
	if(id){
		$('#'+loadingBox).show();
		if($.get('index.php?section=' + section + '&page=' + page + '&cmd=' + action + '&la='+ lang + '&id=' + id + '&id2=' + id2,
			function(data){
				$("#"+contentBox).html(data);
				$('#'+loadingBox).hide();
			}))
		return true;
		};
}

function runGet2(id,id2, section, page, action, lang, contentBox, loadingBox)
{
	if(id){
		$("#"+contentBox).hide();
		$('#'+loadingBox).show();
		$.get('index.php?section=' + section + '&page=' + page + '&cmd=' + action + '&la='+ lang + '&id=' + id + '&id2=' + id2,
			function(data){
				$("#"+contentBox).html(data);
				$('#unitPrice').val(data);
				$("#"+contentBox).show();
				$('#'+loadingBox).hide();
			});
		};
}

function runUrl(url, contentBox, loadingBox){
	if(url){
		$("#"+contentBox).hide();
		$('#'+loadingBox).show();
		$.get(url,
			function(data){
				$("#"+contentBox).html(data);
				$("#"+contentBox).show();
				$('#'+loadingBox).hide();
			});
		};
}
function showProfile(){
	if($("input[name='profile']:checked").val()!=undefined )
	{
		runUrl('index.php?page=user&cmd=checkprofile&id=0')
	}else{
		runUrl('index.php?page=user&cmd=checkprofile&id=1')
	}
	
}


function addScore(id,id2, section, page, action, lang, contentBox, loadingBox)
{
	if(id && id2){
		$("#"+contentBox).hide();
		$('#'+loadingBox).show();
		$.get('index.php?section=' + section + '&page=' + page + '&cmd=' + action + '&la='+ lang + '&id=' + id + '&id2=' + id2,
			function(data){
				$("#"+contentBox).html(data);
				$("#"+contentBox).show();
				$('#'+loadingBox).hide();
			});
		};
getScore(id, 'rateCount');	
}


function showAlert(title, content)
{
	var topPos = document.documentElement.scrollTop + 200;
	
	$('#alert-title-txt').html(title);
	$('#alert-content').html(content);
	$('#alert-box').css({ top: topPos+'px', width: '350px'});
	
	if(jQuery.browser.msie && jQuery.browser.version < 7.0) {
		helpHeight = parseInt($('#alert-box').height()) + 10;
		$('#alert-back-box').css({top : topPos+'px', height : helpHeight+'px'});
		$('#alert-back-box').show();
	}
	
	$('#alert-box').fadeIn();
	
}

function closeAlert()
{
	$('#alert-box').fadeOut();
}

function goTopPage(speed)
{
	if(typeof(speed) != "number")
		speed = 60;
	
	document.documentElement.scrollTop = document.documentElement.scrollTop - 10;
	if(document.documentElement.scrollTop)
		setTimeout(goTopPage, speed, speed);
}

function showLargImage(imageNo, width)
{
	var topPos = document.documentElement.scrollTop + 100;
	var content = "<img src=img.php?i=" + imageNo + "&w=" + width + " />";
	$('#alert-title-txt').html('');
	$('#alert-content').html(content);
	$('#alert-box').css({ top: topPos+'px', width: (width + 20)+'px'});
	
	if(jQuery.browser.msie && jQuery.browser.version < 7.0) {
		helpHeight = parseInt($('#alert-box').height()) + 600;
		$('#alert-back-box').css({top : topPos+'px', height : helpHeight+'px'});
		$('#alert-back-box').show();
	}
	
	$('#alert-box').fadeIn();
}

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }



function priceCal(amount){
	if ( !IsNumeric(amount) || amount<1 ) {
	amount=1;
	$('#tedad').val(1);
	}
	var amount = parseInt(amount);
	var price = parseInt($('#unitPrice').val());
	price = amount*price;
	$('#price').html(price);
	
}

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }


function priceCal(amount){
	if ( !IsNumeric(amount) || amount<1 ) {
	amount=1;
	$('#tedad').val(1);
	}
	var amount = parseInt(amount);
	var price = parseInt($('#unitPrice').val());
	price = amount*price;
	$('#price').html(price);
	
}


/*function changePics(target,src) {
	$('#'+target).fadeOut();
	$('#proPicLoad').show();
	$('#'+target).attr({ src: src }); 
	$('#'+target).fadeIn();
	$('#proPicLoad').hide();
}*/

function changePic(id,newSrc) {
   $('#proPicLoad').show();
   var obj = document.getElementById(id);
   var src = obj.src;
   var pos = src.indexOf('?');
   obj.src = newSrc;
   $(obj).load(function(){$('#proPicLoad').hide();});
}

function disDiv(id,dis) {
    var theDiv = document.getElementById(id)
    var theFields = theDiv.getElementsByTagName('input');
    for (var i=0; i < theFields.length;i++) theFields[i].disabled=dis;
    theDiv.disabled=dis
  }
  
function sliding(divId) {
$('#'+divId).slideToggle('600');
}
function refreshBasket(){
	runG('1','', 'user', 'shop', 'refreshBasket', '', 'shoppingCart', 'cartLoad');
}
function addToCart(productId,productBranchId,amount) {
	$('#cartLoad').show();
	var id = productId+','+productBranchId;
	if(runG(id,amount, 'user', 'shop', 'addToCart', '', '', ''))
	setTimeout('refreshBasket()','1000');
}
function removeCartItem(itemId) {
	$('#cartLoad').show();
	if(runG(itemId,'', 'user', 'shop', 'removeBasketItem', '', '', ''))
	setTimeout('refreshBasket()','2000');
}

function confirmSubmit(id,id2, section, page, action, lang, contentBox, loadingBox)
{

var agree=confirm("آیا شما درخواست جایزه کرده اید؟");
if (agree)
	runG(id,id2, section, page, action, lang, contentBox, loadingBox) ;
else
	return false ;
}

function confirmSubmitEditProfile()
{

var agree=confirm("تغییر اطلاعات شما با موفقیت ثبت شد");
if (agree){
	runG('','', 'user', 'user', 'userhome', '', '', '') ;
}else
	return false ;
}

function updateUnitprice(productBranchId,unitPrice) {
	runG(productBranchId,unitPrice, 'admin', 'shop', 'updateup', '', '', 'statusLoad');
}

function updateThisprice(productBranchId,thisPrice) {
	runG(productBranchId,thisPrice, 'admin', 'shop', 'updatetp', '', '', 'statusLoad');
}

function updateTotal(productBranchId,total){
	runG(productBranchId,total, 'admin', 'shop', 'updateto', '', '', 'statusLoad');
}

function redirect(){
	window.location = "index.php?page=user&cmd=userhome";

}


//form tags to omit in NS6+:
var omitformtags=["input", "textarea", "select"]
omitformtags=omitformtags.join("|")

function disableselect(e){
if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)
return false
}


function reEnable(){
return true
}

if (typeof document.onselectstart!="undefined")
document.onselectstart=new Function ("return false")
else{
document.onmousedown=disableselect
document.onmouseup=reEnable
	
}

  
