var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
function decode64(input){
	var output = "";
    var chr1, chr2, chr3;
    var enc1, enc2, enc3, enc4;
    var i = 0;

    // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
    input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

    do {
        enc1 = keyStr.indexOf(input.charAt(i++));
        enc2 = keyStr.indexOf(input.charAt(i++));
        enc3 = keyStr.indexOf(input.charAt(i++));
        enc4 = keyStr.indexOf(input.charAt(i++));

        chr1 = (enc1 << 2) | (enc2 >> 4);
        chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
        chr3 = ((enc3 & 3) << 6) | enc4;

        output = output + String.fromCharCode(chr1);

        if (enc3 != 64) {
            output = output + String.fromCharCode(chr2);
        }
        if (enc4 != 64) {
            output = output + String.fromCharCode(chr3);
        }
    } while (i < input.length);

    return output;
}
/*  Check in textarea limit 
   Pass   ==>  onkeyup="textLimit(this,LIMIT)" onblur="textLimit(this,LIMIT)"  
*/
function textLimit(field,maxlen) {
    if(field.value.length > maxlen){
        while(field.value.length > maxlen){
            field.value=field.value.replace(/.$/,'');
        }
        return false;
    }
}

function encode64(input){
    var output = "";
    var chr1, chr2, chr3;
    var enc1, enc2, enc3, enc4;
    var i = 0;

    do {
        chr1 = input.charCodeAt(i++);
        chr2 = input.charCodeAt(i++);
        chr3 = input.charCodeAt(i++);

        enc1 = chr1 >> 2;
        enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
        enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
        enc4 = chr3 & 63;

        if (isNaN(chr2)) {
            enc3 = enc4 = 64;
        } else if (isNaN(chr3)) {
            enc4 = 64;
        }

        output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) +
            keyStr.charAt(enc3) + keyStr.charAt(enc4);
    } while (i < input.length);

    return output;
}

var t;
function call_wait_div()
{
	if(jQuery('#loadingDiv').css("display")=='block')
    {
        jQuery('#loadingDiv').html="Still Working...";
        clearTimeout(t);
        return;
    }
    if(jQuery('#loadingDiv').css("display")=='none')
    {
        if(t!=undefined)
        {
            clearTimeout(t);
            return;
        }
        jQuery('#loadingDiv').css('display','block');
    }
    t = setTimeout("call_wait_div()",5000);    
}
function hide_wait_div()
{
    jQuery('#loadingDiv').css('display','none');
    clearTimeout(t);
    t = undefined;
}

function showimage(imgurl,title){
	tb_show(title, imgurl, false);
        return false;
}
function hideimage(imgurl,title){
	tb_remove();
}
function checkValidFile(valid_ext,valu,validExtension)
{
    if(valid_ext == 'Yes')
    {
        var val1,vx;
        var giveAlert="Yes";
        var no;
        val1=valu.split(".");
        var splitvalu=validExtension;
        vx=splitvalu.split(",");
        no=parseInt((val1.length)-1);
        for(l=0;l<vx.length;l++)
        {
            if(val1[no].toUpperCase()==vx[l].toUpperCase())
            {
                giveAlert="No";
                break;
            }
        }
        if(giveAlert == "Yes")
        {
            alert("Please Upload File with " + validExtension + " Extension.");
            return false;
        }
    }
    return true;
}

function OnlynumericValue(eve)
{
   val = eve.keyCode;
	if(!val)
		val=eve.which;
		
	if(val > 47 && val < 58)
	{
		return true;
	}
	else if(val==9 || val==8) 
	{
		return true;
	}
	else
	{
		return false;
	}
}

function postform(action, F) {
	if(F==null) {
		F = document.forms[0];
		if(document.forms[1]!=null) {
			F = document.forms[1];
		}
	}
	var yesno = true;
	var total_cnt = 0;
	for(var cnt =0; cnt < F.length; cnt++){
		if(F[cnt].name == "chk[]" && F[cnt].checked){
			total_cnt++;			
		}		
	}
	if(total_cnt == 0){
		alert("please select at least one record");
		return false;
	}
	switch (action){
		case "delete":
			yesno = confirm("Do you really want to delete selected records?");
			break;
		case "active":
			yesno = confirm("Do you really want to active selected records?");
			break;
		case "inactive":
			yesno = confirm("Do you really want to inactive selected records?");
			break;
		default:
			yesno = true;
			break;
	}	
	if(yesno) {
		F.useraction.value = action;		
		F.submit();
	}
}

//==========================================
//Check All boxes
//==========================================
function CheckAll(fmobj) {
	if(fmobj==null) {
		fmobj = document.forms[0];
		if(document.forms[1]!=null) {
			fmobj = document.forms[1];
		}
	}
	for (var i=0;i<fmobj.elements.length;i++) {
	 var e = fmobj.elements[i];
	 if ( (e.name != 'checkall') && (e.type=='checkbox') && (!e.disabled) ) {
	   e.checked = fmobj.checkall.checked;
	 }
	}
}

//==========================================
//Check all or uncheck all?
//==========================================
function CheckCheckAll(fmobj) {
	if(fmobj==null) {
		fmobj = document.forms[0];
		if(document.forms[1]!=null) {
			fmobj = document.forms[1];
		}
	}

	var TotalBoxes = 0;
	var TotalOn = 0;
	for (var i=0;i<fmobj.elements.length;i++) {
	 var e = fmobj.elements[i];
	 if ((e.name != 'checkall') && (e.type=='checkbox')) {
	   TotalBoxes++;
	   if (e.checked) {
	    TotalOn++;
	   }
	 }
	}
	if (TotalBoxes==TotalOn) {
	 fmobj.checkall.checked=true;
	}
	else {
	fmobj.checkall.checked=false;
	}
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}
function getState(obj){
    jQuery.post(basePath + "/search/ajax/getstate",{"id":obj.value},function(data){
    	jQuery("#divstate").html(data);
	});
}
function bookmark(url, title){

	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);
	}
function searchProduct(formObj){
	formObj.submit();	
}
function searchReview(formObj){
	formObj.submit();	
}
function searchMember(formObj){
	formObj.submit();	
}

function show_category()
{
	if(jQuery('#top_catId').css('display')=='none')
	{
		jQuery('#top_catId').slideDown('slow');
		jQuery('#showId').attr('class','current');
		//jQuery('#top_catId').css('display','block');
	}
	else if(jQuery('#top_catId').css('display')=='block')
	{
		jQuery('#top_catId').slideUp('slow');
		jQuery('#showId').attr('class','');
		//jQuery('#top_catId').css('display','none');
	}
}
urlAddress =window.location.href;
var pageName = ""; 
function addToFavorites(){
	if (window.external) {
		window.external.AddFavorite(urlAddress,pageName);
	}	else {
	alert("Sorry! Your browser doesn't support this function."); 
	}
}
function showHideMoreInfo(id){
	if(document.getElementById("ProductDetail-"+id).style.display!='none'){
		jQuery("#ProductDetail-"+id).slideUp("slow");
		jQuery("#arrow-IMG-"+id).show();
		jQuery("#moreaId-"+id).attr('class', '');
		jQuery("#arrow-up-IMG-"+id).hide();
	}else{
		jQuery("#ProductDetail-"+id).slideDown("slow");
		jQuery("#arrow-up-IMG-"+id).show();
		jQuery("#moreaId-"+id).attr('class', 'active');
		jQuery("#arrow-IMG-"+id).hide();
	}
}
function createPriceAlert(iProductId,iPrice){
    whatprocess[0] = iProductId;
    whatprocess[1] = iPrice;

    checkingfor = "createPriceAlert";
    checkSession('');
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}


function focusUserName(){
    if(document.getElementById("username_top")!=null)
    {
        document.getElementById("username_top").style.backgroundImage = "none";
    }
    
}

function blurUserName() {
    if(document.getElementById("username_top")!=undefined) {
        if(document.getElementById("username_top").value=="") {
            document.getElementById("username_top").style.backgroundImage = "url(" + imageUrl + "/usename.gif)";
        } else {
            document.getElementById("username_top").style.backgroundImage = "none";
        }
        if(document.getElementById("password_top").value=="") {
            document.getElementById("password_top").style.backgroundImage = "url(" + imageUrl + "/password.gif)";
        } else {
            document.getElementById("password_top").style.backgroundImage = "none";
        }
    }
}

function focusPassword() {
    if(document.getElementById("password_top")!=null)
    {
        document.getElementById("password_top").style.backgroundImage = "none";
    }
}

function blurPassword() {
    if(document.getElementById("password_top")!=undefined) {
        if(document.getElementById("password_top").value=="") {
            document.getElementById("password_top").style.backgroundImage = "url(" + imageUrl + "/password.gif)";
        } else {
            document.getElementById("password_top").style.backgroundImage = "none";
        }
    }
}
 function checkkeyonsearch(e)
           {
           	var code= e.keyCode;
           	if(code == 13) {
           		searchProduct();
           	}
	   }
            function searchProduct(){
                product = document.getElementById("productsearch").value;
                if(product==''){
                    alert("Please enter search criteria.");
                    document.getElementById("productsearch").focus();
                    return false;
                }
                var search_page = "/search/index/index/-id-";
                search_page = search_page.replace("-id-", product);
                window.location.href = search_page;
                //window.location = search_page+"?q="+product
            }
