
var small_loader = '<img src="'+baseUrlForJs+'/images/small_loader.gif" width="15" height="15" border="0" style="margin-right:5px;" align="absmiddle">';
var searchBoxDefaultText = 'Search';
var agreement_msg = 'You must accept our Terms and Conditions to proceed';


jQuery(document).ready(function() { 
    if(jQuery('#session').val() == 'set') {
        jQuery('#links_to_hide').attr('style','display:none'); 
        jQuery("#error_span").html('').hide();
        jQuery('#welcome_msg').attr('style','display:');
        //jQuery('#welcome_msg').html('');
	//jQuery('textarea:not(#vote_comments,#spam_comment)').wysiwyg();
    }
    
//forgotPassword('forgot_password');

    //select textarea content of vote on focus
    jQuery("#vote_comments").focus(function(){
        this.select();
    });
    
    jQuery("#vote_comments").click(function(){
        this.select();
    });

});
var setAddDesigns='';
var function_name='';
var forComment = '';
var in_home = '';
var ie4=document.all
var ns6=document.getElementById&&!document.all
var voteNumber='';
var setVotingAction ='';
var leads_value ='';
var designs_id;
var popobj;
var news_id;
var DESIGNS_URL='designs';
var GALLERY_URL='gallery';
var NEWS_URL='news';
var LEADS_URL='leads';
var MEMBERS_URL='members';
var CONTEST_URL='contest';  
var FORUM_URL='forum';
var CMS_URL='cms';
var PAGE_URL='PAGE';
var SERVER_MODE='LOCAL';
var STORE_URL = 'store';

function getposOffset(what, offsettype)
{
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null)
	{
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function hideObj(e)
{
	if (typeof popobj!="undefined")
	{
		if (ie4||ns6)
		popobj.hide();
	}
}


function delayhideObj()
{
	if (ie4||ns6)
	delayhide=setTimeout("hideObj()",250)
}


function clearhideObj()
{
	if (typeof delayhide!="undefined")
	clearTimeout(delayhide)
}



/*** for Voting **/
function resetVotes()
{
for(var i=1; i<=5; i++) { $('v_'+i).show(); }

}

function chooseVote()
		{
			
			//$('vote_comment_box').show();
                   if(jQuery('#session').val() != 'set') {
                        
                    jQuery.blockUI({
                            message: jQuery('#login_popup')
                        });
                     }
                     else {
                        //alert("now open VOTE DIV");
                        checkMyDesign();
                     }
		}

        function checkMyDesign(){
       //alert('hi');
                    var options = {
                                url     :  baseUrlForJs+'/designs/designs/checkmydesign',
                                type    : 'POST',
                                data    :  'designs_id='+jQuery('#item_id').val(),
				beforeSend :function (XMLHttpRequest){
				       jQuery('#submit_voting_comment').before('<span id ="loading_txt" ><img src="'+baseUrlForJs+'/images/ajax_loader.gif" width="31" height="31" title="Processing..." /></span>');
                                       jQuery("#submit_voting_comment").hide();
                                        },
                                success : function (msg) {
                                        var chunks = msg.split('|');
                                        if(chunks[1] == 'True'){
					   //backgroundColor="#fff";
                                             vote();
                                             //  setTimeout("showCommentBox()",1000);
                                                
                                            }else{
                                                voteNumber='';
                                                jQuery.blockUI({ message:"<div class='pop_div'>"+chunks[2]+"</div>" });
						 jQuery('#loading_txt').remove();
						 
                                                 jQuery('#vote_comments').val('Please type your comments here ...');
                                                 jQuery('#vote_comment_box').hide();
						  jQuery('#submit_voting_comment').show();
						//resetVotes();
                                                setTimeout(jQuery.unblockUI, 3000);
                                            }
                                    }
                                };
                jQuery.ajax(options);
    
}





function showVotePop(obj, title, nickname, member_id, design_id, votes)
{

    if(jQuery('#rating_link_div')) {
        clearhideObj();
        if(jQuery('#vote_result_span')) { 
            jQuery('#vote_result_span').html("");
        }
        $('rating_link_div').show();
        //alert('hi');
        var nickname = 'design by <a href="'+baseUrlForJs+'/'+MEMBERS_URL+'/showprofile/'+member_id+'">'+nickname+'</a>';
        var top = getposOffset(obj, 'top');
        var left = getposOffset(obj, 'left');
        $('vote_pop').style.top = top-60+"px";
        $('vote_pop').style.left = left+110+"px";
        $('vote_pop_title').innerHTML ='<a href="'+baseUrlForJs+'/'+DESIGNS_URL+'/'+title+'_'+design_id+'.html">'+title+'</a>';
        $('vote_pop_nickname').innerHTML = nickname;
        $('current_designs_id').value = design_id; 
        $('votedBy').innerHTML = votes; 
        $('vote_pop').show();
        popobj = $('vote_pop');
        resetVotes();
    }
}


function closeLoginPop()
{
if($('v1')) resetVotes();
voteNumber = '';
 jQuery('#vote_comments').val('Please type your comments here ...');
  jQuery('#vote_comment_box').hide();
  jQuery('#submit_voting_comment').show();
//alert("mahendra");
//location.replace(baseUrlForJs);
jQuery.unblockUI();

	
}
function closeVotingPop()
{
        if($('v1')) resetVotes();
    jQuery('#vote_comments').val(''); 
    jQuery('#leads_question').val('');   
    jQuery('#leads_question_error').html('');
    jQuery('#vote_comments').val('Please enter your comments here (optional)');    
   
     jQuery.unblockUI();
}

function chooseRating()
{   //alert('hi');    
    
    function_name=galleryRating;
    //alert(jQuery('#session').val());
     if(jQuery('#session').val() != 'set') {
        jQuery.blockUI({ 
                message: jQuery('#login_popup')
            });
         }
         else {
			 $('heart_it').hide();
            galleryRating();
         }
}

function chooseNewsRating(id)
{
     news_id=id;
     
    function_name = newsRating;
    if(jQuery('#session').val() != 'set') {
	
        jQuery.blockUI({ 
                message: jQuery('#login_popup')
            });
         }
         else {
	    
           newsRating();
         }
    
} 

function showAlt(img, imgid, cont)
{
new Effect.Fade(imgid, 
		{ from: 1.0, to: 0.5, duration: 0.2, 
				afterFinish: function (obj) 
				{ 
				$(imgid).width = img.width;
				$(imgid).height = img.height;
				
				$(cont).style.height = img.height+25+"px";
				
				
				$(imgid).src = img.src ;
				appearNow(imgid);
				}
 
 		});
}
function appearNow(imgid)
{
new Effect.Appear(imgid, { from: 0.5, to: 1.0, duration: 0.2});
}


function createImg(img, src, width, height)
{
	img.src = src;
	img.width = width;
	img.height = height;
}


function DisableEnableForm(xForm,xHow){
  objElems = xForm.elements;
  for(i=0;i<objElems.length;i++){
    objElems[i].disabled = xHow;
  }
}


function showLoadTxt(obj)
{
	//alert('<img src="'+baseUrlForJs+'/images/small_loader.gif" width="15" height="15" border="0">Processing...');
	obj.innerHTML = 'Processing...';
	
}


function openInquiryForm() {
    jQuery('#result_inquiry').html('').hide(); 
    jQuery.blockUI({ 
				   message: jQuery('#pop_inquiry_form'),
				   css: { 
							top:            '5%', 
							left:           '30%' 
					    }
				   });
    //jQuery('#pop_inquiry_form').show(); 
}

function validateInquiryForm() {

    
    
       var validator = jQuery("#inquiry_form").validate({
        rules: {
            inquiry_name    : {required: true},
            inquiry_email   : {required: true, email : true},
            inquiry_subject : {required: true},
            inquiry_type    : {required: true},
            inquiry_message : {required: true}

        },
        
        messages: {
            inquiry_name: { 
                    required: "Please enter your name"
            },
            inquiry_email: { 
                    required: "Please enter your email",
                    email: "Please enter valid email"
            },
            inquiry_subject: { 
                    required: "Please enter subject of inquiry"
            },
            inquiry_type: { 
                    required: "Please select the type of inquiry"
            },
            inquiry_message : {
                   required: "Please enter message" 
            }
        }, 
        
        errorPlacement: function(error, element) {
                error.appendTo (element.next().next()); 
        }, 
        
        submitHandler: function() {
            
             
             jQuery("#inquiry_form").ajaxStart(function(){
                                           jQuery("#inquiry_loading").show();
                                           jQuery("#inquiry_submit").hide();
                                           jQuery("#loading_txt_inquiry").show();
                                           jQuery('#result_inquiry').html('').hide(); 
                                          
                                            });
                                            
            jQuery("#inquiry_form").ajaxComplete(function(request, settings){
                                                  
                                             jQuery("#inquiry_loading").hide();
                                             jQuery("#inquiry_submit").show();
                                             jQuery("#loading_txt_inquiry").hide(); 
                                            
                                                 }); 
                
                var queryString = jQuery('#inquiry_form').formSerialize();
                      
                var options = {
                                url     :  baseUrlForJs+'/index/inquiry',
                                type    : 'POST',
                                data    :  queryString,
                                success : function (msg) {
                                var chunks = msg.split('|');
                                
                                jQuery('#result_inquiry').html(chunks[2]).show();   
                                document.getElementById('inquiry_form').reset(); 
                                
                                setTimeout(jQuery.unblockUI, 5000);
                               
                                //setTimeout("successPopInquiry(\""+chunks[2]+"\")", 2000);
                                    }
                                };
                jQuery.ajax(options);
            
        }, 
        success: function(label) { 
            label.html(" ").addClass("checked"); 
        }
    }); 

}

function successPopInquiry(result)
{
    document.getElementById('inquiry_form').reset();
    jQuery.blockUI({ 
    message: '<div class="pop_div pop_div_form">'+result+'</div>'});
    jQuery("#inquiry_submit").show(); 
    jQuery("#inquiry_loading").hide();
    setTimeout(jQuery.unblockUI, 6000);
}

function checkSearchKeywords() {
    jQuery('#loading_search').show();
    jQuery('#search_submit_name').hide();
    jQuery('#search_submit_img').hide();
        
    var validator = jQuery("#search_form").validate({
        rules : {keywords : 
                    {required : true}},
        messages :{keywords: 
                    {required : 'Please enter proper keywords to search'}},
        errorPlacement: function(error, element) {
                
                jQuery('#search_error_span').html('');
                jQuery('#search_error_span').html(error); 
               // alert(jQuery('#keywords').val());
                if(jQuery('#keywords').val() == ''){
                jQuery('#loading_search').hide();
                jQuery('#search_submit_name').show();
                jQuery('#search_submit_img').show();
                    }
                
        },
        success: function(label) {             
            label.html(" ").addClass("checked"); 
        },
         submitHandler: function(form) {
            form.submit();
         }
    });
    
                
    
}

function openSpamReporter(itemsType,itemsId) {
    jQuery('#spam_result').html('').hide();
    jQuery("#submit_spam").show(); 
    jQuery('#spam_items_type').val(itemsType);
    jQuery('#spam_items_id').val(itemsId);
    
     
     
    jQuery.blockUI({ 
                   message: jQuery('#pop_spam_form'),
                   css: { 
                            top:            '20%', 
                            left:           '30%' 
                        }
                   });
    
}

function validateSpamForm() {
    //alert(jQuery("#spam_members_id").val());
    var validator = jQuery("#spam_form").validate({
        rules: {
            
            spam_reporter_name  : {required: function(element) {
                    return jQuery("#spam_members_id").val() !='SET';}},
            spam_reporter_email : {required: function(element) {
                    return jQuery("#spam_members_id").val() !='SET';}, email: true},

            spam_type           : {required: true},
            spam_comment        : {required: true}
        },
        
        messages: {
             spam_reporter_name: { 
                    required: "Please enter your name"
            },
             spam_reporter_email: { 
                    required: "Please enter  your email address",
                    email: "Please enter valid email address"
            },
            spam_type: { 
                    required: "Please select the reason"
            },
            spam_comment: { 
                    required: "Please enter your comments"
                   
            }
        }, 
        
        errorPlacement: function(error, element) {
                error.appendTo('#'+element.attr("name")+'_error');
        }, 
        
        submitHandler: function() {
           
             
             jQuery("#spam_form").ajaxStart(function(){
                                           jQuery("#spam_loading").show();
                                           jQuery("#submit_spam").hide(); 
                                           jQuery("#spam_result").hide(); 
                                            });
                                            
            jQuery("#spam_form").ajaxComplete(function(request, settings){            
                                             jQuery("#spam_loading").hide();
                                             jQuery("#submit_spam").hide(); 
                                             jQuery("#spam_result").show(); 
                                            
                                                 }); 
                
                var queryString = jQuery('#spam_form').formSerialize();
                //alert(queryString);      
                var options = {
                                url     :  baseUrlForJs+'/index/submitspam',
                                type    : 'POST',
                                data    :  queryString,
                                success : function (msg) {
                                var chunks = msg.split('|');
                                document.getElementById('spam_form').reset();
				jQuery('#spam_result').show();
                               // alert(chunks[2]);
                                jQuery('#spam_result').html('<div class="success_msg">'+chunks[2]+'</div>');
				setTimeout(jQuery.unblockUI, 5000);
                                    }
                                };
                jQuery.ajax(options);
               // document.getElementById('spam_form').reset();
            
        }, 
        success: function(label) { 
            label.html(" ").removeClass("error"); 
        }
    }); 
}

function successPopSpam(result)
{
    document.getElementById('spam_form').reset();
    jQuery.blockUI({ 
    message: '<div class="pop_div">'+result+'</div>'});
    jQuery("#submit_spam").show(); 
    jQuery("#spam_loading").hide();
    setTimeout(jQuery.unblockUI, 2000);
}

function openNewWindow(){
       jQuery.blockUI({  message: jQuery('#terms_condition')});
       
      // setTimeout(jQuery.unblockUI, 5000);
       
}

function formatUrl(element) {
      var myWebsiteUrl = jQuery('#'+element).val();
        if(myWebsiteUrl != '') {
            var ext = myWebsiteUrl.slice(0,7);
            if(ext != 'http://') {
                jQuery('#'+element).val('http://'+myWebsiteUrl);
            }
            else {
                /*var url= myWebsiteUrl.slice(7,9);
                if(url!=""){
                    return false;
                } 
                else{*/
                jQuery('#'+element).val(myWebsiteUrl);
                //}
            }
        }
    }
    
    function openPopUpRss(url)
    {
       // alert(url);
        jQuery('#link_place').html('Subcribe using this link : <br /><form id="copy_form" name="copy_form"><textarea id="copy_value" name="copy_value" >'+url+'</textarea><input type="button" value="Copy Link" onclick="javascript:copyClipBoard(\''+url+'\')"/></form>');
        jQuery('#url_place').html('<a href="http://www.addthis.com/feed.php?pub=vibhorsingh&h1='+url+'&t1=" onclick="return addthis_open(this, \'feed\',\''+url+'\')" alt="Subscribe using any feed reader!" target="_blank">Select any of these web based feed readers</a>');
         jQuery.blockUI({ 
                    message: jQuery('#rss_pop_up'), 
                    css: { width: '375px' }
                         });
    }

function copyClipBoard(text_value){


// window.clipboardData.setData('Text',s);


  if( window.clipboardData && clipboardData.setData )
    {
        clipboardData.setData("Text",text_value);
    }
    else
    {
       // You have to sign the code to enable this or allow the action in about:config by changing
      /* user_pref("signed.applets.codebase_principal_support", true);
        netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

        var clip = Components.classes['@mozilla.org/widget/clipboard;[[[[1]]]]'].createInstance(Components.interfaces.nsIClipboard);
        if (!clip) return;

        // create a transferable
        var trans = Components.classes['@mozilla.org/widget/transferable;[[[[1]]]]'].createInstance(Components.interfaces.nsITransferable);
        if (!trans) return;

        // specify the data we wish to handle. Plaintext in this case.
        trans.addDataFlavor('text/unicode');

        // To get the data from the transferable we need two new objects
        var str = new Object();
        var len = new Object();

        var str = Components.classes["@mozilla.org/supports-string;[[[[1]]]]"].createInstance(Components.interfaces.nsISupportsString);

        var copytext=meintext;

        str.data=copytext;

        trans.setTransferData("text/unicode",str,copytext.length*[[[[2]]]]);

        var clipid=Components.interfaces.nsIClipboard;

        if (!clip) return false;

        clip.setData(trans,null,clipid.kGlobalClipboard);   */  
        
         var flashId = 'flashId-HKxmj5';

        /* Replace this with your clipboard.swf location */
        var clipboardSWF = 'http://appengine.bravo9.com/copy-into-clipboard/clipboard.swf';

        if(!document.getElementById(flashId)) {
            var div = document.createElement('div');
            div.id = flashId;
            document.body.appendChild(div);
        }
        document.getElementById(flashId).innerHTML = '';
        var content = '<embed src="'+clipboardSWF+'" FlashVars="clipboard='+encodeURIComponent(text_value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
        document.getElementById(flashId).innerHTML = content;

    }
}

function checkSearchContest() {
//    jQuery('#loading_search').show();
//    jQuery('#search_btn').hide();
//    //jQuery('#search_submit_img').hide();
//       jQuery('#search_error_span').html('');
//
//                if(jQuery('#keyword').val() == ''){
//
//                jQuery('#search_error_span').html('<div class="error">Please enter proper keywords to search </div>');
//					
//                jQuery('#loading_search').hide();
//                jQuery('#search_btn').show();
//                //jQuery('#search_submit_img').show();
//                    }else{
//
//      if(SERVER_MODE=='SERVER'){
//           location.replace(baseUrlForJs+'/contest/search/'+encodeURIComponent(jQuery('#keyword').val()));
//	  }
//	  else{
//		location.replace(baseUrlForJs+'/contest/contest/index/keywords/'+encodeURIComponent(jQuery('#keyword').val())+'/search_in/'+jQuery('#search_in').val());
//	  }
//           //location.replace(baseUrlForJs+'/contest/search/'+encodeURIComponent(jQuery('#keywords').val()));
//
//         }
//
      var validator = jQuery("#contest_search_form").validate({
        rules : {keywords :
                    {required : true}},
        messages :{keywords:
                    {required : 'Please enter proper keywords to search'}},
        errorPlacement: function(error, element) {
                 jQuery('#search_error_span').html('');
                error.appendTo('#search_error_span');
               // alert(jQuery('#keywords').val());


        },

         submitHandler: function(form) {

             jQuery('#loading_search').show();
            jQuery('#search_btn').hide();
            

            //alert('in submit');
             if(jQuery('#keywords').val() == 'keyword' ){

                jQuery('#search_error_span').html('<div class="error">Please enter proper keywords to search </div>');

                jQuery('#loading_search').hide();
                jQuery('#search_btn').show();
              
                    }else{
                       // form.submit();
					   location.replace(baseUrlForJs+'/contest/?keywords='+jQuery('#keywords').val()+'&search_in='+jQuery('#search_in').val()+'&searched=true');
                    }
			// alert(encodeURIComponent(jQuery('#keywords').val()));
//           if(SERVER_MODE=='SERVER'){
//           location.replace(baseUrlForJs+'/news/search/'+encodeURIComponent(jQuery('#keywords').val()));
//	  }
//	  else{
//		location.replace(baseUrlForJs+'/news/news/index/keywords/'+encodeURIComponent(jQuery('#keyword').val())+'/search_in/'+jQuery('#search_in').val());
//	  }

		   //return false;
		 //form.submit();
         },
        // set this class to error-labels to indicate valid fields
        success: function(label) {
            // set   as text for IE
            label.html(" ").addClass("checked");
        }
    });
                
    
}

function selectKeywordsText()
{
    jQuery('#keyword').select();
}

function cmsBlock(identifier){

    
    jQuery.ajax({
                                    url :  baseUrlForJs+'/index/getcmsblock/',
                                    type : 'POST',
                                    data:'pageType='+identifier,
								    beforeSend :function (XMLHttpRequest){
										jQuery.blockUI.defaults.css.left = '45%'; 
											jQuery.blockUI.defaults.css.top = '45%'; 
												jQuery.blockUI({
													message: '<div><img src="'+baseUrlForJs+'/images/ajax_loader1.gif" /></div>'
												});
                                        },
									
                                    success : function (msg) {
                                        
                                        var chunks = msg.split('|');
											jQuery('#cms_block_content').html(chunks[2]);
											jQuery('#cms_block_title').html(chunks[3]);
											
											
											jQuery.blockUI.defaults.css.left = '30%'; 
											jQuery.blockUI.defaults.css.top = '5%'; 
											
													jQuery.blockUI({ 
																message: jQuery('#cms_block')
															});
											//jQuery.blockUI.defaults.css.left = '30%'; 
											//jQuery.blockUI.defaults.css.top = '40%'; 
										
                                    //setTimeout(jQuery.unblockUI, 6000);

                                    }
                                });
}


 function showVote(type, id, iconImg)
	  {
		
		if(type==1) { $('quick_vote_'+id).show(); $('design_img_'+id).src=baseUrlForJs+"/images/thumb_spacer.png"; }
		else { $('quick_vote_'+id).hide(); $('design_img_'+id).src=iconImg; }
		  
	  }

 function showVotePopup(design_id)
 {
    
	
	    jQuery.blockUI({
			message: '<div><img src="'+baseUrlForJs+'/images/ajax_loader1.gif" /></div>'
			});
	
    


        jQuery("#design_vote_popup").load(baseUrlForJs+'/designs/designs/viewpop/id/'+design_id,function(){
		//jQuery.unblockUI();
		
		
		jQuery.blockUI.defaults.css.left = '20%'; 
		jQuery.blockUI.defaults.css.top = '20%'; 																								 
		jQuery.blockUI({
			message: jQuery('#design_vote_popup')
			});
		jQuery.blockUI.defaults.css.left = '40%'; 
		jQuery.blockUI.defaults.css.top = '40%'; 
                 if(voteNumber != ''){
                     setVotingAction='';
                     
                     showCommentBox();
                 }
 		});
		
		
 }
 
 function chooseVotePopUp(design_id)
{
       
               showVotePopup(design_id);
            
       
}

function globalSearchPopAll(obj){
    //jQuery.blockUI({
//                message: jQuery('#search_popup')
//            });
	   // alert('here');
	var cont = jQuery(obj).position();
	///alert(cont.left + -47);
	//jQuery('login_div').css({ top: cont.top + 10, left: cont.left + 10 });
	$('search_popup').style.top = cont.top + 25 +"px";
	$('search_popup').style.left = cont.left + -47 +"px";
	$('search_popup').toggle();
	
	//fp_login_toggle('login'); // this is to reset the box with Login Fields

	

}
function checkSearch() {
    
    jQuery('#search_error').html('');

    jQuery("#search_form").validate({
          rules: {
              search_txt :{
                  required:true }
              },
          messages:
                    {
                        search_txt :{required:"Please enter proper keywords to search"}

                     },
         errorPlacement:function(error, element) {
             error.appendTo('#search_error');
              },
           submitHandler:function(form) {
               jQuery('#global_search').hide();
               jQuery('#search_loader').show();
               if(SERVER_MODE=='SERVER'){
            //location.replace(baseUrlForJs+'/index/search/'+encodeURIComponent(jQuery('#search_txt').val()));
            jQuery('#search_form').attr('action',baseUrlForJs+'/'+jQuery('#global_search_in').val()+'/'+jQuery('#global_search_in').val()+'/index/searched/true/keywords/'+jQuery('#search_txt').val()+'/search_in/'+jQuery('#global_search_in').val())
            form.submit();


        }
        else{
            location.replace(baseUrlForJs+'/'+jQuery('#global_search_in').val()+'?keywords='+jQuery('#search_txt').val()+'&search_in='+jQuery('#global_search_in').val()+'&searched=true');

        }
           },

            debug: true

        });

//    if(jQuery('#search_txt').val() == ''){
//
//        jQuery('#search_error').html('<div class="error">Please enter proper keywords to search </div>');
//        jQuery('#search_loader').hide();
//        jQuery('#global_search').show();
//
//   }
//   else{
//       //alert('here');
//
//        if(SERVER_MODE=='SERVER'){
//            //location.replace(baseUrlForJs+'/index/search/'+encodeURIComponent(jQuery('#search_txt').val()));
//            jQuery('#search_form').attr('action',baseUrlForJs+'/'+jQuery('#global_search_in').val()+'/'+jQuery('#global_search_in').val()+'/index/keywords/'+jQuery('#search_txt').val()+'/search_in/'+jQuery('#global_search_in').val())
//
//        }
//        else{
//            jQuery('#search_form').attr('action',baseUrlForJs+'/'+jQuery('#global_search_in').val()+'/'+jQuery('#global_search_in').val()+'/index/keywords/'+jQuery('#search_txt').val()+'/search_in/'+jQuery('#global_search_in').val())
//        }
//    }
}

function showTerms($identifier){
	
	jQuery.blockUI.defaults.css.left = '30%'; 
	jQuery.blockUI.defaults.css.top = '15%';
		
     jQuery.blockUI({
			message: jQuery('#'+$identifier+'_terms')
			});
	 
	 jQuery.blockUI.defaults.css.left = '40%'; 
	 jQuery.blockUI.defaults.css.top = '40%';

}

function vote() {

      var comments = '';
      if(jQuery('#vote_comments').val() != 'Please type your comments here ...'){
      comments = jQuery('#vote_comments').val();
      }
    var designsId = jQuery('#current_designs_id').val();
   // alert(comments);

    jQuery.ajax({
        type : 'POST',
        url : baseUrlForJs+'/designs/designs/handleaddvoting',
        data : 'comments='+comments+'&actual_value='+voteNumber+'&designs_id='+designsId,
        beforeSend :function (XMLHttpRequest){
//				       jQuery('#submit_voting_comment').before('<span id ="loading_txt" ><img src="'+baseUrlForJs+'/images/form_loader.gif" width="31" height="31" title="Processing..." /></span>');
//                                       jQuery("#submit_voting_comment").hide();
                                        },
        success: function(msg){
            var chunks = msg.split('|');

            if(chunks[1] == 'SUCCESS') {

              jQuery.blockUI({ message: '<div class="pop_div">'+chunks[2]+'<br />Average Voting for this Design is '+chunks[3]+'</div>'});
			  var count = (parseInt(jQuery('#vote_count').val())+1);
			  //alert(count);
              jQuery('#designs_vote_count').html(count+' People');
              jQuery('#designs_vote_avg').html(chunks[3]);
               jQuery('#vote_comments').val('Please type your comments here ...');
              jQuery('#vote_comment_box').hide();
              jQuery('#submit_voting_comment').show();
	      jQuery('#loading_txt').hide();
              //resetVotes();
              jQuery('#vote_comments').val('');
              jQuery('#vote_comments').val('Please enter your comments here (optional)');

              if(chunks[4] != ''){

              if(jQuery('#has_comment').val() == 'no'){

					jQuery('#response').attr('style','margin-bottom:30px;');
                                          jQuery('#comment_png').show();
                                        }
               jQuery('#response').prepend(jQuery.trim(chunks[4]));
               jQuery('#comment_count').hide();
                jQuery('#comment_count').html('');
                jQuery('#comment_count').html(chunks[5]+' comment(s)');
                jQuery('#comment_counter').html(chunks[5]);
                jQuery('#comment_count').show();
                jQuery('#comment_counter').show();

              }
			  setTimeout(jQuery.unblockUI, 5000);
			  if(actionNameForJs == 'view') {
					setTimeout(location.replace(window.location.toString()), 1000);
				}
              //jQuery('#vote_thankyou').html(jQuery('#vote_result_span').html());
              //jQuery('#vote_thankyou').html('hello');


            }
        }
    });
}

function newsRating()
{
    jQuery.ajax({
        type : 'POST',
        url : baseUrlForJs+'/news/news/handleaddrating',
        data : 'news_id='+news_id,
        success: function(msg){
            var chunks = msg.split('|');

            if(chunks[1] == 'SUCCESS') {
                //alert('mahendra');
               jQuery('#total_rated_news'+chunks[4]).html(chunks[3]);
               jQuery('#rated_news'+chunks[4]).html(chunks[3]);
              //jQuery.blockUI({ message: '<div class="pop_div"><div class="close_btn"><img src="'+baseUrlForJs+'/images/close_btn.png" width="12" height="12" onclick="javascript:closeLoginPop()" /></div>'+chunks[2]+'</div>'});
              jQuery('#like_it_'+chunks[4]).html('');
              jQuery('#like_it_'+chunks[4]).html(chunks[2]);
             // setTimeout(jQuery.unblockUI, 6000);

             // jQuery('#rated_by').html(chunks[2]);
              //jQuery('#vote_thankyou').html('hello');


            }else{
                jQuery('#like_it_'+chunks[4]).html('');
              jQuery('#like_it_'+chunks[4]).html(chunks[2]);
            }
        }
    });
}

function forgotPassword(formName)
{

    var form = jQuery('#'+formName);
      var pass_validator = jQuery(form).validate({
        rules: {
            forgot_pass_email : {required: true, email: true}
           },

        messages: {
            forgot_pass_email: {
                            required: "Please fill your email Address",
                            email: "Invalid Email address."
                        }

        },
        // the errorPlacement has to take the table layout into account
        errorPlacement: function(error, element) {
            jQuery('#error_span').html('');
                error.appendTo('#error_span');
        },
        // specifying a submitHandler prevents the default submit, good for the demo
        submitHandler: function() {
            //alert('in_submit');
                jQuery(form).ajaxStart(function(){
                                           jQuery("#loading_forgot_modal").show();
                                            jQuery("#submit_forgot_modal").hide();
                                           });

             jQuery(form).ajaxComplete(function(request, settings){

                                             jQuery("#loading_forgot_modal").hide();
                                             jQuery("#submit_forgot_modal").show();
                                                });
                var queryString = jQuery(form).formSerialize();

                var options = {
                                url :  baseUrlForJs+'/members/members/retrivepassword',
                                target : '#response',
                                type    : 'POST',
                                data :  queryString,
                                success:function (msg) {
                                        var chunks = msg.split('|');

                                                jQuery('#error_span').html('<div class="error">'+chunks[1]+'</div>');

                                    }
                                };
                jQuery.ajax(options);

        },
        // set this class to error-labels to indicate valid fields
        success: function(label) {
            // set   as text for IE

            label.html("").addClass("checked");
        }
    });
}

function textCounter(field, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
}