
var small_loader = '<img src="'+baseUrlForJs+'/images/small_loader.gif" width="15" height="15" border="0" style="margin-right:5px;" align="absmiddle">';


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('');
    }
    
//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 function_name='';
var in_home = '';
var ie4=document.all
var ns6=document.getElementById&&!document.all
var voteNumber='';
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';

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(v, obj, from )
{
	voteNumber = v;
	resetVotes();
	$(obj).hide();
	
	//if($('rating_box')) 	rating_box(1, this)
	
       // function_name = vote; 
        if(jQuery('#session').val() != 'set') {
        jQuery.blockUI({ 
                message: jQuery('#login_div')
            });
         }
         else {
            checkMyDesign();
            
         }
       
	
}

        function checkMyDesign(){
        
                    var options = {
                                url     :  baseUrlForJs+'/designs/designs/checkmydesign',
                                type    : 'POST',
                                data    :  'designs_id='+jQuery('#current_designs_id').val(),
                                success : function (msg) {
                                        var chunks = msg.split('|');
                                        if(chunks[1] == 'True'){
                                                jQuery.blockUI({ message: jQuery('#voting_comment') });
                                            }else{
                                                jQuery.blockUI({ message:"<div class='pop_div'>"+chunks[2]+"</div>" });
                                                setTimeout(jQuery.unblockUI, 3000);
                                            }
                                    }
                                };
                jQuery.ajax(options);
    
}

function emptyFunction() {
}



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();
        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();
//alert("mahendra");
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()
{
	$('heart_it').hide();
    function_name=galleryRating;
     if(jQuery('#session').val() != 'set') {
        jQuery.blockUI({ 
                message: jQuery('#login_div')
            });
         }
         else {
            galleryRating();
         }
}

function chooseNewsRating(id)
{
     news_id=id;
     
    function_name = newsRating;
    if(jQuery('#session').val() != 'set') {
        jQuery.blockUI({ 
                message: jQuery('#login_div')
            });
         }
         else {
           newsRating();
         }
    
} 

function showAlt(img, imgid, cont)
{
//alert(imgid);
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:            '20%', 
							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('#items_type').remove();
    jQuery('#items_id').remove();
    
     var hidden1 = '<input type="hidden" name="items_type" id="items_type" value="'+itemsType+'" />';
     var hidden2 = '<input type="hidden" name="items_id" id="items_id" value="'+itemsId+'" />';
     jQuery('#spam_form > ul:last').after(hidden1);
     jQuery('#spam_form > ul:last').after(hidden2);
     
    jQuery.blockUI({ 
                   message: jQuery('#pop_spam_form'),
                   css: { 
                            top:            '20%', 
                            left:           '30%' 
                        }
                   });
    
}

function validateSpamForm() {
    var validator = jQuery("#spam_form").validate({
        rules: {
            
            spam_reporter_name  : {required: true},
            spam_reporter_email : {required: true, 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 id",
                    email: "Please enter valid email id"
            },
            spam_type: { 
                    required: "Please select a spam type"
            },
            spam_comment: { 
                    required: "Please enter your comments"
                   
            }
        }, 
        
        errorPlacement: function(error, element) {
                error.appendTo (element.next().next()); 
        }, 
        
        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();
                      
                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').html(chunks[2]).show();
                                setTimeout(jQuery.unblockUI, 5000);
                                    }
                                };
                jQuery.ajax(options);
                document.getElementById('spam_form').reset();
            
        }, 
        success: function(label) { 
            label.html(" ").addClass("checked"); 
        }
    }); 
}

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_submit_name').hide();
    jQuery('#search_submit_img').hide();
       jQuery('#search_error_span').html('');  
    
                if(jQuery('#keywords').val() == ''){
					
                jQuery('#search_error_span').html('<div class="error">Please enter proper keywords to search </div>'); 
					
                jQuery('#loading_search').hide();
                jQuery('#search_submit_name').show();
                jQuery('#search_submit_img').show();
                    }else{
                
      
           location.replace(baseUrlForJs+'/contest/search/'+encodeURIComponent(jQuery('#keywords').val()));
		  
         }
 
    
                
    
}

