function getCookie(search_name) {
  // note: document.cookie only returns name=value, not the other components
  var tab_cookies = document.cookie.split( ';' );
  var i = 0;
  for ( i = 0; i < tab_cookies.length; i++ ) {
    // now we'll split apart each name=value pair
    var cookie_tmp = tab_cookies[i].split('=');  
    // and trim left/right whitespace while we're at it 
    var cookie_name = cookie_tmp[0].replace(/^\s+|\s+$/g, ''); 
    // if the extracted name matches passed search_name
    if (cookie_name==search_name) {
      // we need to handle case where cookie has no value but exists (no = sign, that is):
      if (cookie_tmp.length>1) {
        return unescape( cookie_tmp[1].replace(/^\s+|\s+$/g, '') );
      }
      // cookie is initialized but no value => result = null
      return null;
    } 
  }
  return null;
} 

function getURLVar(varName){
	var url=window.location.toString();
	if(url.search(/\?/) >0){
		var ary=url.split("?")[1].split("&");
		var cnt = ary.length;
		var i = 0;
	  for(i=0;i<cnt;i++){
	  	if(ary[i].split("=")[0] == varName){
	    	return ary[i].split("=")[1];
	    }
	  }
	}
	return null;
}
function gup( name ){
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	 var regexS = "[\\?&]"+name+"=([^&#]*)";  
	 var regex = new RegExp( regexS );  
	 var results = regex.exec( window.location.href );  
	 if( results == null )    
	 	return "";  
	 else    
	 	return results[1];
}
function toggle(submenu, menuarrow){
	if (document.getElementById(submenu).style.display == "none"){
		document.getElementById(submenu).style.display = "block"; 
		document.getElementById(menuarrow).src = 'images/icon_sub_arrow_down.gif';
		document.getElementById(menuarrow).width = 7;
		document.getElementById(menuarrow).height = 4;
	}else if (document.getElementById(submenu).style.display == "block"){
		document.getElementById(submenu).style.display = "none";
		document.getElementById(menuarrow).src = 'images/icon_sub_arrow_right.gif';
		document.getElementById(menuarrow).width = 4;
		document.getElementById(menuarrow).height = 7;
	}
}

function switchDiv(openHeader,closeHeader,openDiv,closeDiv){
	document.getElementById(openHeader).className = "adata_t12_content_header_open";
	document.getElementById(closeHeader).className = "adata_t12_content_header_close";
	document.getElementById(openDiv).style.display = "";
	document.getElementById(closeDiv).style.display = "none";
}
function rank(num){
	var i = 1;
	var total = 5;
	for(i=1;i<=total;i++){
		document.getElementById("rank" + i).src = "images/rankstar2_gray.gif";
	}
	for(i=1;i<=num;i++){
		document.getElementById("rank" + i).src = "images/rankstar1_gray.gif";
	}
	document.newMain.r_rank.value = num;
}
function validForm(fm){
	if(fm.r_rank.value == ""){
		alert("{$l_product_review_empty_star}");
		return false;
	}
	if(fm.r_content.value == ""){
		alert("{$l_product_review_empty_content}");
		return false;
	}
	document.getElementById("content_div").style.display = "none";
	document.getElementById("loading_div").style.display = "block";
	$.ajax({
		url:"product_review_save.php",
     type:"POST",
		data: {
			"pi_id":fm.pi_id.value,
			"r_rank":fm.r_rank.value,
			"r_content":fm.r_content.value
		},
		success:function(data){
			var res = jQuery.trim(data);
			document.getElementById("loading_div").innerHTML = res;
			if(document.getElementById("none_div") != null){
				document.getElementById("none_div").style.display = "none";
			}	
		}
	});
}
