function checkall(targetForm) {
  frm = document.forms[targetForm];
  for(n=0 ;n<frm.length;n++)
  { frm[n].checked = true; }
}


function notcheckall() {
  for(n=0 ;n<document.form.length;n++)
  { document.form[n].checked = false; }
}

function gotourl(path,targetForm) {
  frm = document.forms[targetForm];
  frm.action = path;
  frm.submit();
}

function popup(path,wTop,wLeft,wWidth,wHeight) {
  win = window.open(path,"","width="+wWidth+",height="+wHeight+",top="+wTop+",left="+wLeft);
  win.focus();
}

function popupwithstyle(path,wstyle) {
  win = window.open(path,"",wstyle);
  win.focus();
}

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.0
  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 && document.getElementById) x=document.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 pay_by_bank(){
	document.pay_ment.paym.value="bank";
	document.pay_ment.submit();
}
 
function pay_by_worldpay(){
	document.pay_ment.paym.value="worldpay";	
	document.pay_ment.submit();
}

function pay_by_paypal(){
	document.pay_ment.paym.value="paypal";
	document.pay_ment.submit();
}

function pay_by_protx(){
	document.pay_ment.paym.value="protx";
	document.pay_ment.submit();
}

function pay_by_cncard(){
	document.pay_ment.paym.value="cncard";
	document.pay_ment.submit();
} 
 
/*
Cross browser Marquee II- ?Dynamic Drive (www.dynamicdrive.com)
For full source code, 100's more DHTML scripts, and TOS, visit http://www.dynamicdrive.com
Credit MUST stay intact
*/

//Specify the marquee's width (in pixels)
var marqueewidth="200px"
//Specify the marquee's height
var marqueeheight="100px"
//Specify the marquee's marquee speed (larger is faster 1-10)
var marqueespeed=1
//Pause marquee onMousever (0=no. 1=yes)?
var pauseit=1

var marqueecontent=''

//Specify the marquee's content
//Keep all content on ONE line, and backslash any single quotations (ie: that\'s great):

////NO NEED TO EDIT BELOW THIS LINE////////////

marqueespeed=(document.all)? marqueespeed : Math.max(1, marqueespeed-1) //slow speed down by 1 for NS
var copyspeed=marqueespeed
var pausespeed=(pauseit==0)? copyspeed: 0
var iedom=document.all||document.getElementById
var actualheight=''
var cross_marquee, ns_marquee

function populate(){
	if (iedom){
		cross_marquee=document.getElementById? document.getElementById("iemarquee") : document.all.iemarquee
		cross_marquee.style.top=parseInt(marqueeheight)+8+"px"
		cross_marquee.innerHTML=marqueecontent
		actualheight=cross_marquee.offsetHeight
	}
	else if (document.layers){
		ns_marquee=document.ns_marquee.document.ns_marquee2
		ns_marquee.top=parseInt(marqueeheight)+8
		ns_marquee.document.write(marqueecontent)
		ns_marquee.document.close()
		actualheight=ns_marquee.document.height
	}
	lefttime=setInterval("scrollmarquee()",20)
}

function scrollmarquee(){
	if (iedom){
		if (parseInt(cross_marquee.style.top)>(actualheight*(-1)+8))
			cross_marquee.style.top=parseInt(cross_marquee.style.top)-copyspeed+"px"
		else
			cross_marquee.style.top=parseInt(marqueeheight)+8+"px"
	}
	else if (document.layers){
		if (ns_marquee.top>(actualheight*(-1)+8))
			ns_marquee.top-=copyspeed
		else
			ns_marquee.top=parseInt(marqueeheight)+8
	}
}
 
 
 //Retrieve the relative path of the current location, with a specified number of tree levels
function getRelativePath( dirLevel ){
	
	var path = new String (document.location);
	var extractPath = "";
	var strokePos = path.length;
	var currStrokePos;
	
	for ( i=0; i< dirLevel; i++ ){
		currStrokePos = path.lastIndexOf("/", strokePos-1)
		extractPath = "/" + path.substring(  strokePos , currStrokePos + 1 ) + extractPath;
		strokePos = currStrokePos;
	}
	return extractPath;
}


//Set the style for an active tab button
function setTabStyle( elementID ){
	document.getElementById( elementID ).firstChild.style.backgroundImage="url(../../sc_upload/templates/images/section_bg2.jpg)";
	document.getElementById( elementID ).firstChild.style.color = '#FFFFFF' ;
}

//Common show and hide tag function
 function xup( div_tag){
	document.getElementById(div_tag).style.display = "none";
 }
 function oup( div_tag){
	document.getElementById(div_tag).style.display = "block";
 }
 
  function switch_series_box(elName, chk){
	 boxes = document.getElementsByName(elName);
	 for(i=0; i< boxes.length; i++){
		 if(chk) boxes[i].checked = true;
		 else if(!chk) boxes[i].checked = false;
	 }
 }
 
  function resetAssignedForm(formID){
 	 theForm = document.getElementById(formID);
	 
	 for (var i=0;i<theForm.length;i++){
	 	elm = theForm.elements[i];
		if( elm.type == "text" )
			elm.value="";
		if( elm.type == "select-one" )
			elm.selectedIndex=0;
		if( elm.type == "checkbox" )
			elm.checked=false;
	 }
 }
 
 
 function top_10_switch () {

	 /*if( $("#top_10_1").css('width')=="228px" ){
		$("#top_10_1")
			.animate({width: '0px', height: '0px'}, 1000)
			.css({'display': 'none'})
		$("#top_10_2")
			.animate({width: '228px', height: '300px'}, 1000)
			.css({'display': 'block'})
			
		$("#top_10_switch")
			.css({'background':'url(../../sc_upload/templates/images/b_previous01.gif) top left no-repeat'})
	 }
	 else if ( $("#top_10_1").css('width')=="0px" ){
		
		$("#top_10_2")
			.animate({width: '0px', height: '0px'}, 1000)
			.css({'display': 'none'})
		$("#top_10_1")
			.animate({width: '228px', height: '300px'}, 1000)
			.css({'display': 'block'})
		$("#top_10_switch")
			.css({'background':'url(../../sc_upload/templates/images/b_next01.gif) top left no-repeat'})
	 }*/
	 
	 
	 if (document.getElementById("top_10_1").style.display == "block") {
		 	document.getElementById("top_10_1").style.display = "none";
		 	document.getElementById("top_10_2").style.display = "block";
			document.getElementById("top_10_switch").style.background = "url(../../sc_upload/templates/images/b_previous01.gif) top left no-repeat";
	 }
	 else {
		 	document.getElementById("top_10_2").style.display = "none";
		 	document.getElementById("top_10_1").style.display = "block";
			document.getElementById("top_10_switch").style.background = "url(../../sc_upload/templates/images/b_next01.gif) top left no-repeat";
	 }
 }
 
 function init_sliding_bar( slider_id, btnNext_id, btnPrev_id, visible_item, item_spacing ){
		$( slider_id ).jCarouselLite({
				btnNext: btnNext_id,
				btnPrev: btnPrev_id,
				visible: visible_item,
				circular: true,
				auto: null, // 2800
				spacing: item_spacing	
				/*This new attribute must set as same as the margin-left of the li tag in CSS
				Otherwise the item will not display corrrectly.*/
			});
	}
	
	function turning_product( curr_obj ){
		if( waiting_queue ) keep_scrolling=false;
		
		if( keep_scrolling ){
			$( '#'+curr_obj ).trigger('click')
			setTimeout( function(){ turning_product( curr_obj ) }, 1000 );
		}
		else{
			scrolling_obj_exist = false;
			waiting_queue = false;
		}
	}
	
	function swap_scrolling_obj( pending_obj ){
		if( scrolling_obj_exist ){
			keep_scrolling = false;
			waiting_queue = true;
			setTimeout( function(){ swap_scrolling_obj( pending_obj ) }, 1 );
		}
		else {
			turning_product( pending_obj )
		}
	}

function in_array( key, array_obj ){
	for( i=0; i<array_obj.length; i++ ){
		if( array_obj[i].toString().search(','+key+',') >0 ){
			return i;
		}
	}
	return false;
}

/*===============================================================================

  ===============================================================================*/
/* Usage: This object creates paging effect on tables only.

   Example Code: 
	
	[HTML]
		<table id="table_with_paging">
			<tr>.....<tr>
			<tr>.....<tr>
		</table>
	
	[Scripts]
		new paging_SxL( 'table_with_paging', 2, true );        
		
	[Explaination]
		The above code gives the paging effect on 
			1) the table which id=table_with_paging;
			2) with 2 records per page and;
			3) with an text box to edit the num of records showing per page
  ===============================================================================*/


function paging_SxL( target_table_ID, num_records_showing, edit_view ){
	window[target_table_ID] = this;
	this.varName = target_table_ID;
	this.listTable = $('#'+target_table_ID);
	this.numRec = $('#'+target_table_ID+' tr').length;
	this.onPage = 1;
	this.pagination = $('.pages');
	this.viewRec = num_records_showing;
	this.paging = page_list;
	this.toPage = toPage;
	this.refreshView = recal_paging;
	this.editable = edit_view;
	
	this.paging();
	this.toPage(this.onPage);
}

function page_list(){
	allRec = this.numRec;
	viewing = this.viewRec;
	pages = parseInt( allRec/viewing );
	pages = (allRec%viewing>0)? pages+1:pages;
	
	$('.pages').html('')
	
	pageLink = "<div style=' margin: 10px 20px; '> Page: ";
	input_field = "<span style='margin-left: 50px; '>Showing <input id='cust_veiwRec' onchange='"+this.varName+".refreshView(this.value)' value='"+this.viewRec+"' style='width: 30px;'/> records per page <span>";
	
	for( i=1; i<=pages; i++ ){
		pageLink += (i>1)? "|":"";
		pageLink += ' <a href="javascript:'+this.varName+'.toPage('+i+')">'+i+'</a> ';	
	}
	pageLink += (this.editable)? input_field:"";
	$('.pages').append(pageLink+"</div>");
}

function toPage( page ){
	this.onPage=page;
	
	endRec = page*this.viewRec-1;
	startRec = endRec-this.viewRec+1;
	
	$("#"+this.varName+" tr").hide();
	for( i=startRec; i<=endRec; i++){
		$("#"+this.varName+" tr:eq("+i+")").show();
	}
}

function recal_paging( rec2View){
	this.viewRec = rec2View;
	this.paging();
	this.toPage(1);
}

/*End of the object   
===============================================================================*/

 function chk_email(dataStr){
	 //email format
	 var atPos = dataStr.indexOf("@");
	 var dotPos = dataStr.indexOf(".");
	 
	 if (dataStr.length == 0)
		return true;
	 if ( atPos < 1 )
		return false; //when '@' is not found or at the very beginnig of email
	 if ( dotPos < 1 )
		return false; 
		
		for (var i=0; i<dataStr.length; i++){
		  var uCode = dataStr.charCodeAt(i);
		  if ( uCode < 64 || uCode > 90 ){ //if not uppercase & @
			if ( uCode < 97 || uCode > 122 ){ //if not lowercase
				if (  uCode > 57 || uCode < 48 ){ //not numbers
					if ( uCode != 46 && uCode != 45 && uCode != 95 && uCode != 43){//Special Char " . - _ +"
						return false;
					}
				}
			}
		  } 
		}
				
	 return true; 
	 //
 }
 
 function byte_length( string ){
	chk_val = encodeURI( string );
	str_length = chk_val.length;
	
	if( chk_val.search("%") == -1 ){
		return str_length;
	}
	else{
		arr_length = chk_val.split("%").length -1;
		return str_length - ( arr_length*2 );
	}
}


function facebook_click(u) 
{
	t = document.title;
    //window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t));
	window.open('http://www.facebook.com/pages/Sofasale/139122696107029');
    return false;
}

function twitter_click(url, message) 
{    
    var u = encodeURIComponent(url);
    u = 'http://twitter.com/home?status='+ message + u;
    window.open(u);return false;
}

function diggit_click(img, description, url) 
{    
    var u = encodeURIComponent(url);
    var t = encodeURIComponent(document.title);
    var d = encodeURIComponent(description);
    
    //u = 'http://digg.com/submit?url=' + u + '&title=' + t + '&bodytext=' + d + ';
    u = "http://digg.com/submit?url=" + u + "&title=" + t+ "&bodytext=" + d;
    window.open(u);
    return false;
}

function email_click(subject, body) 
{
    //window.open("mailto:me@provider.de");
}

function myspace_click(content, url)
{
    var T = document.title;
    var L = 2;
    var C = content;
    var U = url;
    
    var targetUrl = 'http://www.myspace.com/Modules/PostTo/Pages/?' + 't=' + encodeURIComponent(T)
    + '&c=' + encodeURIComponent(C) + '&u=' + encodeURIComponent(U) + '&l=' + L;
    
    window.open(targetUrl);
}


function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}


// buy box buy_box animation
var i=-1;
function buy_box_animation(updated_qty, buy_box_element_name,lang){
	if(updated_qty<=0)
		updated_qty = '0';
	$('#qty_of_products_in_cart').html(updated_qty).css('color','#F00');
	$(buy_box_element_name).css('cursor','pointer');
	$("#animation_box a").css('color', 'red').css('font-weight', 'bold');
	n = $("#animation_box a").queue("fx").length;
	if(n<=0){
		i=0;
	}
	runIt(lang);
}

function runIt(lang){
	if(i>=5){
		$('#animation_box a').animate({opacity: 1}, 300, function(){
			$("#animation_box a").css('color', 'black').css('font-weight', 'normal');
			$("#animation_box a").dequeue();
		});
		return;
	}
	else{
		$('#animation_box a').animate({opacity: 1}, 300);
		$('#animation_box a').animate({opacity: 0.3}, 300);
		i++;
		$('#animation_box a').fadeIn("fast", runIt);
	}
	location.href="/sc_webcat/shopping_cart/my_shopping_cat.php?lang="+lang;
}

